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

AssertionError: same number of tiles in inputs and target #100

Closed bkowshik closed 6 years ago

bkowshik commented 6 years ago

While downloading tiles for my dataset, there was one tile that could not be downloaded. The rs download step logged the same as below, which is helpful to get a sense of how many tiles failed to download and which ones.

Warning: Tile(x=187579, y=121531, z=18) failed, skipping

But, in the rs rasterize when there isn't a geojson feature part of a tile, we put in an empty label with all pixels have the value of background. So, what happened is that the number of images was one less than the number of labels. This caused the train script to fail with the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/app/robosat/robosat/tools/__main__.py", line 57, in <module>
    args.func(args)
  File "/app/robosat/robosat/tools/train.py", line 74, in main
    train_loader, val_loader = get_dataset_loaders(model, dataset)
  File "/app/robosat/robosat/tools/train.py", line 198, in get_dataset_loaders
    [os.path.join(path, "training", "images")], os.path.join(path, "training", "labels"), transform
  File "/app/robosat/robosat/datasets.py", line 58, in __init__
    assert len(self.target) == len(self.inputs[0]), "same number of tiles in inputs and target"
AssertionError: same number of tiles in inputs and target

The message about different is number of images and labels is helpful. Should it be a warning instead of an error?

https://github.com/mapbox/robosat/blob/6f26d8586f612d144bf06491fecdbc59913bb508/robosat/datasets.py#L58

daniel-j-h commented 6 years ago

It's the user's responsibility to make sure images and labels are in sync. I think the error is fine here; what we could do is change the wording from input and target to images and masks.

daniel-j-h commented 6 years ago

This landed in https://github.com/mapbox/robosat/pull/101.