knshnb / kaggle-happywhale-1st-place Goto Github PK
View Code? Open in Web Editor NEW1st place solution for Kaggle "Happywhale - Whale and Dolphin Identification"
1st place solution for Kaggle "Happywhale - Whale and Dolphin Identification"
Good afternoon!
I have been trying to recreate the winning score using the code in the README. I've done this easily in the past (like a year ago), but having been struggling to do so lately. I think a lot of these could be fixed by switching to Lightning 2.0, but have been struggling to make that work. Any ideas?
I believe the issue stems with the package versions in the requirements.txt
. I am able to install the requirements, after tweaking the required version of Optuna. Then, running the src.train
script prompts the following error:
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
Stack Exchange recommended running the following command pip install protobuf==3.20.*
, which ran without issue.
Then, running the src.train
file produces the following error: AttributeError: 'WhaleDataModule' object has no attribute '_has_setup_TrainerFn.FITTING'
The only thread that I've seen discuss this recommended upgrading to lightning v.2.0
.
I've also tried upgrading to lightning 2.0, but that has some issues. Namely, test_epoch_end()
has been deprecated. I've tried switching to on_test_epoch_end()
(see proposed switch below). But this switch produces np.nan
in the pred_logit
and embed_features
keys in the results dict.
Do you have any ideas on a better way to upgrade to 2.0?
Thanks!
Phil
class SphereClassifier(LightningModule):
def __init__(self, cfg: dict, id_class_nums=None, species_class_nums=None):
super().__init__()
...
self.test_step_outputs = []
def test_step(self, batch, batch_idx):
x = batch["image"]
feat1 = self.get_feat(x)
out1, out_species1 = self.head_id(feat1), self.head_species(feat1)
feat2 = self.get_feat(x.flip(3))
out2, out_species2 = self.head_id(feat2), self.head_species(feat2)
pred_logit, pred_idx = ((out1 + out2) / 2).cpu().sort(descending=True)
results_dict = {
"original_index": batch["original_index"],
"label": batch["label"],
"label_species": batch["label_species"],
"pred_logit": pred_logit[:, :1000],
"pred_idx": pred_idx[:, :1000],
"pred_species": ((out_species1 + out_species2) / 2).cpu(),
"embed_features1": feat1.cpu(),
"embed_features2": feat2.cpu(),
}
self.test_step_outputs.append(results_dict)
return results_dict
def on_test_epoch_end(self):
outputs = self.test_step_outputs
if self.trainer.global_rank == 0:
epoch_results: Dict[str, np.ndarray] = {}
for key in outputs[0].keys():
if torch.cuda.device_count() > 1:
result = torch.cat([x[key] for x in outputs], dim=1).flatten(end_dim=1)
else:
result = torch.cat([x[key] for x in outputs], dim=0)
epoch_results[key] = result.detach().cpu().numpy()
np.savez_compressed(self.test_results_fp, **epoch_results)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.