# neural-colorization
[![Build Status](https://www.travis-ci.org/zeruniverse/neural-colorization.svg?branch=pytorch)](https://www.travis-ci.org/zeruniverse/neural-colorization)
![Environment](https://img.shields.io/badge/python-3.6-blue.svg)
![License](https://img.shields.io/github/license/zeruniverse/QQRobot.svg)
GAN for image colorization based on [Johnson's network structure](https://github.com/jcjohnson/fast-neural-style).
![Result](https://cloud.githubusercontent.com/assets/4648756/20504440/4067e0f6-affc-11e6-88e7-26de6f5c1cce.jpg)
## Setup
Install the following Python libraries:
+ numpy
+ scipy
+ Pytorch
+ scikit-image
+ Pillow
+ opencv-python
## Colorize images
```bash
#Download pre-trained model
wget -O model.pth "https://github.com/zeruniverse/neural-colorization/releases/download/1.1/G.pth"
#Colorize an image with CPU
python colorize.py -m model.pth -i input.jpg -o output.jpg --gpu -1
# If you want to colorize all images in a folder with GPU
python colorize.py -m model.pth -i input -o output --gpu 0
```
## Train your own model
Note: Training is only supported with GPU (CUDA).
### Prepare dataset
+ Download some datasets and unzip them into a same folder (saying `train_raw_dataset`). If the images are not in `.jpg` format, you should convert them all in `.jpg`s.
+ run `python build_dataset_directory.py -i train_raw_dataset -o train` (you can skip this if all your images are **directly** under the `train_raw_dataset`, in which case, just rename the folder as `train`)
+ run `python resize_all_imgs.py -d train` to resize all training images into `256*256` (you can skip this if your images are already in `256*256`)
### Optional preparation
It's highly recommended to train from my pretrained models. You can get both generator model and discriminator model from the GitHub Release:
```bash
wget "https://github.com/zeruniverse/neural-colorization/releases/download/1.1/G.pth"
wget "https://github.com/zeruniverse/neural-colorization/releases/download/1.1/D.pth"
```
It's also recommended to have a test image (the script will generate a colorization for the test image you give at every checkpoint so you can see how the model works during training).
### Training
The required arguments are training image directory (e.g. `train`) and path to save checkpoints (e.g. `checkpoints`)
```bash
python train.py -d train -c chekpoints
```
To add initial weights and test images:
```bash
python train.py -d train -c chekpoints --d_init D.pth --g_init G.pth -t test.jpg
```
More options are available and you can run `python train.py --help` to print all options.
For torch equivalent (no GAN), you can set option `-p 1e9` (set a very large weight for pixel loss).
## Reference
[Perceptual Losses for Real-Time Style Transfer and Super-Resolution](https://github.com/jcjohnson/fast-neural-style)
## License
GNU GPL 3.0 for personal or research use. COMMERCIAL USE PROHIBITED.
Model weights are released under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
没有合适的资源?快使用搜索试试~ 我知道了~
用于图像着色的GAN_Pytorch实现_python_代码_下载
共9个文件
py:5个
yml:1个
license:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 6 下载量 200 浏览量
2022-06-17
10:13:03
上传
评论 2
收藏 20KB ZIP 举报
温馨提示
效果图: https://cloud.githubusercontent.com/assets/4648756/20504440/4067e0f6-affc-11e6-88e7-26de6f5c1cce.jpg
资源推荐
资源详情
资源评论
收起资源包目录
neural-colorization-pytorch.zip (9个子文件)
neural-colorization-pytorch
.travis.yml 1KB
colorize.py 2KB
build_dataset_directory.py 1KB
resize_all_imgs.py 1006B
train.py 7KB
LICENSE 35KB
model.py 4KB
.gitignore 20B
README.md 3KB
共 9 条
- 1
快撑死的鱼
- 粉丝: 2w+
- 资源: 9148
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页