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 and vector outputs are single value #34

Closed
calebpan opened this issue May 9, 2023 · 5 comments
Closed

segment and vector outputs are single value #34

calebpan opened this issue May 9, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@calebpan
Copy link

calebpan commented May 9, 2023

Environment Information

  • samgeo version: segment_geospatial-0.4.0-py2.py3-none-any.whl
  • Python version: 3.1
  • Operating System: Windows 10

Description

Ran the example code provided in both pycharm on local machine and in Google Colab here:
https://colab.research.google.com/github/opengeos/segment-geospatial/blob/main/docs/examples/satellite.ipynb#scrollTo=Gqby0rFINPNR

Output vectors and segments return single value of 255. Does not return the same output as shown in example.

image

What I Did

import os
from samgeo import SamGeo, tms_to_geotiff, get_basemaps
bbox = [-122.0142108,37.0539328,-122.0129377,37.0554187]

image = 'satellite_v6.tif'
shapefile = "segment_v6.shp"
mask = 'segment_v6.tif'
tms_to_geotiff(output=image, bbox = bbox, zoom=20, source="Satellite", overwrite=True)

# '''
# Initialize SAM class
# '''
out_dir = os.path.join(os.path.expanduser("~"), "Downloads")
checkpoint = os.path.join(out_dir, "sam_vit_h_4b8939.pth")

sam = SamGeo(
   model_type="vit_h",
   checkpoint=checkpoint,
   sam_kwargs=None,
)
#
# '''
# Segment the image
# Set batch=True to segment the image in batches. This is useful for large images that cannot fit in memory.
# '''
print('Generating segments...')

sam.generate(
   image, mask, batch=True, foreground=True, erosion_kernel=(3, 3), mask_multiplier=255
)

# '''
# Polygonize the raster data
# Save the segmentation results as a GeoPackage file.
# '''
print('Creating shapefile...')
sam.tiff_to_vector(mask, shapefile)

Returns same results as in the Colab example.

@calebpan calebpan added the bug Something isn't working label May 9, 2023
@giswqs
Copy link
Member

giswqs commented May 9, 2023

This bug has been fixed in #29, but it has not been released to PyPI yet. You can run the following to install it from GitHub. Otherwise, wait until the next release later this week.

pip install git+https://github.com/opengeos/segment-geospatial.git

@giswqs
Copy link
Member

giswqs commented May 9, 2023

Or install v0.3.0.

pip install segment-geospatial==0.3.0

@calebpan
Copy link
Author

calebpan commented May 9, 2023

In line. resintalled version 0.3.0

sam.generate() returns an error:
mask = "segment.tiff"
sam.generate(
image, mask, batch=True, foreground=True, erosion_kernel=(3, 3), mask_multiplier=255
)

TypeError Traceback (most recent call last)
in <cell line: 2>()
1 mask = "segment.tiff"
----> 2 sam.generate(
3 image, mask, erosion_kernel=(3, 3), mask_multiplier=255
4 )

/usr/local/lib/python3.10/dist-packages/samgeo/samgeo.py in generate(self, in_path, out_path, **kwargs)
110 """
111
--> 112 return tiff_to_tiff(in_path, out_path, self, **kwargs)
113
114 def image_to_image(self, image, **kwargs):

TypeError: tiff_to_tiff() got an unexpected keyword argument 'erosion_kernel'

@giswqs
Copy link
Member

giswqs commented May 9, 2023

It is probably because the notebook has been updated. It is no longer compatible with v0.3. Try installing from Github

@calebpan
Copy link
Author

calebpan commented May 9, 2023

You're right, thank you

@calebpan calebpan closed this as completed May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants