How to quickly run GFPGAN locally (with Docker) #190

Open
opened 2026-01-29 21:45:29 +00:00 by claunia · 8 comments
Owner

Originally created by @soulteary on GitHub (May 20, 2022).

Thanks to the project sponsors, GFPGAN is a very interesting and practical project.

I've seen quite a few users of the project have problems, these questions include:

  • how to run this project locally,
  • how to run the project in a container,
  • how to resolve project dependencies,
  • how to run the model without the GPU,
  • how to run the project on the M1 device run etc.

So, I created a project called docker-gfpgan https://github.com/soulteary/docker-gfpgan

Anyone can use this method to quickly run GFPGAN, and I also provide pre-built images.

With just one simple command, we can call the program in docker to drive the model and process the images we want to process.

docker run --rm -it -v `pwd`/model/GFPGANCleanv1-NoCE-C2.pth:/GFPGAN.pth -v `pwd`/data:/data soulteary/docker-gfpgan

The result of the operation will appear in the data directory:

preview


For the details of the production of this tool, if anyone is interested, you can read the following article:

enjoy!

Originally created by @soulteary on GitHub (May 20, 2022). Thanks to the project sponsors, GFPGAN is a very interesting and practical project. I've seen quite a few users of the project have problems, these questions include: - how to run this project locally, - how to run the project in a container, - how to resolve project dependencies, - how to run the model without the GPU, - how to run the project on the M1 device run etc. So, I created a project called `docker-gfpgan` https://github.com/soulteary/docker-gfpgan Anyone can use this method to quickly run GFPGAN, and I also provide pre-built images. With just one simple command, we can call the program in docker to drive the model and process the images we want to process. ```bash docker run --rm -it -v `pwd`/model/GFPGANCleanv1-NoCE-C2.pth:/GFPGAN.pth -v `pwd`/data:/data soulteary/docker-gfpgan ``` The result of the operation will appear in the `data` directory: ![preview](https://user-images.githubusercontent.com/1500781/169509049-f9c15e84-d012-41ea-8b1d-d1a8f17df91d.jpg) ------ For the details of the production of this tool, if anyone is interested, you can read the following article: - https://www.zhihu.com/question/36346612/answer/2494105354 - https://zhuanlan.zhihu.com/p/517512279 enjoy!
Author
Owner

@andreafalzetti commented on GitHub (May 21, 2022):

Does it support the 3 versions?

@andreafalzetti commented on GitHub (May 21, 2022): Does it support the 3 versions?
Author
Owner

@soulteary commented on GitHub (May 21, 2022):

I have tested the newer two versions (without gpu), and if you have time, you can help supplement the model originally provided by the paper. thanks @andreafalzetti

Don't forget to modify the parameters in the docker entrypoint (app.py), the first model has parameters that are not the same as the subsequent models

@soulteary commented on GitHub (May 21, 2022): I have tested the newer two versions (without gpu), and if you have time, you can help supplement the model originally provided by the paper. thanks @andreafalzetti Don't forget to modify the parameters in the docker entrypoint (app.py), the first model has parameters that are not the same as the subsequent models
Author
Owner

@andreafalzetti commented on GitHub (May 21, 2022):

I have tested the newer two versions (without gpu), and if you have time, you can help supplement the model originally provided by the paper. thanks @andreafalzetti

Don't forget to modify the parameters in the docker entrypoint (app.py), the first model has parameters that are not the same as the subsequent models

I've tried multiple times and never managed to make v1 work, that's why I was asking

@andreafalzetti commented on GitHub (May 21, 2022): > I have tested the newer two versions (without gpu), and if you have time, you can help supplement the model originally provided by the paper. thanks @andreafalzetti > > > > Don't forget to modify the parameters in the docker entrypoint (app.py), the first model has parameters that are not the same as the subsequent models I've tried multiple times and never managed to make v1 work, that's why I was asking
Author
Owner

@soulteary commented on GitHub (May 21, 2022):

I have tested the newer two versions (without gpu), and if you have time, you can help supplement the model originally provided by the paper. thanks @andreafalzetti
Don't forget to modify the parameters in the docker entrypoint (app.py), the first model has parameters that are not the same as the subsequent models

I've tried multiple times and never managed to make v1 work, that's why I was asking

Maybe you can try this:

git checkout the code of this project when v1 is released, keep various parameters in the python program original, use it to directly make the entrypoint of the container, and try the v1 model in the Tencent Cloud 腾讯微云 (readme.md).

@soulteary commented on GitHub (May 21, 2022): > > I have tested the newer two versions (without gpu), and if you have time, you can help supplement the model originally provided by the paper. thanks @andreafalzetti > > Don't forget to modify the parameters in the docker entrypoint (app.py), the first model has parameters that are not the same as the subsequent models > > I've tried multiple times and never managed to make v1 work, that's why I was asking Maybe you can try this: git checkout the code of this project when v1 is released, keep various parameters in the python program original, use it to directly make the entrypoint of the container, and try the v1 model in the Tencent Cloud 腾讯微云 (readme.md).
Author
Owner

@thelamedia commented on GitHub (Aug 10, 2022):

