SatelliteShorelines / CoastSeg

An interactive toolbox for downloading satellite imagery, applying image segmentation models, mapping shoreline positions and more. The mapping extension for CoastSat and Zoo.
https://satelliteshorelines.github.io/CoastSeg/
GNU General Public License v3.0
46 stars 8 forks source link

Due to doodleverse-utils v0.0.33 MNDWI and NDWI models no longer function #160

Closed 2320sharon closed 1 year ago

2320sharon commented 1 year ago

Due to the latest update to doodleverse-utils v0.0.33 MNDWI and NDWI models no longer function and throw error similar to the one pasted below. These models need the option to pass only a single band to the model such with code such as tf.squeeze(model(tf.expand_dims(image[:,:,1], 0)))

Traceback (most recent call last):
  File "c:\development\doodleverse\coastseg\CoastSeg\debug_scripts\test_models.py", line 78, in <module>
    model_dict = {
  File "C:\development\doodleverse\coastseg\CoastSeg\src\coastseg\zoo_model.py", line 1036, in run_model
    self.compute_segmentation(model_dict, percent_no_data)
  File "C:\development\doodleverse\coastseg\CoastSeg\src\coastseg\zoo_model.py", line 1099, in compute_segmentation
    do_seg(
  File "C:\Users\sf230\anaconda3\envs\coastseg_transformers10\lib\site-packages\doodleverse_utils\prediction_imports.py", line 395, in do_seg
    est_label, counter = est_label_multiclass(image,M,MODEL,TESTTIMEAUG,NCLASSES,TARGET_SIZE)
  File "C:\Users\sf230\anaconda3\envs\coastseg_transformers10\lib\site-packages\doodleverse_utils\prediction_imports.py", line 174, in est_label_multiclass
    est_label = tf.squeeze(model(tf.expand_dims(image[:,:,:3], 0)))
  File "C:\Users\sf230\anaconda3\envs\coastseg_transformers10\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\sf230\anaconda3\envs\coastseg_transformers10\lib\site-packages\keras\src\engine\input_spec.py", line 280, in assert_input_compatibility
    raise ValueError(
ValueError: Exception encountered when calling layer 'model' (type Functional).
dbuscombe-usgs commented 1 year ago

I updated doodleverse-utils to hopefully avoid this bug. please try it out https://pypi.org/project/doodleverse-utils/0.0.34/

2320sharon commented 1 year ago

This remains an issue even with doodleverse_utils 0.0.34. For a temporary solution these models will be taken out in coastseg 0.0.72

dbuscombe-usgs commented 1 year ago

Due to information provided by @2320sharon , the est_label_multiclass version implemented (for some reason!) in zoo was working but not the one in 'verse-utils-34 ... so I put the zoo versions of that function plus sister functions est_label_binary and do_seg into 'verse-utils/prediction_imports.

then I updated the Zoo and Gym functions so they use the doodleverse-utils versions of the above functions. Specifically, I updated model_functions and model_inference_funcs in zoo and tested various models with segment_orthomosaic.py and `select_model_and_batch_process_folder.py. I also tested gym/seg_images_in_folder.py

I tested both 2- and multiclass models, and segformer and resunet models, on satellite imagery and other imagery, including RGB and MNDWI and NDWI. It worked great every time :tada:

please use https://pypi.org/project/doodleverse-utils/0.0.35/ and fingers crossed!!

2320sharon commented 1 year ago

I was worried this might not work, but its works great! I tested it with all the models in both BEST and ENSEMBLE model and it works great! I also tested this change with all the models and it works!