timothybrooks / instruct-pix2pix

Other
6.1k stars 527 forks source link

About pix2pix access huggingface URL #112

Open yoker5262 opened 10 months ago

yoker5262 commented 10 months ago

my code: image = Image.fromarray(image) pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained("timbrooks/instruct-pix2pix", torch_dtype=torch.float16, safety_checker=None) pipe.to("cuda") pipe.scheduler = DDIMScheduler.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="scheduler") num_inference_steps = 200 image_guidance_scale = 2.1 guidance_scale = 8.35 images = pipe(text_prompt, image=image, num_inference_steps=num_inference_steps, image_guidance_scale=image_guidance_scale,guidance_scale=guidance_scale).images[0] images = np.array(images) numbers = datetime.now().strftime("%Y%m%d%H%M%S") cv2.imwrite(f"outputs/{imagename.split('.')[0]+str({image_guidance_scale})+':'+str({guidance_scale})+':'+str({num_inference_steps}) + ':'+ numbers + ':'+ text_prompt}.png", images)

error message: ╭───────────────────── Traceback (most recent call last) ──────────────────────╮ │ /home/yoker/codes/image-synthesis/imageSyn-algorthmsManage/algorithms_manage │ │ /algorithm_pool/model_code/instruct-nerf2nerf/main.py:61 in │ │ │ │ 58 │ # ) │ │ 59 │ │ │ 60 │ image = Image.fromarray(image) │ │ ❱ 61 │ pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained("timb │ │ 62 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ torch │ │ 63 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ safet │ │ 64 │ pipe.to("cuda") │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/diffusers/pipel │ │ ines/pipeline_utils.py:910 in from_pretrained │ │ │ │ 907 │ │ if not os.path.isdir(pretrained_model_name_or_path): │ │ 908 │ │ │ print(pretrained_model_name_or_path) │ │ 909 │ │ │ print(cache_dir) │ │ ❱ 910 │ │ │ cached_folder = cls.download( │ │ 911 │ │ │ │ pretrained_model_name_or_path, │ │ 912 │ │ │ │ cache_dir=cache_dir, │ │ 913 │ │ │ │ resume_download=resume_download, │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/diffusers/pipel │ │ ines/pipeline_utils.py:1221 in download │ │ │ │ 1218 │ │ │ │ 1219 │ │ if not local_files_only: │ │ 1220 │ │ │ try: │ │ ❱ 1221 │ │ │ │ info = model_info( │ │ 1222 │ │ │ │ │ pretrained_model_name, │ │ 1223 │ │ │ │ │ use_auth_token=use_auth_token, │ │ 1224 │ │ │ │ │ revision=revision, │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/huggingface_hub │ │ /utils/_validators.py:118 in _inner_fn │ │ │ │ 115 │ │ if check_use_auth_token: │ │ 116 │ │ │ kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__na │ │ 117 │ │ │ │ ❱ 118 │ │ return fn(*args, kwargs) │ │ 119 │ │ │ 120 │ return _inner_fn # type: ignore │ │ 121 │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/huggingface_hub │ │ /hf_api.py:1675 in model_info │ │ │ │ 1672 │ │ │ params["securityStatus"] = True │ │ 1673 │ │ if files_metadata: │ │ 1674 │ │ │ params["blobs"] = True │ │ ❱ 1675 │ │ r = get_session().get(path, headers=headers, timeout=timeout, │ │ 1676 │ │ hf_raise_for_status(r) │ │ 1677 │ │ d = r.json() │ │ 1678 │ │ return ModelInfo(d) │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/requests/sessio │ │ ns.py:602 in get │ │ │ │ 599 │ │ """ │ │ 600 │ │ │ │ 601 │ │ kwargs.setdefault("allow_redirects", True) │ │ ❱ 602 │ │ return self.request("GET", url, kwargs) │ │ 603 │ │ │ 604 │ def options(self, url, kwargs): │ │ 605 │ │ r"""Sends a OPTIONS request. Returns :class:Response object. │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/requests/sessio │ │ ns.py:589 in request │ │ │ │ 586 │ │ │ "allow_redirects": allow_redirects, │ │ 587 │ │ } │ │ 588 │ │ send_kwargs.update(settings) │ │ ❱ 589 │ │ resp = self.send(prep, send_kwargs) │ │ 590 │ │ │ │ 591 │ │ return resp │ │ 592 │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/requests/sessio │ │ ns.py:703 in send │ │ │ │ 700 │ │ start = preferred_clock() │ │ 701 │ │ │ │ 702 │ │ # Send the request │ │ ❱ 703 │ │ r = adapter.send(request, kwargs) │ │ 704 │ │ │ │ 705 │ │ # Total elapsed time of the request (approximately) │ │ 706 │ │ elapsed = preferred_clock() - start │ │ │ │ /home/yoker/miniconda3/envs/alg/lib/python3.10/site-packages/requests/adapte │ │ rs.py:501 in send │ │ │ │ 498 │ │ │ ) │ │ 499 │ │ │ │ 500 │ │ except (ProtocolError, OSError) as err: │ │ ❱ 501 │ │ │ raise ConnectionError(err, request=request) │ │ 502 │ │ │ │ 503 │ │ except MaxRetryError as e: │ │ 504 │ │ │ if isinstance(e.reason, ConnectTimeoutError): │ ╰──────────────────────────────────────────────────────────────────────────────╯ ConnectionError: (ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')), '(Request ID: 21a01d15-c1aa-4256-9a82-99b35f5dbb52)')

question:

Why does it always connect to the network to access huggingface when executing pix2pix? Shouldn't the required files be downloaded to the local cache the first time it is executed? Is it a necessary step if huggingface is accessed for every execution? This causes my program to report errors frequently, because my network access to huggingface is very difficult!