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

Interactive segmentation with input prompts. TypeError: Image data of dtype <U117 cannot be converted to float #124

Closed
oscarbau opened this issue Jun 26, 2023 · 0 comments · Fixed by #131
Labels
bug Something isn't working

Comments

@oscarbau
Copy link

Environment Information

  • samgeo version: 0.8.3
  • Python version: 3.9.16
  • Operating System: Windows 10

Description

Error when trying to show segmentation boxes after interactive segmentation with input prompts

What I Did

image

sam = SamGeo(
    model_type="vit_h",
    checkpoint="sam_vit_h_4b8939.pth",
    automatic=False,
    sam_kwargs=None,
)

sam.show_map()


sam.show_anns(
    cmap='Greens',
    box_color='red',
    title='Automatic Segmentation of Houses',
    blend=True,
)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[14], line 1
----> 1 sam.show_anns(
      2     cmap='Greens',
      3     box_color='red',
      4     title='Automatic Segmentation of Houses',
      5     blend=True,
      6 )

File ~\miniconda3\envs\geo\lib\site-packages\samgeo\samgeo.py:358, in SamGeo.show_anns(self, figsize, axis, alpha, output, blend, **kwargs)
    355     return
    357 plt.figure(figsize=figsize)
--> 358 plt.imshow(self.image)
    360 sorted_anns = sorted(anns, key=(lambda x: x["area"]), reverse=True)
    362 ax = plt.gca()

File ~\miniconda3\envs\geo\lib\site-packages\matplotlib\pyplot.py:2695, in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, interpolation_stage, filternorm, filterrad, resample, url, data, **kwargs)
   2689 @_copy_docstring_and_deprecators(Axes.imshow)
   2690 def imshow(
   2691         X, cmap=None, norm=None, *, aspect=None, interpolation=None,
   2692         alpha=None, vmin=None, vmax=None, origin=None, extent=None,
   2693         interpolation_stage=None, filternorm=True, filterrad=4.0,
   2694         resample=None, url=None, data=None, **kwargs):
-> 2695     __ret = gca().imshow(
   2696         X, cmap=cmap, norm=norm, aspect=aspect,
   2697         interpolation=interpolation, alpha=alpha, vmin=vmin,
   2698         vmax=vmax, origin=origin, extent=extent,
   2699         interpolation_stage=interpolation_stage,
   2700         filternorm=filternorm, filterrad=filterrad, resample=resample,
   2701         url=url, **({"data": data} if data is not None else {}),
   2702         **kwargs)
   2703     sci(__ret)
   2704     return __ret

File ~\miniconda3\envs\geo\lib\site-packages\matplotlib\__init__.py:1442, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1439 @functools.wraps(func)
   1440 def inner(ax, *args, data=None, **kwargs):
   1441     if data is None:
-> 1442         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1444     bound = new_sig.bind(ax, *args, **kwargs)
   1445     auto_label = (bound.arguments.get(label_namer)
   1446                   or bound.kwargs.get(label_namer))

File ~\miniconda3\envs\geo\lib\site-packages\matplotlib\axes\_axes.py:5665, in Axes.imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, interpolation_stage, filternorm, filterrad, resample, url, **kwargs)
   5657 self.set_aspect(aspect)
   5658 im = mimage.AxesImage(self, cmap=cmap, norm=norm,
   5659                       interpolation=interpolation, origin=origin,
   5660                       extent=extent, filternorm=filternorm,
   5661                       filterrad=filterrad, resample=resample,
   5662                       interpolation_stage=interpolation_stage,
   5663                       **kwargs)
-> 5665 im.set_data(X)
   5666 im.set_alpha(alpha)
   5667 if im.get_clip_path() is None:
   5668     # image does not already have clipping set, clip to axes patch

File ~\miniconda3\envs\geo\lib\site-packages\matplotlib\image.py:701, in _ImageBase.set_data(self, A)
    697 self._A = cbook.safe_masked_invalid(A, copy=True)
    699 if (self._A.dtype != np.uint8 and
    700         not np.can_cast(self._A.dtype, float, "same_kind")):
--> 701     raise TypeError("Image data of dtype {} cannot be converted to "
    702                     "float".format(self._A.dtype))
    704 if self._A.ndim == 3 and self._A.shape[-1] == 1:
    705     # If just one dimension assume scalar and apply colormap
    706     self._A = self._A[:, :, 0]

TypeError: Image data of dtype <U117 cannot be converted to float

@oscarbau oscarbau added the bug Something isn't working label Jun 26, 2023
@giswqs giswqs linked a pull request Jun 28, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant