CodeFormer icon indicating copy to clipboard operation
CodeFormer copied to clipboard

Have you considered to have docker support?

Open hero-intelligent opened this issue 2 years ago • 5 comments
trafficstars

It would be easier to deploy if using docker, especially in Linux.

hero-intelligent avatar Jan 14 '23 06:01 hero-intelligent

I built one

Pull this image to your GPU host docker pull taenyang/code-former:latest Start and enter this container docker run -it taenyang/code-former /bin/bash Process the examples python inference_codeformer.py -w 0.5 --has_aligned --input_path inputs/cropped_faces/ Copy results to your host docker cp {container}:/app/CodeFormer/results/cropped_faces_0.5/restored_faces {host_path} Except for command 3, which is executed in the container, others are executed on the host

@WindNotStop Thanks for your working first :)
There's a WARNNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested when I ran the instructions in macOS M1. Maybe you can build the image for more platforms.

And more, there's an error after ran the 3rd command. It shows root@:/app# python: can't open file 'inference_codeformer.py': [Errno 2] No such file or directory. Changing the directory from /app to /app/CodeFormer works.

joint-song avatar Jan 15 '23 01:01 joint-song

I built one

  1. Pull this image to your GPU host docker pull taenyang/code-former:latest
  2. Start and enter this container docker run -it taenyang/code-former /bin/bash
  3. Process the examples cd CodeFormer; python inference_codeformer.py -w 0.5 --has_aligned --input_path inputs/cropped_faces/
  4. Copy results to your host docker cp {container}:/app/CodeFormer/results/cropped_faces_0.5/restored_faces {host_path}

Except for 3, which is executed in the container, others are executed on the host

@WindNotStop Thanks for your working.

Did you used Dockerfile to build or just execute commands inside a container then pack into an image? Actually, yesterday I've written a Dockerfile that works quite the same as yours.

My version of Dockerfile:

FROM pytorch/pytorch:latest

RUN apt update && apt install -y git ffmpeg libgl1 libglib2.0-dev libsm6 libxext6 && \
    git clone https://github.com/sczhou/CodeFormer.git /codeformer

WORKDIR /codeformer

RUN pip3 install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple

RUN python basicsr/setup.py develop && \
    python scripts/download_pretrained_models.py facelib && \
    python scripts/download_pretrained_models.py CodeFormer

VOLUME [ "/codeformer/inputs/", "/codeformer/results/" ]

ENTRYPOINT [ "python", "inference_codeformer.py" ]

CMD [ "-w", "0.5", "--has_aligned", "--input_path", "inputs/cropped_faces/" ]

commands in the directory ~/CodeFormer after git-ted the repository: To build a docker image:

sudo docker build -t code-former:latest . 

To run in container:

sudo docker run --rm -it --name=cf \
    -v $(pwd)/inputs:/codeformer/inputs \
    -v $(pwd)/results:/codeformer/results \
    code-former \
    -w 0.5 --has_aligned --input_path inputs/cropped_faces/

results (it works fine):

jack@jack-Virtual-Machine:~/CodeFormer$ sudo docker run --rm -it --name=cf -v $(pwd)/inputs:/codeformer/inputs -v $(pwd)/results:/codeformer/results code-former -w 0.5 --has_aligned --input_path inputs/cropped_faces/
Background upsampling: False, Face upsampling: False
[1/20] Processing: 0143.png
[2/20] Processing: 0240.png
[3/20] Processing: 0342.png
[4/20] Processing: 0345.png
[5/20] Processing: 0368.png
[6/20] Processing: 0412.png
[7/20] Processing: 0444.png
[8/20] Processing: 0478.png
[9/20] Processing: 0500.png
[10/20] Processing: 0599.png
[11/20] Processing: 0717.png
[12/20] Processing: 0720.png
[13/20] Processing: 0729.png
[14/20] Processing: 0763.png
[15/20] Processing: 0770.png
[16/20] Processing: 0777.png
[17/20] Processing: 0885.png
[18/20] Processing: 0934.png
[19/20] Processing: Solvay_conference_1927_0018.png
[20/20] Processing: Solvay_conference_1927_2_16.png

All results are saved in results/cropped_faces_0.5
jack@jack-Virtual-Machine:~/CodeFormer/results/cropped_faces_0.5/restored_faces$ ls
0143.png  0368.png  0500.png  0729.png  0885.png
0240.png  0412.png  0599.png  0763.png  0934.png
0342.png  0444.png  0717.png  0770.png  Solvay_conference_1927_0018.png
0345.png  0478.png  0720.png  0777.png  Solvay_conference_1927_2_16.png
jack@jack-Virtual-Machine:~/CodeFormer/results/cropped_faces_0.5/restored_faces$       

But my concern is that it is so inconvenient in this way because there is no GUI support, and I have to execute command everytime I want to use this program. Besides, there is GUI support in this program, which lies in ./web-demo, and I tried launching hugging_face, but there is package conflict so that the program refuses to work. So in my openion, our work is still half-finished.

As you see, I didn't use anaconda, because in my opinion docker itself is a self-sustained environment so that an isolated environment at python level is no longer needed, and I have no idea how to use anaconda in docker, especially in writing Dockerfile. But I was wrong, now i think. We have to turn to anaconda to solve the package conflict problem.

hero-intelligent avatar Jan 15 '23 09:01 hero-intelligent

My new version of Dockerfile with web-UI support. Refer to #143 for detailed information.

FROM pytorch/pytorch:latest

RUN apt update && apt install -y git ffmpeg libgl1 libglib2.0-dev libsm6 libxext6 && \
    git clone https://huggingface.co/spaces/sczhou/CodeFormer /cf

WORKDIR /cf

RUN pip3 install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple

RUN pip install gradio && python -m pip install markupsafe==2.0.1

RUN apt install -y wget

WORKDIR /cf/CodeFormer/weights/CodeFormer
RUN wget https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth 
WORKDIR /cf/CodeFormer/weights/facelib
RUN wget https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/detection_Resnet50_Final.pth
RUN wget https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth
WORKDIR /cf/CodeFormer/weights/realesrgan
RUN wget https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/RealESRGAN_x2plus.pth

WORKDIR /cf

RUN sed -i '$c demo.launch(server_name="0.0.0.0")' app.py

EXPOSE 7860

CMD [ "python", "app.py" ]

hero-intelligent avatar Feb 15 '23 02:02 hero-intelligent