Segment anything workflow issues
miguel-geo opened this issue · 2 comments
While im trying to run the segment anything workflow. I ran into some issues.
TypeError: unhashable type: 'numpy.ndarray'
while trying to run the image_to_cloud function in the line :
if rgb not in unique_values:
my solution was rgb=tuple(rgb)
.
Another issue i was running into is when rearraring the array that rasterio returns when reading a tif.
image_rgb = image_rgb.reshape((image_rgb.shape[1], image_rgb.shape[2], image_rgb.shape[0]))
instead i use:
image_rgb = np.transpose(image_rgb, (1, 2, 0))
And finally in the part of the segment method:
with rasterio.open(labels_path, 'r') as src:
segmented_image = src.read()
segmented_image = np.squeeze(segmented_image)
print(f'- Generating segment IDs...')
segment_ids = image_to_cloud(points, minx, maxy, segmented_image, self.resolution)
end = time.time()
the error was that most of the points didnt pass the if stament:
if not (0 <= pixel_x < image.shape[1]) or not (0 <= pixel_y < image.shape[0]):
because rasterio arrange width, height,bands different than the classic.
so i use
with rasterio.open(labels_path, 'r') as src:
segmented_image = src.read()
segmented_image = np.squeeze(segmented_image)
segmented_image=np.transpose(segmented_image, (1, 2, 0))
print(f'- Generating segment IDs...')
segment_ids = image_to_cloud(points, minx, maxy, segmented_image, self.resolution)
end = time.time()
Hello @miguel-geo,
I think you are rights because rasterio reads images to shape (bands, rows, columns)
. I'll look at this in the code.
Thanks for your contribution.
This issue was fixed with v0.1.8. Using segment-anything
algorithm should work without errors.