We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello, I'm ussing samgeo2 text prompt
I have a list of images that are going to be segmented one by one, the process runs fine, all the images meet the 8-bit RGB requirements.
The loop runs and sam.show_anns(cmap="Greys_r", add_boxes=False, alpha=1, blend=False, output=mask_output_filename) shows the segmented image:
But when saving the output it returns the error TypeError: Cannot handle this data type: (1, 1), <i8
KeyError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/PIL/Image.py in fromarray(obj, mode) 3276 try: -> 3277 mode, rawmode = _fromarray_typemap[typekey] 3278 except KeyError as e:
KeyError: ((1, 1), '<i8')
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last) 4 frames in <cell line: 14>() 75 # Procesar y segmentar el tile 76 tile_filename = process_tile(tile, transform, i, j) ---> 77 mask_output_filename = segment_image(tile_filename, output_dir) 78 output_masks.append(mask_output_filename) 79
in segment_image(tile_filename, output_dir) 53 title="Segmentación automatica", 54 ) ---> 55 sam.show_anns(cmap="Greys_r", add_boxes=False, alpha=1, blend=False, output=mask_output_filename) 56 57 print(f"Segmentación y máscara guardada para {tile_filename}")
/usr/local/lib/python3.10/dist-packages/samgeo/text_sam.py in show_anns(self, figsize, axis, cmap, alpha, add_boxes, box_color, box_linewidth, title, output, blend, **kwargs) 569 plt.savefig(output, **kwargs) 570 else: --> 571 array_to_image(self.prediction, output, self.source) 572 573 def raster_to_vector(self, image, output, simplify_tolerance=None, **kwargs):
/usr/local/lib/python3.10/dist-packages/samgeo/common.py in array_to_image(array, output, source, dtype, compress, **kwargs) 1525 1526 else: -> 1527 img = Image.fromarray(array) 1528 img.save(output, **kwargs) 1529
/usr/local/lib/python3.10/dist-packages/PIL/Image.py in fromarray(obj, mode) 3279 typekey_shape, typestr = typekey 3280 msg = f"Cannot handle this data type: {typekey_shape}, {typestr}" -> 3281 raise TypeError(msg) from e 3282 else: 3283 rawmode = mode
TypeError: Cannot handle this data type: (1, 1), <i8
The same thing happens if I add the output inside sam.predict Any ideas, solutions, alternatives to save the result?
Curiously, if I pass the image one by one through the samgeo2 text prompt example, they work without any problem.
The text was updated successfully, but these errors were encountered:
Can you provide some small sample datasets and code snippets that can reproduce the issue?
Sorry, something went wrong.
tile filenames = ['output_images/tile_0_0.tiff', 'output_images/tile_0_1024.tiff', 'output_images/tile_1024_0.tiff', 'output_images/tile_1024_1024.tiff'] sam = LangSAM(model_type="sam2-hiera-large") output_masks = [] for tile_filename in tile_filenames: # Segment the image mask = sam.predict(tile_filename, "trees", box_threshold=0.24, text_threshold=0.24) print(mask) try: mask_output_filename = os.path.join(output_dir, f"mask_{os.path.basename(tile_filename)}") sam.show_anns(cmap="Greys_r", add_boxes=False, alpha=1, blend=False, output=mask_output_filename) output_masks.append(mask_output_filename) except Exception as e: print(f"Error showing or saving file for {tile_filename}: {e}")
And there are the tiles: tiles.zip
No branches or pull requests
Hello, I'm ussing samgeo2 text prompt
I have a list of images that are going to be segmented one by one, the process runs fine, all the images meet the 8-bit RGB requirements.
The loop runs and sam.show_anns(cmap="Greys_r", add_boxes=False, alpha=1, blend=False, output=mask_output_filename) shows the segmented image:
But when saving the output it returns the error
TypeError: Cannot handle this data type: (1, 1), <i8
This is the entire error:
KeyError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/PIL/Image.py in fromarray(obj, mode)
3276 try:
-> 3277 mode, rawmode = _fromarray_typemap[typekey]
3278 except KeyError as e:
KeyError: ((1, 1), '<i8')
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
4 frames
in <cell line: 14>()
75 # Procesar y segmentar el tile
76 tile_filename = process_tile(tile, transform, i, j)
---> 77 mask_output_filename = segment_image(tile_filename, output_dir)
78 output_masks.append(mask_output_filename)
79
in segment_image(tile_filename, output_dir)
53 title="Segmentación automatica",
54 )
---> 55 sam.show_anns(cmap="Greys_r", add_boxes=False, alpha=1, blend=False, output=mask_output_filename)
56
57 print(f"Segmentación y máscara guardada para {tile_filename}")
/usr/local/lib/python3.10/dist-packages/samgeo/text_sam.py in show_anns(self, figsize, axis, cmap, alpha, add_boxes, box_color, box_linewidth, title, output, blend, **kwargs)
569 plt.savefig(output, **kwargs)
570 else:
--> 571 array_to_image(self.prediction, output, self.source)
572
573 def raster_to_vector(self, image, output, simplify_tolerance=None, **kwargs):
/usr/local/lib/python3.10/dist-packages/samgeo/common.py in array_to_image(array, output, source, dtype, compress, **kwargs)
1525
1526 else:
-> 1527 img = Image.fromarray(array)
1528 img.save(output, **kwargs)
1529
/usr/local/lib/python3.10/dist-packages/PIL/Image.py in fromarray(obj, mode)
3279 typekey_shape, typestr = typekey
3280 msg = f"Cannot handle this data type: {typekey_shape}, {typestr}"
-> 3281 raise TypeError(msg) from e
3282 else:
3283 rawmode = mode
TypeError: Cannot handle this data type: (1, 1), <i8
The same thing happens if I add the output inside sam.predict
Any ideas, solutions, alternatives to save the result?
Curiously, if I pass the image one by one through the samgeo2 text prompt example, they work without any problem.
The text was updated successfully, but these errors were encountered: