Giter VIP home page Giter VIP logo

anime-inpainting's Introduction

Anime-InPainting: An application Tool based on Edge-Connect

Version Status Platform PyTorch License

English | 中文版介绍


Important

2019.3.27 Update:
Our latest drawing method PI-REC is more powerful.
Take a look on it, and I'm sure it won't disappoint you.


Tool show time 🏳️‍🌈

Outputs

Tool operation

Introduction:

This is an optimized application tool which has a frontend based on Opencv, whose backend used Edge-Connect. Make sure you have read their awesome work and license thoroughly. Compared with the original work, this project has such improvements :

  • Add tool application modes
  • Optimize the training phase
    • Auto-save and auto-load latest weights files
    • Add a fast training phase combined with origin phase 2 and 3
  • bugs fixed (most of them are merged into the original work)
  • Add utility files
  • Add configs in config.yml
    • PRINT_FREQUENCY
    • DEVICE : cpu or gpu
  • ... ...

You can do the amazing Anime inpainting conveniently here.

And detailed training manual is released. You may train your own dataset smoothly now.

Prerequisites

  • Python 3
  • PyTorch 1.0 (0.4 is not supported)
  • NVIDIA GPU + CUDA cuDNN

Installation

  • Clone this repo
  • Install PyTorch and dependencies from http://pytorch.org
  • Install python requirements:
pip install -r requirements.txt

Run the Tool

I want to run the tool! Calm down and follow such step:

Info: The following weights files are trained on anime face dataset which performs not good on a large whole anime character.

  1. Download the well trained model weights file --> Google Drive | Baidu
  2. Unzip the .7z and put it under your root directory. So make sure your path now is: ./model/getchu/<xxxxx.pth>
  3. Complete the above Prerequisites and Installation
  4. (Optional) Check and edit the ./model/getchu/config.yml config file as you wish
  5. Run the cooool tool:

Default Tool:

python tool_patch.py --path model/getchu/

Tool with edge window:

python tool_patch.py --edge --path model/getchu/

Args help

python tool_patch.py -h

PS. You can run any well trained model, not only above one. You can download more model weights files from the original work Edge-Connect. Then you can run the Tool as above. Only one thing to be careful: The config.yml in this project has some additional options than the config from the Edge-Connect.

Tool operation

For detailed manual, refer to your terminal prints or the __doc__ in tool_patch.py.

Below is the simplified tool operation manual:

Key description
Mouse Left To draw out the defective area in window input and to draw the edge in window edge
Mouse Right To erase edge in window edge
Key [ To make the brush thickness smaller
Key ] To make the brush thickness larger
Key 0 Todo
Key 1 Todo
Key n To patch the black part of image, just use input image
Key e To patch the black part of image, use the input image and edit edge (only work under edge window opened)
Key r To reset the setup
Key s To save the output
Key q To quit

Training manual

Click here --> Training manual by yourself

中文版介绍🇨🇳


重要

2019.3.27 更新:
我们的最新模型 PI-REC 更强大.
如果你想用最新的AI绘画黑科技,而非仅仅是修补图像,请点击上面的链接👆


简介

Tool效果看上面👆 | Bilibili视频教程:TO DO

这是图像修补方向最新研究成果Edge-Connect阿姆斯特朗氮气加速魔改(优化)版。 用Opencv写了个前端部分,后端是Edge-Connect,方便当作工具使用。 此工具可以用来自动图像修补,去马赛克……同样优化了模型训练的过程。具体优化内容请看英文版Improvements

更新:训练手册已经填坑完发布了!你可以照着指南训练自己数据集了~

基础环境

  • Python 3
  • PyTorch 1.0 (0.4 会报错)
  • NVIDIA GPU + CUDA cuDNN (当前版本已可选cpu,请修改config.yml中的DEVICE

第三方库安装

  • Clone this repo
  • 安装PyTorch和torchvision --> http://pytorch.org
  • 安装 python requirements:
pip install -r requirements.txt

运行Tool

教练!我有个大胆的想法🈲……别急,一步步来:

注意:以下模型是在动漫头像数据集上训练的,所以对动漫全身大图修补效果一般,想自己再训练的参考下面的训练指南

  1. 下训练好的模型文件 --> Google Drive | Baidu
  2. 解压 .7z 放到你的根目录下. 确保你的目录现在是这样: ./model/getchu/<xxxxx.pth>
  3. 完成上面的基础环境和第三方库安装步骤
  4. (可选) 检查并编辑 ./model/getchu/config.yml 配置文件
  5. 使用以下命令运行:

默认Tool:

python tool_patch.py --path model/getchu/

带Edge编辑窗口的Tool:

python tool_patch.py --edge --path model/getchu/

命令行参数帮助

python tool_patch.py -h

PS. 你也能用tool跑别的任何模型,在这里下载原作更多模型Edge-Connect. 文件组织方式参考上面,其余运行命令都一样。唯一注意的是这个项目的 config.yml 比原作的多了几个选项,报错了的话注意修改。

Tool操作指南

详细内容请翻看控制台的打印内容,或查看tool_patch.py里的__doc__
简略版tool使用指南:

按键 说明
鼠标左键 Input窗口:画出瑕疵区域的遮盖,Edge窗口:手动画边缘
鼠标右键 Edge窗口:橡皮擦
按键 [ 笔刷变细 (控制台打印粗细大小)
按键 ] 笔刷变粗
按键 0 Todo
按键 1 Todo
按键 n 修补黑色涂抹区域,只使用一张输入图片
按键 e 修补黑色涂抹区域,使用输入图片和边缘图片(仅当edge窗口启动时有效)
按键 r 全部重置
按键 s 保存输出图片
按键 q 退出

训练指南

训练指南 --> 阅读

License

Licensed under a Creative Commons Attribution-NonCommercial 4.0 International.

Except where otherwise noted, this content is published under a CC BY-NC license, which means that you can copy, remix, transform and build upon the content as long as you do not use the material for commercial purposes and give appropriate credit and provide a link to the license.

Citation

If you use this code for your research, please cite our paper EdgeConnect: Generative Image Inpainting with Adversarial Edge Learning:

@inproceedings{nazeri2019edgeconnect,
  title={EdgeConnect: Generative Image Inpainting with Adversarial Edge Learning},
  author={Nazeri, Kamyar and Ng, Eric and Joseph, Tony and Qureshi, Faisal and Ebrahimi, Mehran},
  journal={arXiv preprint},
  year={2019},
}

anime-inpainting's People

Contributors

youyuge34 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anime-inpainting's Issues

读取图片的时候报错 ValueError: empty range for randrange() (0,0, 0)

我的图片和掩码都是1.2w,报错场景是这样的,有想过是图片的问题,但没能解决,求助一下博主,谢谢了
start training...

Training epoch: 1
loading error: ./celeb/008621.png
loading error: ./celeb/010481.png
loading error: ./celeb/003145.png
loading error: ./celeb/004050.png
loading error: ./celeb/011577.png
Traceback (most recent call last):
File "train.py", line 4, in
main(mode=1)
File "/mnt/Anime-InPainting/main.py", line 55, in main
model.train()
File "/mnt/Anime-InPainting/src/edge_connect.py", line 101, in train
for items in train_loader:
File "/root/miniconda3/envs/myconda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/root/miniconda3/envs/myconda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 658, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
ValueError: Traceback (most recent call last):
File "/mnt/Anime-InPainting/src/dataset.py", line 41, in getitem
item = self.load_item(index)
File "/mnt/Anime-InPainting/src/dataset.py", line 67, in load_item
mask = self.load_mask(img, index)
File "/mnt/Anime-InPainting/src/dataset.py", line 135, in load_mask
mask_index = random.randint(0, len(self.mask_data) - 1)
File "/root/miniconda3/envs/myconda/lib/python3.6/random.py", line 221, in randint
return self.randrange(a, b+1)
File "/root/miniconda3/envs/myconda/lib/python3.6/random.py", line 199, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/root/miniconda3/envs/myconda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/root/miniconda3/envs/myconda/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "/mnt/Anime-InPainting/src/dataset.py", line 44, in getitem
item = self.load_item(0)
File "/mnt/Anime-InPainting/src/dataset.py", line 67, in load_item
mask = self.load_mask(img, index)
File "/mnt/Anime-InPainting/src/dataset.py", line 135, in load_mask
mask_index = random.randint(0, len(self.mask_data) - 1)
File "/root/miniconda3/envs/myconda/lib/python3.6/random.py", line 221, in randint
return self.randrange(a, b+1)
File "/root/miniconda3/envs/myconda/lib/python3.6/random.py", line 199, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)

Testing damaged image

Thanks for your code! There is a problem that when i test the model with damaged images, i can't get the generated edge information through the edge generator. Same things as this, i can't get a inpainted image through the image inpainting network. But when i input a no damaged image and mask image, the picture can be inpainted. If i want to input a damaged image directly to test the network, what should i do?

如何去掉黑色mask留下的阴影

image
首先感谢你们提供了训练好的模型,但是在output里,绘制的黑色mask会有很明显的阴影,这应该如何去掉,谢谢

i use the pre-trained net to run the tool .but these mistakes happened

