Doodleverse / doodleverse_utils

A set of common Doodleverse tools and utilities
MIT License
4 stars 3 forks source link

Model Error: RGB model fails when do_crf is False #5

Closed 2320sharon closed 2 years ago

2320sharon commented 2 years ago

Model: landsat_6229071 Input Type: RGB Inputs: Attached in a zipped folder RGB.zip Context: The model works if the do_crf parameter is True, but if do_CRF is False then this error occurs. doodleverse_utils: version 0.0.3 Error Message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~\Anaconda3\envs\coastseg_dev\lib\site-packages\doodleverse_utils\prediction_imports.py:450, in do_seg(f, M, metadatadict, sample_direc, NCLASSES, N_DATA_BANDS, TARGET_SIZE, TESTTIMEAUG, WRITE_MODELMETADATA, do_crf)
    447 try:
    448     color_label = label_to_colors(
    449         est_label,
--> 450         bigimage.numpy()[:, :, 0] == 0,
    451         alpha=128,
    4
[RGB.zip](https://github.com/Doodleverse/doodleverse_utils/files/9602667/RGB.zip)
52         colormap=class_label_colormap,
    453         color_class_offset=0,
    454         do_alpha=False,
    455     )
    456 except:

AttributeError: 'numpy.ndarray' object has no attribute 'numpy'

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
File ~\Anaconda3\envs\coastseg_dev\lib\site-packages\doodleverse_utils\prediction_imports.py:458, in do_seg(f, M, metadatadict, sample_direc, NCLASSES, N_DATA_BANDS, TARGET_SIZE, TESTTIMEAUG, WRITE_MODELMETADATA, do_crf)
    457 try:
--> 458     color_label = la
[RGB.zip](https://github.com/Doodleverse/doodleverse_utils/files/9602668/RGB.zip)
bel_to_colors(
    459         est_label,
    460         bigimage[:, :, 0] == 0,
    461         alpha=128,
    462         colormap=class_label_colormap,
    463         color_class_offset=0,
    464         do_alpha=False,
    465     )
    466 except:

File ~\Anaconda3\envs\coastseg_dev\lib\site-packages\doodleverse_utils\imports.py:126, in label_to_colors(img, mask, alpha, colormap, color_class_offset, do_alpha)
    125 for c in range(minc, maxc + 1):
--> 126     cimg[img == c] = colormap[(c + color_class_offset) % len(colormap)]
    128 cimg[mask == 1] = (0, 0, 0)

IndexError: boolean index did not match indexed array along dimension 2; dimension is 3 but corresponding boolean dimension is 5

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
File ~\Anaconda3\envs\coastseg_dev\lib\site-packages\ipywidgets\widgets\widget_output.py:103, in Output.capture.<locals>.capture_decorator.<locals>.inner(*args, **kwargs)
    101     self.clear_output(*clear_args, **clear_kwargs)
    102 with self:
--> 103     return func(*args, **kwargs)

Input In [11], in run_model_button_clicked(button)
    161 metadatadict=zoo_model.get_metadatadict(Ww,config_files, model_types)
    162 # # Compute the segmentation
--> 163 zoo_model.compute_segmentation(model_dict["sample_direc"], model_list, metadatadict,model_dict['use_CRF'])
    164 # Enable  run and open results buttons when model has exexcuted
    165 run_model_button.disabled = False

File C:\1_USGS_repos\2_doodleverse\CoastSeg\CoastSeg\zoo_model_module.py:43, in Zoo_Model.compute_segmentation(self, sample_direc, model_list, metadatadict, do_crf)
     41 # Compute the segmentation for each of the files
     42 for f in tqdm(sample_filenames):
---> 43     do_seg(
     44         f,
     45         model_list,
     46         metadatadict,
     47         sample_direc,
     48         self.NCLASSES,
     49         self.N_DATA_BANDS,
     50         self.TARGET_SIZE,
     51         TESTTIMEAUG,
     52         WRITE_MODELMETADATA,
     53         do_crf)

File ~\Anaconda3\envs\coastseg_dev\lib\site-packages\doodleverse_utils\prediction_imports.py:467, in do_seg(f, M, metadatadict, sample_direc, NCLASSES, N_DATA_BANDS, TARGET_SIZE, TESTTIMEAUG, WRITE_MODELMETADATA, do_crf)
    458         color_label = label_to_colors(
    459             est_label,
    460             bigimage[:, :, 0] == 0,
   (...)
    464             do_alpha=False,
    465         )
    466     except:
--> 467         color_label = label_to_colors(
    468             est_label,
    469             bigimage == 0,
    470             alpha=128,
    471             colormap=class_label_colormap,
    472             color_class_offset=0,
    473             do_alpha=False,
    474         )        
    476 imsave(segfile, (color_label).astype(np.uint8), check_contrast=False)
    478 if WRITE_MODELMETADATA:

File ~\Anaconda3\envs\coastseg_dev\lib\site-packages\doodleverse_utils\imports.py:126, in label_to_colors(img, mask, alpha, colormap, color_class_offset, do_alpha)
    123 maxc = np.max(img)
    125 for c in range(minc, maxc + 1):
--> 126     cimg[img == c] = colormap[(c + color_class_offset) % len(colormap)]
    128 cimg[mask == 1] = (0, 0, 0)
    130 if do_alpha is True:

IndexError: boolean index did not match indexed array along dimension 2; dimension is 3 but corresponding boolean dimension is 5
ebgoldstein commented 2 years ago

relevant snippet of code:

https://github.com/Doodleverse/doodleverse_utils/blob/691abe7f3c3d354df50c2958cf727c4037950222/doodleverse_utils/prediction_imports.py#L443-L455

dbuscombe-usgs commented 2 years ago

I have fixed this issue (and another one -see https://github.com/Doodleverse/doodleverse_utils/commit/495b8899cf4c1fd420e26a2680714671467fdc3d): NCLASSES should be passed as-is, not NCLASSES+1

Please update to v 0.0.8 https://pypi.org/project/doodleverse-utils/0.0.8/