The original image in LEVIR-CD has a size of 1024 * 1024, which will consume too much memory when training. Therefore, needed to cut the origin images into smaller patches.
When image dataset contains images in png format with size 1024x1024 code below doesn't return an error, if I cropped image into 16 parts (256x256px) this code return an error
tmp = np.array(Image.open(L_path), dtype=np.uint32)/255
L_img = Image.fromarray(tmp)
Error
L_img = Image.fromarray(tmp) File "/usr/lib64/python3.6/dist-packages/PIL/Image.py", line 2766, in fromarray raise TypeError("Cannot handle this data type: %s, %s" % typekey) from e TypeError: Cannot handle this data type: (1, 1, 3), <f8
Image sample - (left bottom corner from original image)
Original image sample
To fix this issue as described in this answer PIL TypeError: Cannot handle this data type question answer
I fix error:
L_img = Image.fromarray(tmp.astype(np.uint8))
Full code described here at STANet project Github page
pip3 imported libs versions:
Pillow 8.1.0
numpy 1.19.5
I misunderstood how can image size can change function behavior. I would be very grateful if someone could explain.
UPDATE: as I understand, it depend on bit depth of an image. Original image 8 bit, but cropped image is 24 bit png. I did not pay attention to this point, but the question has already been resolved.


importstatements and code to chop the image which you have removed please? And also provide the original image rather than the chopped one. I'm guessing you have a problem with data types and ranges. Thank you. - Mark Setchell