continue-revolution / sd-webui-segment-anything

Segment Anything for Stable Diffusion WebUI
3.41k stars 206 forks source link

[Bug]: 怎样屏蔽代码里自动下载models--bert-base-uncased? #196

Open MaggieLxj opened 9 months ago

MaggieLxj commented 9 months ago

Is there an existing issue for this?

Have you updated WebUI and this extension to the latest version?

Do you understand that you should read the 1st item of https://github.com/continue-revolution/sd-webui-segment-anything#faq if you cannot install GroundingDINO?

Do you understand that you should use the latest ControlNet extension and enable external control if you want SAM extension to control ControlNet?

Do you understand that you should read the 2nd item of https://github.com/continue-revolution/sd-webui-segment-anything#faq if you observe problems like AttributeError bool object has no attribute enabled and TypeError bool object is not subscriptable?

What happened?

webui启动要求不能开代理,但是groundingdino插件启动会自动下载models--bert-base-uncased,而这个下载必须通过代理进行,所以有没有办法能直接在代码里屏蔽掉自动下载,而使用手动下载的bert-base-uncased模型?

Steps to reproduce the problem

直接使用groundingdino插件功能

What should have happened?

屏蔽自动下载,使用已下载好的bert-base-uncased模型

Commit where the problem happens

webui: 正常运行 extension: groundingdino出错

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

No

Console logs

GroundingDINO dynamic library have been successfully built.
Running GroundingDINO Inference
Initializing GroundingDINO GroundingDINO_SwinT_OGC (694MB)
final text_encoder_type: bert-base-uncased
Traceback (most recent call last):
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connection.py", line 203, in _new_conn
    sock = connection.create_connection(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

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

Traceback (most recent call last):
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1096, in _validate_conn
    conn.connect()
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connection.py", line 611, in connect
    self.sock = sock = self._new_conn()
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connection.py", line 218, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa7208ef3d0>: Failed to establish a new connection: [Errno 101] Network is unreachable

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

Traceback (most recent call last):
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/urllib3/util/retry.py", line 515, 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: /bert-base-uncased/resolve/main/config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa7208ef3d0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1238, in hf_hub_download
    metadata = get_hf_file_metadata(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1631, in get_hf_file_metadata
    r = _request_wrapper(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 385, in _request_wrapper
    response = _request_wrapper(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 408, in _request_wrapper
    response = get_session().request(method=method, url=url, **params)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 67, in send
    return super().send(request, *args, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/config.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa7208ef3d0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: 6fa3b7cc-47f9-4e58-aa4a-3b932ed31b90)')

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

Traceback (most recent call last):
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/utils/hub.py", line 417, in cached_file
    resolved_file = hf_hub_download(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1371, in hf_hub_download
    raise LocalEntryNotFoundError(
huggingface_hub.utils._errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/extensions/sd-webui-segment-anything/scripts/sam.py", line 247, in dino_predict
    boxes_filt, install_success = dino_predict_internal(input_image, dino_model_name, text_prompt, box_threshold)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/extensions/sd-webui-segment-anything/scripts/dino.py", line 174, in dino_predict_internal
    dino_model = load_dino_model(dino_model_name, install_success)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/extensions/sd-webui-segment-anything/scripts/dino.py", line 120, in load_dino_model
    dino = build_model(args)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/groundingdino/models/__init__.py", line 17, in build_model
    model = build_func(args)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/groundingdino/models/GroundingDINO/groundingdino.py", line 388, in build_groundingdino
    model = GroundingDINO(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/groundingdino/models/GroundingDINO/groundingdino.py", line 107, in __init__
    self.tokenizer = get_tokenlizer.get_tokenlizer(text_encoder_type)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/groundingdino/util/get_tokenlizer.py", line 19, in get_tokenlizer
    tokenizer = AutoTokenizer.from_pretrained(text_encoder_type)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 658, in from_pretrained
    config = AutoConfig.from_pretrained(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 944, in from_pretrained
    config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/configuration_utils.py", line 574, in get_config_dict
    config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/configuration_utils.py", line 629, in _get_config_dict
    resolved_config_file = cached_file(
  File "/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/utils/hub.py", line 452, in cached_file
    raise EnvironmentError(
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'.

Additional information

查看过关于groundingdino问题的多个issue回复,已经尝试过把bert-base-uncased放在/home/lxj/.cache/huggingface/hub/models--bert-base-uncased下,以及/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/extensions/sd-webui-segment-anything/local_groundingdino/models/GroundingDINO/bert-base-uncased,以及/home/lxj/Documents/code/ScenarioTool/stable-diffusion-webui/venv/lib/python3.10/site-packages/groundingdino/util/bert-base-uncased,三种方式均不能调用现成的模型

light-and-ray commented 9 months ago

Try to use this environment variable TRANSFORMERS_OFFLINE=1

MaggieLxj commented 9 months ago

Excuse me, please tell me where to put this environment variable TRANSFORMERS_OFFLINE=1. Thanks very much!

light-and-ray commented 9 months ago

Write set TRANSFORMERS_OFFLINE=1 in your bat file if Windows, export TRANSFORMERS_OFFLINE=1 in .sh file if Linux. I had a problem when my Internet was disabled, and segment anything froze for about 10 seconds

jackyjinjing commented 2 weeks ago

can refer to this pr : https://github.com/IDEA-Research/Grounded-Segment-Anything/pull/517 which has bean merged