項(xiàng)目地址:
https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpainthttps://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint在云服務(wù)器端運(yùn)行下面給出的Example的時(shí)候出現(xiàn)報(bào)錯(cuò):
(myconda) root@wnyrpE:/mnt/Diffusers/inpainting# python3 SD_inpaint_eg.py
Couldn't connect to the Hub: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/runwayml/stable-diffusion-inpainting (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa6c5357dc0>: Failed to establish a new connection: [Errno 110] Connection timed out'))"), '(Request ID: bebba422-c4d8-4797-a818-a00fe02957e8)').
Will try to load from local cache.
Traceback (most recent call last):
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/util/connection.py", line 95, in create_connection
raise err
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/util/connection.py", line 85, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connection.py", line 358, in connect
self.sock = conn = self._new_conn()
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa6c5357dc0>: Failed to establish a new connection: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /api/models/runwayml/stable-diffusion-inpainting (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa6c5357dc0>: Failed to establish a new connection: [Errno 110] Connection timed out'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/diffusers/pipelines/pipeline_utils.py", line 1656, in download
info = model_info(pretrained_model_name, token=token, revision=revision)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/huggingface_hub/hf_api.py", line 2084, in model_info
r = get_session().get(path, headers=headers, timeout=timeout, params=params)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/requests/sessions.py", line 542, in get
return self.request('GET', url, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/huggingface_hub/utils/_http.py", line 67, in send
return super().send(request, *args, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/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: /api/models/runwayml/stable-diffusion-inpainting (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa6c5357dc0>: Failed to establish a new connection: [Errno 110] Connection timed out'))"), '(Request ID: bebba422-c4d8-4797-a818-a00fe02957e8)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "SD_inpaint_eg.py", line 20, in <module>
pipe = StableDiffusionInpaintPipeline.from_pretrained(
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/diffusers/pipelines/pipeline_utils.py", line 1096, in from_pretrained
cached_folder = cls.download(
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/diffusers/pipelines/pipeline_utils.py", line 1905, in download
raise EnvironmentError(
OSError: Cannot load model runwayml/stable-diffusion-inpainting: model is not cached locally and an error occured while trying to fetch metadata from the Hub. Please check out the root cause in the stacktrace above.
原因是:國(guó)內(nèi)無法服務(wù)器無法直接連接上huggingface。
解決辦法是:開代理把模型下載到本地再上傳到服務(wù)器端。(不管是下載到本地,還是直接同步到服務(wù)器端,只要是國(guó)內(nèi)的網(wǎng)絡(luò)都要把代理打開)
我運(yùn)行的Example代碼是:文章來源:http://www.zghlxwxcb.cn/news/detail-837423.html
import PIL
import requests
import torch
from io import BytesIO
from diffusers import StableDiffusionInpaintPipeline
def download_image(url):
response = requests.get(url)
return PIL.Image.open(BytesIO(response.content)).convert("RGB")
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
init_image = download_image(img_url).resize((512, 512))
mask_image = download_image(mask_url).resize((512, 512))
pipe = StableDiffusionInpaintPipeline.from_pretrained(
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
從Example代碼里面看到,應(yīng)該是要下載runwayml/stable-diffusion-inpainting模型文章來源地址http://www.zghlxwxcb.cn/news/detail-837423.html
pipe = StableDiffusionInpaintPipeline.from_pretrained(
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")
注意修改腳本中的代碼:
pipe = StableDiffusionInpaintPipeline.from_pretrained(
"/本地/模型/路徑", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")
到了這里,關(guān)于運(yùn)行StableDiffusionInpaintPipeline的Example時(shí)報(bào)錯(cuò):OSError: Cannot load model runwayml/stable-diffusion-...的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!