From 4dab6c7bdb7b831e812cb205cfc7c69fcf802b86 Mon Sep 17 00:00:00 2001 From: yaohwang Date: Tue, 24 Oct 2023 17:51:34 +0800 Subject: [PATCH] init --- .gitignore | 6 +++ Dockerfile | 108 +++++++++++++++++++++++++++++++++++++++++++ multi-style/run.py | 33 ++++++++++--- source/cartoonize.py | 6 ++- 4 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f21b6fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__pycache__ +.cache +damo +tmp +test_toonify_compare1 +output diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1616127 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,108 @@ +FROM nvidia/cuda:11.2.0-cudnn8-devel-ubuntu18.04 + +ENV DEBIAN_FRONTEND=noninteractive + +RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list +RUN sed -i "s@http://\(deb\|security\).debian.org@https://mirrors.aliyun.com@g" /etc/apt/sources.list +RUN sed -i s/cn.archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list +RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list +RUN apt-get clean +#RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC +RUN apt-get update -y + +# opencv + +RUN apt-get install -y libglib2.0-0 +RUN apt-get install libsm6 -y +RUN apt-get install libxrender1 -y +RUN apt install libxext6 -y +RUN apt-get install libgl1-mesa-glx -y + +# python 3.7 + +RUN apt-get install -y --no-install-recommends \ + git \ + wget \ + g++ \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +ENV PATH="/root/miniconda3/bin:${PATH}" +ARG PATH="/root/miniconda3/bin:${PATH}" + +RUN rm -rf /opt/conda +RUN rm -rf /root/.conda + +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + && mkdir /root/.conda \ + && bash Miniconda3-latest-Linux-x86_64.sh -b \ + && rm -f Miniconda3-latest-Linux-x86_64.sh \ + && echo "Running $(conda --version)" && \ + conda init bash && \ + . /root/.bashrc && \ + conda update conda && \ + conda create -n python-app python=3.7 && \ + conda activate python-app && \ + echo 'print("Hello World!")' > python-app.py + +RUN echo 'conda activate python-app \n\ +alias python-app="python python-app.py"' >> /root/.bashrc + +SHELL ["conda", "run", "-n", "python-app", "/bin/bash", "-c"] + +# pip basic + +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple --upgrade pip +RUN conda install -c conda-forge mamba +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple -U openmim + +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple ipython +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple matplotlib +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple tqdm +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple wget +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple click +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple easydict +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple future +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple requests +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple tqdm +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple ninja +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple psutil + +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple scipy +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple numpy +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pandas +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple scikit-learn + +# pip image +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pyspng +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple Pillow==9.2.0 +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple scikit-image==0.17.2 +#RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple opencv-python==4.1.1.26 +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple opencv-python==4.5.5.64 +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple imageio-ffmpeg==0.4.3 + +# torch + +#RUN pip3 install -i https://mirrors.ustc.edu.cn/pypi/web/simple torch==1.7.1 torchvision torchaudio +#RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple timm + +# tensorflow +#RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple keras-applications>=1.0.6 +#RUN pip install keras-applications>=1.0.6 +#RUN pip install keras-applications>=1.0.8 +#RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple keras-applications>=1.0.8 +RUN pip install -i https://mirrors.aliyun.com/pypi/simple keras-applications>=1.0.8 +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple tensorflow==1.15 +#RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple tensorboard==2.6.0 +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple tensorboardX==2.5.1 + +# mmcv +#RUN mim install mmcv-full -i https://pypi.tuna.tsinghua.edu.cn/simple + +# pip other +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple easydict +RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple --upgrade "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html +#RUN pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple opencv-python==4.5.5.64 + + +ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "python-app"] diff --git a/multi-style/run.py b/multi-style/run.py index 3a42889..3526893 100644 --- a/multi-style/run.py +++ b/multi-style/run.py @@ -7,6 +7,21 @@ import os import argparse + +from pathlib import Path +from itertools import chain +from glob import glob + + +def get_path_images(path_in: Path): + allowed = ['*.png', '*.jpg', '*.jpeg', '*.jfif', '*.gif', '*.webp'] + path_in_images = list(chain.from_iterable([ + glob(str(path_in/'**'/t), recursive=True) + for t in allowed + ])) + return path_in_images + + def process(args): style = args.style @@ -29,21 +44,25 @@ def process(args): print('no such style %s' % style) return 0 - img = cv2.imread('input.png')[..., ::-1] - result = algo.cartoonize(img) - cv2.imwrite('result1_%s.png'%style, result) + args.path_out.mkdir(parents=True, exist_ok=True) - print('finished!') + for path_image in get_path_images(args.path_in): + # img = cv2.imread('input.png')[..., ::-1] + img = cv2.imread(path_image)[..., ::-1] + result = algo.cartoonize(img) + # cv2.imwrite('result1_%s.png'%style, result) + path_image = Path(path_image) + cv2.imwrite(str(args.path_out/f'{path_image.stem}_{style}{path_image.suffix}'), result) + print('finished!') if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--style', type=str, default='anime') + parser.add_argument('--path-in', type=Path) + parser.add_argument('--path-out', type=Path) args = parser.parse_args() process(args) - - - diff --git a/source/cartoonize.py b/source/cartoonize.py index 9c9a42b..cff23e8 100644 --- a/source/cartoonize.py +++ b/source/cartoonize.py @@ -16,9 +16,11 @@ class Cartoonizer(): self.facer = FaceAna(dataroot) self.sess_head = self.load_sess( - os.path.join(dataroot, 'cartoon_anime_h.pb'), 'model_head') + # os.path.join(dataroot, 'cartoon_anime_h.pb'), 'model_head') + os.path.join(dataroot, 'cartoon_h.pb'), 'model_head') self.sess_bg = self.load_sess( - os.path.join(dataroot, 'cartoon_anime_bg.pb'), 'model_bg') + # os.path.join(dataroot, 'cartoon_anime_bg.pb'), 'model_bg') + os.path.join(dataroot, 'cartoon_bg.pb'), 'model_bg') self.box_width = 288 global_mask = cv2.imread(os.path.join(dataroot, 'alpha.jpg'))