Skip to content
New issue

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

Segment anything workflow issues #8

Closed
miguel-geo opened this issue Jul 5, 2023 · 2 comments
Closed

Segment anything workflow issues #8

miguel-geo opened this issue Jul 5, 2023 · 2 comments

Comments

@miguel-geo
Copy link

miguel-geo commented Jul 5, 2023

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()

@Yarroudh
Copy link
Owner

Yarroudh commented Jul 7, 2023

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.

@Yarroudh
Copy link
Owner

Yarroudh commented Jul 7, 2023

This issue was fixed with v0.1.8. Using segment-anything algorithm should work without errors.

@Yarroudh Yarroudh closed this as completed Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants