opengeos / segment-geospatial

A Python package for segmenting geospatial data with the Segment Anything Model (SAM)
https://samgeo.gishub.org
MIT License
3.05k stars 313 forks source link

MissingSchema: Invalid URL 'vit_h': No scheme supplied. #178

Closed oscarbau closed 1 year ago

oscarbau commented 1 year ago

Environment Information

Description

Running the default example of samgeo.hq_sam

What I Did

import os
import leafmap
from samgeo.hq_sam import SamGeo, tms_to_geotiff

sam = SamGeo(
    model_type="vit_h",  # can be vit_h, vit_b, vit_l, vit_tiny
    automatic=False,
    sam_kwargs=None,
)
---------------------------------------------------------------------------
MissingSchema                             Traceback (most recent call last)
Cell In[7], line 1
----> 1 sam = SamGeo(
      2     model_type="vit_h",  # can be vit_h, vit_b, vit_l, vit_tiny
      3     automatic=False,
      4     sam_kwargs=None,
      5 )

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\samgeo\hq_sam.py:69, in SamGeo.__init__(self, model_type, automatic, device, checkpoint_dir, hq, sam_kwargs, **kwargs)
     67     kwargs.pop("checkpoint")
     68 else:
---> 69     checkpoint = download_checkpoint(model_type, checkpoint_dir, hq)
     71 # Use cuda if available
     72 if device is None:

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\samgeo\common.py:207, in download_checkpoint(url, output, overwrite, **kwargs)
    192     model_types = {
    193         "vit_h": {
    194             "name": "sam_vit_h_4b8939.pth",
   (...)
    204         },
    205     }
    206 else:
--> 207     model_types = {
    208         "vit_h": {
    209             "name": "sam_hq_vit_h.pth",
    210             "url": "https://drive.google.com/file/d/1qobFYrI4eyIANfBSmYcGuWRaSIXfMOQ8/view?usp=sharing",
    211         },
    212         "vit_l": {
    213             "name": "sam_hq_vit_l.pth",
    214             "url": "https://drive.google.com/file/d/1Uk17tDKX1YAKas5knI4y9ZJCo0lRVL0G/view?usp=sharing",
    215         },
    216         "vit_b": {
    217             "name": "sam_hq_vit_b.pth",
    218             "url": "https://drive.google.com/file/d/11yExZLOve38kRZPfRx_MRxfIAKmfMY47/view?usp=sharing",
    219         },
    220         "vit_tiny": {
    221             "name": "sam_hq_vit_tiny.pth",
    222             "url": "https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_tiny.pth",
    223         },
    224     }
    226 if model_type not in model_types:
    227     raise ValueError(
    228         f"Invalid model_type: {model_type}. It must be one of {', '.join(model_types)}"
    229     )

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\samgeo\common.py:160, in download_file(url, output, quiet, proxy, speed, use_cookies, verify, id, fuzzy, resume, unzip, overwrite, subfolder)
    157 if "https://drive.google.com/file/d/" in url:
    158     fuzzy = True
--> 160 output = gdown.download(
    161     url, output, quiet, proxy, speed, use_cookies, verify, id, fuzzy, resume
    162 )
    164 if unzip and output.endswith(".zip"):
    165     with zipfile.ZipFile(output, "r") as zip_ref:

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\gdown\download.py:161, in download(url, output, quiet, proxy, speed, use_cookies, verify, id, fuzzy, resume, format)
    159 while True:
    160     try:
--> 161         res = sess.get(url, stream=True, verify=verify)
    162     except requests.exceptions.ProxyError as e:
    163         print(
    164             "An error has occurred using proxy:",
    165             sess.proxies,
    166             file=sys.stderr,
    167         )

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\requests\sessions.py:600, in Session.get(self, url, **kwargs)
    592 r"""Sends a GET request. Returns :class:`Response` object.
    593 
    594 :param url: URL for the new :class:`Request` object.
    595 :param \*\*kwargs: Optional arguments that ``request`` takes.
    596 :rtype: requests.Response
    597 """
    599 kwargs.setdefault("allow_redirects", True)
--> 600 return self.request("GET", url, **kwargs)

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\requests\sessions.py:573, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    560 # Create the Request.
    561 req = Request(
    562     method=method.upper(),
    563     url=url,
   (...)
    571     hooks=hooks,
    572 )
--> 573 prep = self.prepare_request(req)
    575 proxies = proxies or {}
    577 settings = self.merge_environment_settings(
    578     prep.url, proxies, stream, verify, cert
    579 )

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\requests\sessions.py:484, in Session.prepare_request(self, request)
    481     auth = get_netrc_auth(request.url)
    483 p = PreparedRequest()
--> 484 p.prepare(
    485     method=request.method.upper(),
    486     url=request.url,
    487     files=request.files,
    488     data=request.data,
    489     json=request.json,
    490     headers=merge_setting(
    491         request.headers, self.headers, dict_class=CaseInsensitiveDict
    492     ),
    493     params=merge_setting(request.params, self.params),
    494     auth=merge_setting(auth, self.auth),
    495     cookies=merged_cookies,
    496     hooks=merge_hooks(request.hooks, self.hooks),
    497 )
    498 return p

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\requests\models.py:368, in PreparedRequest.prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
    365 """Prepares the entire request with the given parameters."""
    367 self.prepare_method(method)
--> 368 self.prepare_url(url, params)
    369 self.prepare_headers(headers)
    370 self.prepare_cookies(cookies)

File ~\AppData\Local\miniconda3\envs\geo\lib\site-packages\requests\models.py:439, in PreparedRequest.prepare_url(self, url, params)
    436     raise InvalidURL(*e.args)
    438 if not scheme:
--> 439     raise MissingSchema(
    440         f"Invalid URL {url!r}: No scheme supplied. "
    441         f"Perhaps you meant [https://{](https://%7Burl/)[url](https://%7Burl/)}?"
    442     )
    444 if not host:
    445     raise InvalidURL(f"Invalid URL {url!r}: No host supplied")

MissingSchema: Invalid URL 'vit_h': No scheme supplied. Perhaps you meant https://vit_h/?
giswqs commented 1 year ago

I just tested it on Windows, it works fine. Try running the code again.

image

oscarbau commented 1 year ago

It works now... thanks!