YvanYin / Metric3D

The repo for "Metric3D: Towards Zero-shot Metric 3D Prediction from A Single Image" and "Metric3Dv2: A Versatile Monocular Geometric Foundation Model..."
https://jugghm.github.io/Metric3Dv2/
Creative Commons Zero v1.0 Universal
1.05k stars 73 forks source link

HTTPError when trying to do inference using torch #108

Open Arjun-G-Ravi opened 1 month ago

Arjun-G-Ravi commented 1 month ago

I tried the following code, but received HTTPError

import torch
model = torch.hub.load('yvanyin/metric3d', 'metric3d_vit_small', pretrain=True)
pred_depth, confidence, output_dict = model.inference({'input': rgb})

Error

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
Cell In[3], line 2
      1 import torch
----> 2 model = torch.hub.load('yvanyin/metric3d', 'metric3d_vit_small', pretrain=True)
      3 pred_depth, confidence, output_dict = model.inference({'input': rgb})

File ~/Desktop/GitHub/project-1/.venv/lib/python3.10/site-packages/torch/hub.py:563, in load(repo_or_dir, model, source, trust_repo, force_reload, verbose, skip_validation, *args, **kwargs)
    559     raise ValueError(
    560         f'Unknown source: "{source}". Allowed values: "github" | "local".')
    562 if source == 'github':
--> 563     repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, trust_repo, "load",
    564                                        verbose=verbose, skip_validation=skip_validation)
    566 model = _load_local(repo_or_dir, model, *args, **kwargs)
    567 return model

File ~/Desktop/GitHub/project-1/.venv/lib/python3.10/site-packages/torch/hub.py:230, in _get_cache_or_reload(github, force_reload, trust_repo, calling_fn, verbose, skip_validation)
    227 else:
    228     # Validate the tag/branch is from the original repo instead of a forked repo
    229     if not skip_validation:
--> 230         _validate_not_a_forked_repo(repo_owner, repo_name, ref)
    232     cached_file = os.path.join(hub_dir, normalized_br + '.zip')
    233     _remove_if_exists(cached_file)

File ~/Desktop/GitHub/project-1/.venv/lib/python3.10/site-packages/torch/hub.py:189, in _validate_not_a_forked_repo(repo_owner, repo_name, ref)
    187 page += 1
    188 url = f'{url_prefix}?per_page=100&page={page}'
--> 189 response = json.loads(_read_url(Request(url, headers=headers)))
    190 # Empty response means no more data to process
    191 if not response:

File ~/Desktop/GitHub/project-1/.venv/lib/python3.10/site-packages/torch/hub.py:172, in _read_url(url)
    171 def _read_url(url):
--> 172     with urlopen(url) as r:
    173         return r.read().decode(r.headers.get_content_charset('utf-8'))

File /usr/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    214 else:
    215     opener = _opener
--> 216 return opener.open(url, data, timeout)

File /usr/lib/python3.10/urllib/request.py:525, in OpenerDirector.open(self, fullurl, data, timeout)
    523 for processor in self.process_response.get(protocol, []):
    524     meth = getattr(processor, meth_name)
--> 525     response = meth(req, response)
    527 return response

File /usr/lib/python3.10/urllib/request.py:634, in HTTPErrorProcessor.http_response(self, request, response)
    631 # According to RFC 2616, "2xx" code indicates that the client's
    632 # request was successfully received, understood, and accepted.
    633 if not (200 <= code < 300):
--> 634     response = self.parent.error(
    635         'http', request, response, code, msg, hdrs)
    637 return response

File /usr/lib/python3.10/urllib/request.py:563, in OpenerDirector.error(self, proto, *args)
    561 if http_err:
    562     args = (dict, 'default', 'http_error_default') + orig_args
--> 563     return self._call_chain(*args)

File /usr/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    494 for handler in handlers:
    495     func = getattr(handler, meth_name)
--> 496     result = func(*args)
    497     if result is not None:
    498         return result

File /usr/lib/python3.10/urllib/request.py:643, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
    642 def http_error_default(self, req, fp, code, msg, hdrs):
--> 643     raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: HTTP Error 401: Unauthorized

Am I missing something?

ZachL1 commented 1 month ago

I can't reproduce the error and I can't deduce what's causing it from the information you've provided. But it looks like it could be an issue with your environment or something to do with torchhub. You could perhaps try to find the cause from google or the torchhub community, or provide more information and reproducible examples such as google colab.