I was trying to execute this code to reconstruct the final predicted image but it is throwing this error mentioned below. I am very new to python and I am unable to understand the error. Can anyone please help.
I want to extract building information from the RGB image
# image height and width
img_h, img_w = image.shape[0], image.shape[1]
# reconstructs predicted mask tiles into one single mask image
predicted_image = ps.reconstruct(preds, img_w, img_h, model_input_w, model_input_h, numpy_output = False)
plt.imshow(predicted_image)
Error:
ValueError Traceback (most recent call last)
Input In [28], in <cell line: 5>()
2 img_h, img_w = image.shape[0], image.shape[1]
4 # reconstructs predicted mask tiles into one single mask image
----> 5 predicted_image = ps.reconstruct(preds, img_w, img_h, model_input_w, model_input_h, numpy_output = False)
7 plt.imshow(predicted_image)
File ~\BuildingExtractionWithDEEPlearning\image_utils.py:245, in reconstruct(tiles_list, img_width, img_height, model_input_w, model_input_h, numpy_output)
241 tiles_list = [Image.fromarray(i, 'L') for i in tiles_list]
243 # if RGB image
244 else:
--> 245 tiles_list = [Image.fromarray(i.astype('uint8'), 'RGB') for i in tiles_list]
247 first_image = tiles_list[0]
249 num_row = int(np.ceil(img_height / model_input_h))
File ~\BuildingExtractionWithDEEPlearning\image_utils.py:245, in <listcomp>(.0)
241 tiles_list = [Image.fromarray(i, 'L') for i in tiles_list]
243 # if RGB image
244 else:
--> 245 tiles_list = [Image.fromarray(i.astype('uint8'), 'RGB') for i in tiles_list]
247 first_image = tiles_list[0]
249 num_row = int(np.ceil(img_height / model_input_h))
File ~\anaconda3\envs\tensorflow\lib\site-packages\PIL\Image.py:2974, in fromarray(obj, mode)
2971 else:
2972 obj = obj.tostring()
-> 2974 return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)
File ~\anaconda3\envs\tensorflow\lib\site-packages\PIL\Image.py:2901, in frombuffer(mode, size, data, decoder_name, *args)
2898 im.readonly = 1
2899 return im
-> 2901 return frombytes(mode, size, data, decoder_name, args)
File ~\anaconda3\envs\tensorflow\lib\site-packages\PIL\Image.py:2843, in frombytes(mode, size, data, decoder_name, *args)
2840 args = mode
2842 im = new(mode, size)
-> 2843 im.frombytes(data, decoder_name, args)
2844 return im
File ~\anaconda3\envs\tensorflow\lib\site-packages\PIL\Image.py:798, in Image.frombytes(self, data, decoder_name, *args)
795 s = d.decode(data)
797 if s[0] >= 0:
--> 798 raise ValueError("not enough image data")
799 if s[1] != 0:
800 raise ValueError("cannot decode image data")
ValueError: not enough image data