mapbox / robosat

Semantic segmentation on aerial and satellite imagery. Extracts features such as: buildings, parking lots, roads, water, clouds
MIT License
2.02k stars 383 forks source link

Added torch.no_grad() #109

Closed Jesse-jApps closed 6 years ago

Jesse-jApps commented 6 years ago

no_grad() is available since pytorch 0.4.0 and prevents possible 'out of memory' errors during validation.

daniel-j-h commented 6 years ago

Ouch, good catch!

I think we should move this to the validation function; here we are setting the net in evaluation mode to freeze batch norms, etc. already:

https://github.com/mapbox/robosat/blob/6dcdc0ee527f384fb6eb1c813dba6889bfa13404/robosat/tools/train.py#L156

Jesse-jApps commented 6 years ago

What about decorating validation with @torch.no_grad()?

daniel-j-h commented 6 years ago

Sure that would work, too!

Jesse-jApps commented 6 years ago

I oversaw, that no_grad() as decorator is only available since pytorch 0.4.1. I committed a workaround using contextmanager. As soon as robosat is upgraded for 0.4.1 the additional contextmanager code can be discarded.

daniel-j-h commented 6 years ago

Merci!