最近用了Grounded-Segment-Anything来做text prompt的语义分割。按照官方教程安装好后,运行 grounding_dino demo:
python grounding_dino_demo.py
报错如下:
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like bert-base-uncased is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
参考Grounded-Segment-Anything/issues/75的comment:
Here is my workaround to run the model without connecting to huggingface:
Step 1: download necessary files listed in huggingface-bert-base-uncased, including config.json, flax_model.msgpack, pytorch_model.bin, tf_model.h5, tokenizer.json, tokenizer_config.json, vocab.txt
Step 2: put downloaded files (Step 1) into your local folder. For example, the local folder could be Grounded-Segment-Anything/huggingface/bert-base-uncased
Step 3: modify text_encoder_type in get_tokenlizer.py#L17
and get_tokenlizer.py#L23 to your local folder (defined in Step 2)
Step 4: run the model and enjoy it
至于step3参考Grounded-Segment-Anything/issues/346,修改如下:
# tokenizer = AutoTokenizer.from_pretrained(text_encoder_type)
tokenizer = AutoTokenizer.from_pretrained('YOUR PATH/bert-base-uncased', cache_dir='bert-base-uncased')
# return BertModel.from_pretrained(text_encoder_type)
return BertModel.from_pretrained('YOUR PATH/bert-base-uncased', local_files_only=True)
修改后就可以了,如果还是不能解决建议参考GroundingDINO官方repo的issue。