TencentARC / GFPGAN

GFPGAN aims at developing Practical Algorithms for Real-world Face Restoration.
Other
35.86k stars 5.94k forks source link

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

Open soulteary opened 2 years ago

soulteary commented 2 years ago

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:

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!

andreafalzetti commented 2 years ago

Does it support the 3 versions?

soulteary commented 2 years ago

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

andreafalzetti commented 2 years ago

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

soulteary commented 2 years ago

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

thelamedia commented 2 years ago

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'

soulteary commented 2 years ago

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

thelamedia commented 2 years ago

@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.

soulteary commented 2 years ago

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