VIDA-NYU / tile2net

Automated mapping of pedestrian networks from aerial imagery tiles
BSD 3-Clause "New" or "Revised" License
146 stars 22 forks source link

Invalid Geometry with Larger Areas #40

Closed sylvan-sh closed 8 months ago

sylvan-sh commented 10 months ago

With the SSL certificate issue of #12 resolved and newer imagery, been trialing some cities in Oregon. I'm encountering an error only when running larger (using the built-in geocoder for bounding box) cities.

I have successfully run:

I encounter the same (different coordinate values) error with:

An example of a Eugune run where the error occurs:

(t2n) t2n@t2n:~/tile2net# python -m tile2net generate -l "Eugene, Oregon, United States" -o "./output" -n eugene | python -m tile2net inference
INFO       Geocoding Eugene, Oregon, United States, this may take awhile...                                                                                      
INFO       Geocoded 'Eugene, Oregon, United States' to                          
        'Eugene, Lane County, Oregon, United States'                                                                                                             
INFO       Geocoding [43.9875292, -123.2087577, 44.1322715, -123.0358859], this may take awhile...                                                               
INFO       Using Oregon as the source at location=[43.9875292, -123.2087577, 44.1322715, -123.0358859]                                                           
INFO       Using base_tilesize=256 from source                                  
INFO       Stitching Tiles...                                                                                                                                    
           Checking 75,776 files...               : 100%|███████████████████████████████████| 75776/75776 [00:02<00:00, 28474.30it/s]                            
           Downloading 75,776 tiles...            : 100%|█████████████████████████████████████| 75776/75776 [10:25<00:00, 121.16it/s]                            
INFO       All 75776 tiles are on disk.                                         
           Stitching 4,736 tiles...               : 100%|████████████████████████████████████████| 4736/4736 [04:26<00:00, 17.79it/s]                            
INFO       Dumping to output/eugene/tiles/eugene_256_info.json                  
DEBUG      Inference piped                                                                                                                                       
INFO       Inferencing. Segmentation results will be saved to output/eugene/segmentation                                                                         
Using regular batch norm                                                                                                                                         
ignore_label = -1                       
num_classes = 4                                                                                                                                                  
Found 4736 folder imgs                                                          
all imgs 4736                                                                   
Using Per Image based weighted loss                                                                                                                              
Using Cross Entropy Loss                
Loading weights from: checkpoint=/t2n/tile2net/src/tile2net/raster/resources/assets/weights/satellite_2021.pth                                                  
=> init weights from normal distribution                                        
=> loading pretrained model /t2n/tile2net/src/tile2net/raster/resources/assets/weights/hrnetv2_w48_imagenet_pretrained.pth                                      
Trunk: hrnetv2                          
Model params = 72.1M                    
INFO       Using base_tilesize=256 from source                                  
Inference [Iter: 1 / 4736]              
Inference [Iter: 21 / 4736]
...
Inference [Iter: 4701 / 4736]                                                                                                                             [6/762]
Inference [Iter: 4721 / 4736]
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/t2n/tile2net/src/tile2net/__main__.py", line 7, in <module>
    argh.dispatch_commands([
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/argh/dispatching.py", line 358, in dispatch_commands
    dispatch(parser, *args, **kwargs)
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/argh/dispatching.py", line 183, in dispatch
    for line in lines:
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/argh/dispatching.py", line 294, in _execute_command
    for line in result:
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/argh/dispatching.py", line 247, in _call
    result = function(namespace_obj)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/tile2net/src/tile2net/namespace.py", line 640, in wrapper
    return func(namespace, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/tile2net/src/tile2net/tileseg/inference/__init__.py", line 303, in inference
    run_inference()
  File "/t2n/tile2net/src/tile2net/tileseg/inference/__init__.py", line 202, in run_inference
    validate(val_loader, net, criterion=None, optim=None, epoch=0,
  File "/t2n/tile2net/src/tile2net/tileseg/inference/__init__.py", line 280, in validate
    grid.save_ntw_polygon()
  File "/t2n/tile2net/src/tile2net/raster/grid.py", line 600, in save_ntw_polygon
    unioned = buff_dfs(poly_network)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/tile2net/src/tile2net/raster/tile_utils/geodata_utils.py", line 378, in buff_dfs
    buffersw = buffer_union_erode(dfsw, 0.3, -0.3, 0.2, 0.3, 0.3)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/tile2net/src/tile2net/raster/tile_utils/geodata_utils.py", line 247, in buffer_union_erode
    gdf_uni = unary_multi(gdf_erode)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/tile2net/src/tile2net/raster/tile_utils/geodata_utils.py", line 212, in unary_multi
    if gdf.unary_union.type == 'MultiPolygon':
       ^^^^^^^^^^^^^^^
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/geopandas/base.py", line 1219, in unary_union
    return self.geometry.values.unary_union()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/geopandas/array.py", line 743, in unary_union
    return vectorized.unary_union(self._data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/geopandas/_vectorized.py", line 1186, in unary_union
    data = shapely.union_all(data)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/shapely/decorators.py", line 77, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/t2n/mambaforge/envs/t2n/lib/python3.11/site-packages/shapely/set_operations.py", line 426, in union_all
    return lib.unary_union(collections, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
shapely.errors.GEOSException: TopologyException: side location conflict at -13709026.947767392 5483724.0441047. This can occur if the input geometry is invalid.
Mary-h86 commented 9 months ago

@sylvan-sh Thanks for flagging this issue. We've addressed it in the latest commit. Please run git pull to update your local repository and run again on the regions that were causing problems.

If you encounter any further issues, don't hesitate to report back

github-actions[bot] commented 8 months ago

We are closing this issue due to inactivity. If you have any further questions or need assistance, please feel free to reopen the issue. We will be glad to help!