I'm getting this error when trying to mount in Docker
Traceback (most recent call last): File "/entrypoint.py", line 22, in <module> towhee.glob['path']('*.jpg') File "/opt/conda/lib/python3.9/site-packages/towhee/hparam/hyperparameter.py", line 198, in __call__ return self._func(*args, **kws) File "/opt/conda/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 652, in wrapper return self.map(op) File "/opt/conda/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 343, in map if hasattr(unary_op, 'is_stateful') and unary_op.is_stateful: File "/opt/conda/lib/python3.9/site-packages/towhee/engine/factory.py", line 121, in is_stateful self.__check_init__() File "/opt/conda/lib/python3.9/site-packages/towhee/engine/factory.py", line 71, in __check_init__ self._op = op(self._name, self._tag, **self._kws) File "/opt/conda/lib/python3.9/site-packages/towhee/engine/factory.py", line 50, in op op_obj = loader.load_operator(operator_src, kwargs, tag) File "/opt/conda/lib/python3.9/site-packages/towhee/engine/operator_loader.py", line 150, in load_operator op = factory(function, args, tag) File "/opt/conda/lib/python3.9/site-packages/towhee/engine/operator_loader.py", line 60, in load_operator_from_registry return self.instance_operator(op, args) if op is not None else None File "/opt/conda/lib/python3.9/site-packages/towhee/engine/operator_loader.py", line 160, in instance_operator return op(**args) if args is not None else op() File "/entrypoint.py", line 13, in __init__ self._restorer = GFPGANer(model_path, upscale, arch, channel_multiplier, bg_upsampler) File "/opt/conda/lib/python3.9/site-packages/gfpgan/utils.py", line 87, in __init__ loadnet = torch.load(model_path) File "/opt/conda/lib/python3.9/site-packages/torch/serialization.py", line 594, in load with _open_file_like(f, 'rb') as opened_file: File "/opt/conda/lib/python3.9/site-packages/torch/serialization.py", line 230, in _open_file_like return _open_file(name_or_buffer, mode) File "/opt/conda/lib/python3.9/site-packages/torch/serialization.py", line 211, in __init__ super(_open_file, self).__init__(open(name, mode)) IsADirectoryError: [Errno 21] Is a directory: '/GFPGAN.pth'

@thelamedia commented on GitHub (Aug 10, 2022): I'm getting this error when trying to mount in Docker `Traceback (most recent call last): File "/entrypoint.py", line 22, in <module> towhee.glob['path']('*.jpg') File "/opt/conda/lib/python3.9/site-packages/towhee/hparam/hyperparameter.py", line 198, in __call__ return self._func(*args, **kws) File "/opt/conda/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 652, in wrapper return self.map(op) File "/opt/conda/lib/python3.9/site-packages/towhee/functional/data_collection.py", line 343, in map if hasattr(unary_op, 'is_stateful') and unary_op.is_stateful: File "/opt/conda/lib/python3.9/site-packages/towhee/engine/factory.py", line 121, in is_stateful self.__check_init__() File "/opt/conda/lib/python3.9/site-packages/towhee/engine/factory.py", line 71, in __check_init__ self._op = op(self._name, self._tag, **self._kws) File "/opt/conda/lib/python3.9/site-packages/towhee/engine/factory.py", line 50, in op op_obj = loader.load_operator(operator_src, kwargs, tag) File "/opt/conda/lib/python3.9/site-packages/towhee/engine/operator_loader.py", line 150, in load_operator op = factory(function, args, tag) File "/opt/conda/lib/python3.9/site-packages/towhee/engine/operator_loader.py", line 60, in load_operator_from_registry return self.instance_operator(op, args) if op is not None else None File "/opt/conda/lib/python3.9/site-packages/towhee/engine/operator_loader.py", line 160, in instance_operator return op(**args) if args is not None else op() File "/entrypoint.py", line 13, in __init__ self._restorer = GFPGANer(model_path, upscale, arch, channel_multiplier, bg_upsampler) File "/opt/conda/lib/python3.9/site-packages/gfpgan/utils.py", line 87, in __init__ loadnet = torch.load(model_path) File "/opt/conda/lib/python3.9/site-packages/torch/serialization.py", line 594, in load with _open_file_like(f, 'rb') as opened_file: File "/opt/conda/lib/python3.9/site-packages/torch/serialization.py", line 230, in _open_file_like return _open_file(name_or_buffer, mode) File "/opt/conda/lib/python3.9/site-packages/torch/serialization.py", line 211, in __init__ super(_open_file, self).__init__(open(name, mode)) IsADirectoryError: [Errno 21] Is a directory: '/GFPGAN.pth' `
Author
Owner

@soulteary commented on GitHub (Aug 12, 2022):

“[Errno 21] Is a directory: '/GFPGAN.pth'”, based on this error, there should be a problem with the mapping of the model file. @thelamedia

@soulteary commented on GitHub (Aug 12, 2022): “[Errno 21] Is a directory: '/GFPGAN.pth'”, based on this error, there should be a problem with the mapping of the model file. @thelamedia
Author
Owner

@thelamedia commented on GitHub (Aug 12, 2022):

@soulteary I'm not sure what I'm doing wrong. I am following your instructions exactly and this errors out immediately when trying to run the docker container. Any input would be helpful.

@thelamedia commented on GitHub (Aug 12, 2022): @soulteary I'm not sure what I'm doing wrong. I am following your instructions exactly and this errors out immediately when trying to run the docker container. Any input would be helpful.
Author
Owner

@soulteary commented on GitHub (Aug 13, 2022):

You can check if the following steps are executed. @thelamedia

  1. mkdir a directory which named model
  2. download project pre-trained model, put it to model directory.
  3. run command.
docker run --rm -it -v `pwd`/model/GFPGANCleanv1-NoCE-C2.pth:/GFPGAN.pth -v `pwd`/data:/data soulteary/docker-gfpgan
@soulteary commented on GitHub (Aug 13, 2022): You can check if the following steps are executed. @thelamedia 1. `mkdir` a directory which named `model` 2. download project pre-trained model, put it to `model` directory. 3. run command. ```bash docker run --rm -it -v `pwd`/model/GFPGANCleanv1-NoCE-C2.pth:/GFPGAN.pth -v `pwd`/data:/data soulteary/docker-gfpgan ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#190