Doodleverse / segmentation_zoo

A collection of geoscientific image segmentation models
MIT License
7 stars 3 forks source link

Computing Segmentation gives error RuntimeError: array type dtype('float16') not supported #22

Closed 2320sharon closed 1 year ago

2320sharon commented 1 year ago

Bug

When I ran the RGB 4 class model sat_RGB_4class_6950472 with the images included in RGB.zip I kept getting the error RuntimeError: array type dtype('float16') not supported. I believe the error is coming from skimage's resize function that is used within doodleverse_utils's do_seg function in the lineest_label = resize(est_label, (w, h)). est_label is of type float16 which is causing this bug to appear and (w, h) are both of type int so they aren't causing the problem. The bug appears for BEST and ENSEMBLE models and on all imagery I've tested it with,

I tried running the same model with coastseg and it worked just fine on these images. I cannot figure out why I'm getting exceptions here and valid results with coastseg. 2019-01-25-18-57-02_RGB_L8 2019-01-25-18-57-25_RGB_L8 2019-02-10-18-56-59_RGB_L8 2019-02-10-18-57-23_RGB_L8 RGB.zip

How I obtained the Error Message

I modified scripts/select_model_and_batch_process_folder.py to print the full traceback for the exception that occurred

import traceback
# Import do_seg() from doodleverse_utils to perform the segmentation on the images
for f in tqdm(sample_filenames):
    try:
        do_seg(f, M, metadatadict, sample_direc,NCLASSES,N_DATA_BANDS,TARGET_SIZE,TESTTIMEAUG, WRITE_MODELMETADATA,OTSU_THRESHOLD)
    except Exception as e:
![2019-01-25-18-57-02_RGB_L8](https://user-images.githubusercontent.com/61564689/206025024-6ced24f0-fbcb-4489-81f6-53c4fe6ed674.jpg)
![2019-01-25-18-57-25_RGB_L8](https://user-images.githubusercontent.com/61564689/206025027-638ba591-e27d-4833-abcf-274c2d985deb.jpg)
![2019-02-10-18-56-59_RGB_L8](https://user-images.githubusercontent.com/61564689/206025029-90331ce4-2494-4efa-b474-4fa67aa7b2e3.jpg)
![2019-02-10-18-57-23_RGB_L8](https://user-images.githubusercontent.com/61564689/206025034-e5dc2b9b-7b4c-41fc-9eca-3678c83ca5f3.jpg)

        print(e)
        print(traceback.format_exc())
        print("{} failed. Check config file, and check the path provided contains valid imagery".format(f))

Error Message

array type dtype('float16') not supported
Traceback (most recent call last):
  File "C:\1_USGS\5_Doodleverse\segmentation_zoo\segmentation_zoo\scripts\select_model_and_batch_process_folder.py", line 398, in <module>
    do_seg(f, M, metadatadict, sample_direc,NCLASSES,N_DATA_BANDS,TARGET_SIZE,TESTTIMEAUG, WRITE_MODELMETADATA,OTSU_THRESHOLD)
  File "C:\Users\Sharon\anaconda3\envs\zoo\lib\site-packages\doodleverse_utils\prediction_imports.py", line 442, in do_seg
    est_label = resize(est_label, (w, h))
  File "C:\Users\Sharon\AppData\Roaming\Python\Python39\site-packages\skimage\transform\_warps.py", line 147, in resize
    image = ndi.gaussian_filter(image, anti_aliasing_sigma,
  File "C:\Users\Sharon\AppData\Roaming\Python\Python39\site-packages\scipy\ndimage\filters.py", line 342, in gaussian_filter
    gaussian_filter1d(input, sigma, axis, order, output,
  File "C:\Users\Sharon\AppData\Roaming\Python\Python39\site-packages\scipy\ndimage\filters.py", line 261, in gaussian_filter1d
    return correlate1d(input, weights, axis, output, mode, cval, 0)
  File "C:\Users\Sharon\AppData\Roaming\Python\Python39\site-packages\scipy\ndimage\filters.py", line 133, in correlate1d
    _nd_image.correlate1d(input, weights, axis, output, mode, cval,
RuntimeError: array type dtype('float16') not supported

My Environment

OS: Windows 10 Doodleverse_utils: 0.0.16 Tensorflow: 2.11.0 Latest and up to date version of segmentation zoo 0 GPUs: on my machine. I used SET_GPU='-1'

2320sharon commented 1 year ago

The resize function is being passed an array of type float16 (a 16-bit floating-point number), which is not supported.

The solution is to convert the est_label array to a different data type before passing it to the resize function. You can do this using the astype method, like this: est_label = est_label.astype('float32') This will convert the est_label array to type float32, which should be supported by the resize function.

@ebgoldstein thanks for the help!

2320sharon commented 1 year ago

This issue was fixed in doodleverse_utils 0.0.18