当前位置: 代码网 > 科技>人工智能>aigc > 运行StableDiffusionInpaintPipeline的Example时报错:OSError: Cannot load model runwayml/stable-diffusion-...

运行StableDiffusionInpaintPipeline的Example时报错:OSError: Cannot load model runwayml/stable-diffusion-...

2024年07月28日 aigc 我要评论
从Example代码里面看到,应该是要下载runwayml/stable-diffusion-inpainting模型。原因是:国内无法服务器无法直接连接上huggingface。解决办法是:开代理把模型下载到本地再上传到服务器端。

项目地址:

https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpainticon-default.png?t=n7t8https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/inpaint在云服务器端运行下面给出的example的时候出现报错:

(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. 
原因是:国内无法服务器无法直接连接上huggingface。

解决办法是:开代理把模型下载到本地再上传到服务器端。(不管是下载到本地,还是直接同步到服务器端,只要是国内的网络都要把代理打开)

我运行的example代码是:

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代码里面看到,应该是要下载runwayml/stable-diffusion-inpainting模型

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")

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com