mapbox / robosat

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

Access local files using docker #170

Closed maning closed 5 years ago

maning commented 5 years ago

@daniel-j-h Excited for the new release! I'm trying my old data using I get an error FileNotFoundError: [Errno 2]. Note I'm not expecting predict to completely finish since some of the depedencies have changed since I generated this checkpoint, but I expected to get the error beyond FileNotFoundError.

Probably a docker noob mistake, any pointers?

Steps are the following:

  1. Alias docker run to robosat
$ alias robosat='docker run -it --rm -v $PWD:/data --ipc=host --network=host mapbox/robosat:latest-cpu'
$ robosat --help
usage: ./rs [-h]  ...

optional arguments:
  -h, --help  show this help message and exit

robosat tools:

    extract   extracts GeoJSON features from OpenStreetMap
    cover     generates tiles covering GeoJSON features
    download  downloads images from Mapbox Maps API
    rasterize
              rasterize features to label masks
    train     trains model on dataset
    export    exports model in ONNX format
    predict   predicts probability masks for slippy map tiles
    masks     compute masks from prediction probabilities
    features  extracts simplified GeoJSON features from segmentation masks
    merge     merged adjacent GeoJSON features
    dedupe    deduplicates features against OpenStreetMap
    serve     serves predicted masks with on-demand tileserver
    weights   computes class weights on dataset
    compare   compare images, labels and masks side by side
    subset    filter images in a slippy map directory using a csv
  1. List all files needed.
$ ls 2018-07-18/
total 2558992
drwxrwxr-x  3 maningsambale  staff         96 Jul  1  2018 __MACOSX/
-rw-r--r--  1 maningsambale  staff  157856321 Jul 20  2018 checkpoint-00040-of-00050.pth
drwxr-xr-x  4 maningsambale  staff        128 Jun 23  2018 classify/
-rw-r--r--  1 maningsambale  staff  915632558 Jul  1  2018 classify.zip
drwxr-xr-x  6 maningsambale  staff        192 Jun  3 18:04 dataset/
-rw-r--r--@ 1 maningsambale  staff  206964752 Jul 22  2018 dataset-20180714.zip
-rw-r--r--  1 maningsambale  staff        648 Jul 20  2018 dataset-building.toml
-rw-r--r--  1 maningsambale  staff        656 Jul 20  2018 model-unet.toml
  1. Run predict
$ time robosat predict --tile_size 256 --model 2018-07-18/model-unet.toml --dataset 2018-07-18/dataset-building.toml --checkpoint 2018-07-18/checkpoint-00040-of-00050.pth 2018-07-18/classify 2018-07-18/segmentation
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/robosat/tools/__main__.py", line 58, in <module>
    args.func(args)
  File "/usr/src/app/robosat/tools/predict.py", line 44, in main
    model = load_config(args.model)
  File "/usr/src/app/robosat/config.py", line 21, in load_config
    return toml.load(path)
  File "/opt/venv/lib/python3.6/site-packages/toml/decoder.py", line 111, in load
    with io.open(_getpath(f), encoding='utf-8') as ffile:
FileNotFoundError: [Errno 2] No such file or directory: '2018-07-18/model-unet.toml'

real    0m1.682s
user    0m0.038s
sys 0m0.033s
maning commented 5 years ago

nvm, found the issue: -v <host-folder-path>:<container-folder-path>

Inside the container use "container-folder-path"

So syntax should be:

time robosat predict --tile_size 256 --model /data/2018-07-18/model-unet.toml --dataset /data/2018-07-18/dataset-building.toml --checkpoint /data/2018-07-18/checkpoint-00040-of-00050.pth /data/2018-07-18/classify /data/2018-07-18/segmentation
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/robosat/tools/__main__.py", line 58, in <module>
    args.func(args)
  File "/usr/src/app/robosat/tools/predict.py", line 68, in main
    net.load_state_dict(chkpt["state_dict"])
KeyError: 'state_dict'

real    0m4.167s
user    0m0.039s
sys 0m0.030s

Error above is likely due to old checkpoints used. Closing, hopefully noobs see this and won't be confused again. ;)