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

[Bug]: huggingface Download failed #2506

Closed
1 task done
phhh-xh opened this issue Jan 14, 2025 · 5 comments
Closed
1 task done

[Bug]: huggingface Download failed #2506

phhh-xh opened this issue Jan 14, 2025 · 5 comments

Comments

@phhh-xh
Copy link

phhh-xh commented Jan 14, 2025

Describe the bug

/timm/wide_resnet50_2.racm_in1k/resolve/main/model.safetensors Patchcore model
Download failed, which folder should the downloaded files be placed in?

Dataset

MVTec

Model

PatchCore

Steps to reproduce the behavior

python train.py

train.py 

> # 1. Import required modules
> from anomalib.data import MVTec
> from anomalib.engine import Engine
> from anomalib.models import EfficientAd, Patchcore
> 
> if __name__=="__main__":
>     # 2. Create a dataset
>     # MVTec is a popular dataset zhefor anomaly detection
>     datamodule = MVTec(
>         root="./datasets/MVTec",  # Path to download/store the dataset
>         category="screw",  # MVTec category to use
>         train_batch_size=8,  # Number of images per training batch
>         eval_batch_size=32,  # Number of images per validation/test batch
>         num_workers=0,  # Number of parallel processes for data loading
>     )
> 
>     # 3. Initialize the model
>     # EfficientAd is a good default choice for beginners
>     # model = EfficientAd()
>     model = Patchcore()
> 
>     # 4. Create the training engine
>     engine = Engine(max_epochs=10)  # Train for 10 epochs
> 
>     # 5. Train the model
>     engine.fit(datamodule=datamodule, model=model)

OS information

OS information:

  • OS: Windows10
  • Python version: 3.10.0
  • Anomalib version: 2.0.0b2

Expected behavior

Can load the model correctly

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

No response

Configuration YAML

none

Logs

FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
  warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
INFO:anomalib.models.components.base.anomalib_module:Initializing Patchcore model.
INFO:timm.models._builder:Loading pretrained weights from Hugging Face hub (timm/wide_resnet50_2.racm_in1k)
Traceback (most recent call last):
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\connectionpool.py", line 773, in urlopen
    self._prepare_proxy(conn)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\connectionpool.py", line 1042, in _prepare_proxy
    conn.connect()
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\connection.py", line 713, in connect
    self.sock = sock = self._connect_tls_proxy(self.host, sock)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\connection.py", line 813, in _connect_tls_proxy
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\connection.py", line 920, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\util\ssl_.py", line 460, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\util\ssl_.py", line 504, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "D:\Install\miniconda\envs\ano\lib\ssl.py", line 512, in wrap_socket
    return self.sslsocket_class._create(
  File "D:\Install\miniconda\envs\ano\lib\ssl.py", line 1070, in _create
    self.do_handshake()
  File "D:\Install\miniconda\envs\ano\lib\ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
FileNotFoundError: [Errno 2] No such file or directory

The above exception was the direct cause of the following exception:

urllib3.exceptions.ProxyError: ('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory'))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Install\miniconda\envs\ano\lib\site-packages\requests\adapters.py", line 667, in send
    resp = conn.urlopen(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\connectionpool.py", line 841, in urlopen
    retries = retries.increment(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\urllib3\util\retry.py", line 519, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /timm/wide_resnet50_2.racm_in1k/resolve/main/model.safetensors (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Install\miniconda\envs\ano\lib\site-packages\timm\models\_factory.py", line 126, in create_model
    model = create_fn(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\timm\models\resnet.py", line 1520, in wide_resnet50_2
    return _create_resnet('wide_resnet50_2', pretrained, **dict(model_args, **kwargs))
  File "D:\Install\miniconda\envs\ano\lib\site-packages\timm\models\resnet.py", line 642, in _create_resnet
    return build_model_with_cfg(ResNet, variant, pretrained, **kwargs)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\timm\models\_builder.py", line 436, in build_model_with_cfg
    load_pretrained(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\timm\models\_builder.py", line 213, in load_pretrained
    state_dict = load_state_dict_from_hf(pretrained_loc, weights_only=True, cache_dir=cache_dir)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\timm\models\_hub.py", line 211, in load_state_dict_from_hf
    cached_safe_file = hf_hub_download(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\file_download.py", line 860, in hf_hub_download
    return _hf_hub_download_to_cache_dir(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\file_download.py", line 923, in _hf_hub_download_to_cache_dir
    (url_to_download, etag, commit_hash, expected_size, head_call_error) = _get_metadata_or_catch_error(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\file_download.py", line 1374, in _get_metadata_or_catch_error
    metadata = get_hf_file_metadata(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\utils\_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\file_download.py", line 1294, in get_hf_file_metadata
    r = _request_wrapper(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\file_download.py", line 278, in _request_wrapper
    response = _request_wrapper(
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\file_download.py", line 301, in _request_wrapper
    response = get_session().request(method=method, url=url, **params)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\huggingface_hub\utils\_http.py", line 93, in send
    return super().send(request, *args, **kwargs)
  File "D:\Install\miniconda\envs\ano\lib\site-packages\requests\adapters.py", line 694, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /timm/wide_resnet50_2.racm_in1k/resolve/main/model.safetensors (Caused by ProxyError('Unable to connect to proxy', FileNotFoundError(2, 'No such file or directory')))"), '(Request ID: 8bccae81-e665-4402-9961-dfe6774e38ab)')

Code of Conduct

  • I agree to follow this project's Code of Conduct
@alexriedel1
Copy link
Contributor

Hi! I cannot reproduce the error. maybe huggingface was just offline at that moment.

@phhh-xh
Copy link
Author

phhh-xh commented Jan 17, 2025

Hi! I cannot reproduce the error. maybe huggingface was just offline at that moment.

hi,I can manually download the weights, where do I need to put the downloaded file to load it?

@alexriedel1
Copy link
Contributor

Hi! I cannot reproduce the error. maybe huggingface was just offline at that moment.

hi,I can manually download the weights, where do I need to put the downloaded file to load it?

You can find a solution to do this here: #2439

@phhh-xh
Copy link
Author

phhh-xh commented Jan 20, 2025

Hi! I cannot reproduce the error. maybe huggingface was just offline at that moment.

hi,I can manually download the weights, where do I need to put the downloaded file to load it?

You can find a solution to do this here: #2439

I think it work

model = Patchcore(
        backbone="wide_resnet50_2",
        layers=["layer1", "layer2", "layer3"],
        pre_trained=False
    )

model.model.feature_extractor.feature_extractor = timm.create_model(
    "wide_resnet50_2",
    pretrained=True,
    pretrained_cfg_overlay=dict(file=r'..\.cache\torch\hub\checkpoints\wide_resnet50_2-95faca4d.pth'),
    features_only=True,
    exportable=True,
    out_indices=model.model.feature_extractor.idx
    ) 

@phhh-xh phhh-xh closed this as completed Jan 28, 2025
@samet-akcay
Copy link
Contributor

What do you think if we refactor backbone that can get str or nn.Module? If str is passed, Anomalib would create the feature extractor under the hood. For any custom configuration, user can create a feature extractor via timm.create_model and pass it to the model.

Currently, the customising the feature extractor might be a bit limited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants