Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train WildFire #64

Merged
merged 8 commits into from
May 24, 2020
Merged

Conversation

MateoLostanlen
Copy link
Member

The purpose of this PR is to add a basic training loop for the wildfire dataset. This is far from being optimal in terms of performance but it can be considered as a first baseline.

@codecov
Copy link

codecov bot commented May 2, 2020

Codecov Report

Merging #64 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #64   +/-   ##
=======================================
  Coverage   83.85%   83.85%           
=======================================
  Files          19       19           
  Lines         706      706           
=======================================
  Hits          592      592           
  Misses        114      114           

@frgfm frgfm added the ext: references Related to references label May 12, 2020
@frgfm frgfm added this to the 0.1.1 milestone May 12, 2020
@MateoLostanlen MateoLostanlen requested review from x0s and frgfm May 12, 2020 09:04
Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
There seems to be an issues with overlapping modifications with #63. Could you take a look please?

Comment on lines 72 to 87
if ratios['test'] > 0:
fire_ids = {'train': self._get_fire_ids_for_one_split(n_samples_train),
'val': self._get_fire_ids_for_one_split(n_samples_val)}
fire_ids['test'] = [id_ for id_ in self._fire_id_to_size
if id_ not in (fire_ids['train'] + fire_ids['val'])]
# Finish exhaustion
for fire_id_test in fire_ids['test']:
del self._fire_id_to_size_to_exhaust[fire_id_test]

else:
fire_ids = {'train': self._get_fire_ids_for_one_split(n_samples_train)}
fire_ids['val'] = [id_ for id_ in self._fire_id_to_size if id_ not in fire_ids['train']]
# Finish exhaustion
for fire_id_test in fire_ids['val']:
del self._fire_id_to_size_to_exhaust[fire_id_test]
fire_ids['test'] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this supposed to be in #63 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's in #63, I wrote this PR on top of #63. So we need to merge #63 before this one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you cancel out this modif please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

Comment on lines 161 to 164
# if wildfire.metadata['fire_id'].nunique() != wildfire.metadata['fire_id'].max() + 1:
# warnings.warn(f"Inconsistent Fire Labeling. Maybe try to label the fire again\n"
# f"Distinct values of ids({wildfire.metadata['fire_id'].nunique()}"
# f" ≠ {wildfire.metadata['fire_id'].max() + 1})", Warning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines 96 to 104
def test_splitting_with_test_to_zero(self):
ratios = {'train': 0.81, 'val': 0.19, 'test': 0}

splitter = WildFireSplitter(ratios, seed=42)
splitter.fit(self.wildfire)

for (set_, ratio_) in splitter.ratios_.items():
self.assertAlmostEqual(ratio_, ratios[set_], places=2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! A few changes and some transformation choices that I'm having doubts about, let me know your thoughts about the comments!

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])

train_transforms = transforms.Compose([
transforms.RandomResizedCrop(size=args.resize // 7, scale=(0.8, 1.0)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a pretty big loss of information with a relative output size of 1/7. Perhaps we should directly resize to target size?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a mistake, I didn't want to lose so much information. Thank you, that's corrected. I also deleted one of the two crops.

transforms.RandomRotation(degrees=15),
transforms.ColorJitter(),
transforms.RandomHorizontalFlip(),
transforms.CenterCrop(size=args.resize), # Image net standards
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally CenterCrop is used for eval but not train set. Having two crop transformations seems unnecessary. It might be better to stick with RandomResizedCrop but discard CenterCrop

])

val_transforms = transforms.Compose([
transforms.Resize(size=args.resize // 7),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here for the small resize

Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change to make for eval transformations but the rest looks good!

Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only some side modifications to cancel out, the rest looks good!

Comment on lines 72 to 87
if ratios['test'] > 0:
fire_ids = {'train': self._get_fire_ids_for_one_split(n_samples_train),
'val': self._get_fire_ids_for_one_split(n_samples_val)}
fire_ids['test'] = [id_ for id_ in self._fire_id_to_size
if id_ not in (fire_ids['train'] + fire_ids['val'])]
# Finish exhaustion
for fire_id_test in fire_ids['test']:
del self._fire_id_to_size_to_exhaust[fire_id_test]

else:
fire_ids = {'train': self._get_fire_ids_for_one_split(n_samples_train)}
fire_ids['val'] = [id_ for id_ in self._fire_id_to_size if id_ not in fire_ids['train']]
# Finish exhaustion
for fire_id_test in fire_ids['val']:
del self._fire_id_to_size_to_exhaust[fire_id_test]
fire_ids['test'] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you cancel out this modif please?

Comment on lines 96 to 104
def test_splitting_with_test_to_zero(self):
ratios = {'train': 0.81, 'val': 0.19, 'test': 0}

splitter = WildFireSplitter(ratios, seed=42)
splitter.fit(self.wildfire)

for (set_, ratio_) in splitter.ratios_.items():
self.assertAlmostEqual(ratio_, ratios[set_], places=2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you cancel out this modification? The rest of the PR looks good!

Copy link
Contributor

@Akilditu Akilditu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Added some comments to let the ability of optimizer change and tensor shape for targets.

Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the changes!

@MateoLostanlen MateoLostanlen merged commit 8473c19 into pyronear:master May 24, 2020
Akilditu pushed a commit to Akilditu/seb_pyro-vision that referenced this pull request Jun 3, 2020
* Allow test ratio to zero in WildFireSplitter

* fix flake8

* add training script for Wildfire

* add a test to improve code coverage

* put back the warning on FireIds

* Fix size in RandomCrop and delete CenterCrop

* add centercrop to get square images

* remove change already made in PR pyronear#63
@MateoLostanlen MateoLostanlen deleted the trainWilfire branch September 18, 2020 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: references Related to references
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants