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

Error if I want to pass a vector file path as input for predict() #294

Open
ericko443 opened this issue Jun 18, 2024 · 0 comments
Open

Error if I want to pass a vector file path as input for predict() #294

ericko443 opened this issue Jun 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ericko443
Copy link

Environment Information

  • samgeo version: 0.10.6
  • Python version: 3.12.3
  • Operating System: Ubuntu 20.04.6 LTS

Description

I wanted to run sam.predict() on an image for which I previously generated a vector file (.shp) containing several point geometries indicating the objects I want to segment. The documentation says that the points to be used in sam.predict() can also be specified as a file path to a vector dataset. However, I keep receiving an error (see below). I think the error lies in the vector_to_geojson() function that gets called within predict(). If I don't supply it with a URL then it fails because it wants to call download_file() but I only specify a file path so I would not expect download_file() to be called. Is this a bug? Or did I misunderstand the allowed input format?

What I Did

Code:

from samgeo import SamGeo

checkpoint = '.../sam_vit_h_4b8939.pth'
image = '.../input_img.tif'
randpoints = '.../input_pts.shp'

device = 'cuda' if torch.cuda.is_available() else 'cpu'
sam = SamGeo(
    checkpoint=checkpoint,
    model_type='vit_h',
    device=device,
    sam_kwargs=None,
    automatic=False,
)

sam.set_image(image)
sam.predict(randpoints)

Output:

Traceback (most recent call last):

  Cell In[45], line 17
    sam.predict(randpoints)

  File ~/anaconda3/envs/spyder-env/lib/python3.12/site-packages/samgeo/samgeo.py:533 in predict
    point_coords = vector_to_geojson(point_coords)

  File ~/anaconda3/envs/spyder-env/lib/python3.12/site-packages/samgeo/common.py:727 in vector_to_geojson
    filename = download_file(filename)

  File ~/anaconda3/envs/spyder-env/lib/python3.12/site-packages/samgeo/common.py:146 in download_file
    out_dir = os.path.abspath(os.path.dirname(output))

  File <frozen posixpath>:181 in dirname

TypeError: expected str, bytes or os.PathLike object, not NoneType
@ericko443 ericko443 added the bug Something isn't working label Jun 18, 2024
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

1 participant