RuntimeError: Error(s) in loading state_dict for EdgeGenerator:
Missing key(s) in state_dict: "encoder.1.weight", "encoder.4.weight", "encoder.7.weight", "middle.0.conv_block.1.weigh
t", "middle.0.conv_block.5.weight", "middle.1.conv_block.1.weight", "middle.1.conv_block.5.weight", "middle.2.conv_block.1.wei
ght", "middle.2.conv_block.5.weight", "middle.3.conv_block.1.weight", "middle.3.conv_block.5.weight", "middle.4.conv_block.1.w
eight", "middle.4.conv_block.5.weight", "middle.5.conv_block.1.weight", "middle.5.conv_block.5.weight", "middle.6.conv_block.1
.weight", "middle.6.conv_block.5.weight", "middle.7.conv_block.1.weight", "middle.7.conv_block.5.weight", "decoder.0.weight",
"decoder.3.weight".
Unexpected key(s) in state_dict: "encoder.1.weight_v", "encoder.4.weight_v", "encoder.7.weight_v", "middle.0.conv_bloc
k.1.weight_v", "middle.0.conv_block.5.weight_v", "middle.1.conv_block.1.weight_v", "middle.1.conv_block.5.weight_v", "middle.2
.conv_block.1.weight_v", "middle.2.conv_block.5.weight_v", "middle.3.conv_block.1.weight_v", "middle.3.conv_block.5.weight_v",
"middle.4.conv_block.1.weight_v", "middle.4.conv_block.5.weight_v", "middle.5.conv_block.1.weight_v", "middle.5.conv_block.5.
weight_v", "middle.6.conv_block.1.weight_v", "middle.6.conv_block.5.weight_v", "middle.7.conv_block.1.weight_v", "middle.7.con
v_block.5.weight_v", "decoder.0.weight_v", "decoder.3.weight_v".

可以训练PASCAL数据集吗?

您好!
可以用PASCAL voc 2012 数据集吗?我主要想做目标移除的修复。(比如将图片中的人移除,然后背景修复)
谢谢!

如何在预训练模型的基础上实现迁移学习?

之前使用自己的数据集训练EdgeConnect模型,同样注意到了过久的训练时长。读源代码时只看到在loss.py中冻结了VGG19的部分参数,没有找到迁移学习有关的冻结网络层、调用预训练模型中参数等代码。
请问大佬具体是怎样实现的迁移学习?在项目代码中有写吗?感恩感恩~

Slow convergence

Slow convergence when training the network.I tarin the model using remote sensing images(segmented ;num:160000)on single GTX1080TI . it have been worked more than one week for edge model,but the precision could not be over 0.5.
Is wrong with my dataset?or other problem?

关于数据格式问题

我在用paris数据集进行model 1 的训练时出现了一些错误 我的数据集尺寸为256256 mask数据集也为256256,下面是我的错误截图,请问您项目中的初始数据集尺寸与mask尺寸为多少呢?

@HZEU3KZI _L7`WRF0(2%E7

启动程序提示的错误

请问这个问题是怎样产生的?怎样解决?

python tool_patch.py --edge --path model/getchu/
Traceback (most recent call last): File "tool_patch.py", line 53, in <module> from main import main File "E:\Git\Anime-InPainting-master\main.py", line 5, in <module> import torch File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\__init__.py", line 84, in <module> from torch._C import * ImportError: DLL load failed: 找不到指定的模块。

pip安装的whl文件:torch-1.0.0-cp37-cp37m-win_amd64.whl

运行就报这个错误

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [1, 512, 4, 4]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

Pytorch版本

使用高版本的pytorch例如1.7.0会报错,使用低版本的pytorch又和CUDA不兼容,改怎么处理好

如何使用呢?

image为什么xiaogyu效果是这样的还是我的操作方法的问题呢?作者大哥看到的话请联系我谢谢了,3241644639 (qq)

Joint model

Hi, thanks for detailed descriptions of training steps! I want to know if it's necessary to jointly train edge and inpainting models? ( line 164 in edge_connect.py ) Have you tried it ?

你好

很有趣的一款工具,是否有兴趣接入到ImagePy,图像展示和常规的交互都是框架提供的,对于Python项目接入应该毫无阻力。由于我目前工作重点在科学计算,生物,材料图像分析上,但如果你有兴趣,我会全力辅助。

运行不了/ I can't run the tool

多谢学长代码。我运行了工具,用的win10CPU,只用input和output两个窗口,可以显示 Image selected: G:\yzceig\Pictures\input.png,前面打印的也没问题。然后就用左键划黑线,但按‘n'键无反应,命令行光标一直在闪,按其他键也一样无反应。这可能是什么问题。

About recall and precision

I found that the recall rate and accuracy rate are very low during my training. Is my training not enough? is this normal?I am using my own data set
512/512 [====================] - 29s 56ms/step - epoch: 66 - iter: 2012224 - precision: 0.1374 - recall: 0.1230

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.