mapbox / robosat

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

Division by zero when training with small datasets caused by incomplete batch dropping #228

Open iboates opened 1 year ago

iboates commented 1 year ago

I am aware that this repo is no longer maintained but I recently had to blow the dust off of it to replicate some stuff I did a few years ago. When setting up the environment I kept getting a division by 0 here. I finally resolved it and thought I should leave a note here in case anyone finds themself in a similar situation.

It turns out it was because I was using a trivially small datasetr (only a few features) because I was just trying to get the entire pipeline working correctly. Specifically, when initializing the DataLoaders, the drop_last parameter is hardcoded to True, which will always drop the last batch if it is incomplete. So if you only have one (tiny) batch, you end up with an empty data loader, causing the aforementioned division by zero error.

Change this parameter to False here and here to fix it.