Both GPFGAN and CodeFormer throw PermissionError: [Errno 13]

Right now this is the problem I’ve been banging my head against all day. Every time I try to use GPFGAN and CodeFormer, I get the following errors that I do not understand. I suppose I will discontinue my attempts and wait to see if anyone knows more, because I’m stuck. If I’m still stuck tomorrow, I will probably rip everything out and start over.

I do have some experience at the Linux command line but I’ll be honest – I used to like diving into the guts of the OS, but not in the last decade or so. As a consequence, I find solving problems that manifest in a “Linuxy way” (as opposed to a “Windows way”) to be an order of magnitude more difficult than you all seem to think it is. Please bear that in mind.

I’m running Windows 11. System is an i5-8500 (6 cores like an i7-8700 but no Hyperthreading), 16 GB of RAM, and an RTX 3060 (12 GB VRAM).

I have to admit I absolutely hate dependency chain hell and I’m about to just abandon local Stable Diffusion altogether because I just can’t get it to work right. Something seems to be broken at every turn, and I spend hours searching for similar problems only to not find any or to see them “closed as stale” without resolution (my particular pet peeve!). This is just way too fiddly and fragile, it seems like one continuous game of whack-a-mole.

*** Error completing request
*** Arguments: (‘task(z8a3uvu6wxtboqx)’, 0.0, <PIL.Image.Image image mode=RGBA size=512x512 at 0x2BFB69F0A00>, None, ‘’, ‘’, True, False, 0.0, 4, 0.0, 512, 512, True, ‘None’, ‘None’, 0, True, 1, False, 1, 0, False, 0.5, 0.2, False, 0.9, 0.15, 0.5, False, False, 384, 768, 4096, 409600, ‘Maximize area’, 0.1, False, [‘Horizontal’], False, [‘Deepbooru’]) {}
Traceback (most recent call last):
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 57, in f
res = list(func(*args, **kwargs))
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 36, in f
res = func(*args, **kwargs)
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 131, in run_postprocessing_webui
return run_postprocessing(*args, **kwargs)
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 71, in run_postprocessing, args)
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 198, in run
script.process(single_image, **process_args)
File “C:\Other Programs\Stable Diffusion\webui\scripts\”, line 25, in process
restored_img = gfpgan_model.gfpgan_fix_faces(np.array(pp.image.convert(“RGB”), dtype=np.uint8))
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 58, in gfpgan_fix_faces
return gfpgan_face_restorer.restore(np_image)
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 53, in restore
return self.restore_with_helper(np_image, restore_face)
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 156, in restore_with_helper
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 132, in send_model_to
if self.face_helper:
File “C:\Users\ADMIND\AppData\Local\Programs\Python\Python310\lib\”, line 981, in get
val = self.func(instance)
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 126, in face_helper
return create_face_helper(self.get_device())
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 47, in create_face_helper
return FaceRestoreHelper(
File “C:\Other Programs\Stable Diffusion\webui\venv\lib\site-packages\facexlib\utils\”, line 99, in init
self.face_det = init_detection_model(det_model, half=False, device=self.device, model_rootpath=model_rootpath)
File “C:\Other Programs\Stable Diffusion\webui\venv\lib\site-packages\facexlib\”, line 18, in init_detection_model
model_path = load_file_from_url(
File “C:\Other Programs\Stable Diffusion\webui\modules\”, line 174, in facex_load_file_from_url
return det_facex_load_file_from_url(**update_kwargs(kwargs))
File “C:\Other Programs\Stable Diffusion\webui\venv\lib\site-packages\facexlib\utils\”, line 77, in load_file_from_url
download_url_to_file(url, cached_file, hash_prefix=None, progress=progress)
File “C:\Other Programs\Stable Diffusion\webui\venv\lib\site-packages\torch\”, line 638, in download_url_to_file
f = open(tmp_dst, ‘w+b’)
PermissionError: [Errno 13] Permission denied: ‘C:\Other Programs\Stable Diffusion\webui\models\GFPGAN\detection_Resnet50_Final.pth.9342ed0cbe7547f78c282d6a51909d50.partial’

Here’s the advice I got from Llama 3 Instruct. I still don’t understand it well enough to know if it will fix anything, or even how to do some of it, but is it at least on the right track?

Llama 3 Instruct: It looks like the issue is related to permission denied errors when trying to download files from URLs using torch.hub.download_url_to_file. This suggests that there might be an issue with file permissions or access rights.

Here are some potential causes and suggestions:

  1. File system permissions: Make sure you have write permissions for the directory where Stable Diffusion is installed (e.g., C:\Other Programs\Stable Diffusion). You can try running your script as administrator to see if that resolves the issue.
  2. Temporary file creation: The error message mentions a temporary file (tmp_ dst) being created during the download process. This might be related to permissions issues with creating files in certain directories.
  3. Model loading: It seems like there’s an issue with loading models (e.g., detection_Resnet50_Final.pth), which is causing the permission denied error.

To troubleshoot this further, you can try:

  1. Check your file system permissions and ensure that you have write access to the relevant directories.
  2. Try running your script in a different directory or with elevated privileges (e.g., as administrator).
  3. Investigate why model loading is failing by checking if there are any issues with the models themselves, such as corrupted files or incorrect paths.

If none of these suggestions help, please provide more context about your environment and setup, including:

  • Your operating system
  • Python version
  • Stable Diffusion installation method (e.g., pip, conda)
  • Any relevant configuration files or settings

I’ll do my best to assist you in resolving this issue!

Prompt: that .partial file doeesn’t ever seem to exist when I go to look.
Response: The .partial file not existing could be a clue!

In that case, it’s possible that the error is related to the model loading process rather than permissions issues.

Here are some potential causes and suggestions:

  1. Model corruption: The detection_Resnet50_Final.pth model might be corrupted or incomplete, which would prevent it from being loaded correctly.
  2. Incorrect model path: Double-check if the model file exists at the expected location (C:\Other Programs\Stable Diffusion\webui\models\GFPGAN). If not, ensure that you have downloaded the correct model and placed it in the right directory.

To troubleshoot this further:

  1. Check the integrity of the detection_Resnet50_Final.pth file by downloading it again or verifying its contents.
  2. Verify if there are any typos or incorrect paths when loading the model. Make sure you’re using the correct path and filename.
  3. If you’ve modified your code to load models from a different location, ensure that the new path is correct.

If none of these suggestions help, please provide more context about how you installed Stable Diffusion and any relevant configuration files or settings.

This seems to have been corrected by using Stability Matrix to handle all packages and the like, instead of the haphazard manual method.