目录html
对抗神经网络python
参考:http://www.javashuo.com/article/p-opzashmi-dy.htmlgit
官方详细介绍:https://affinelayer.com/pix2pix/github
这篇博客中详细介绍了如何搭建tensorflow环境docker
# clone this repo git clone https://github.com/affinelayer/pix2pix-tensorflow.git cd pix2pix-tensorflow # download the CMP Facades dataset (generated from http://cmp.felk.cvut.cz/~tylecr1/facade/) 下载数据集 python tools/download-dataset.py facades # 训练数据 python pix2pix.py \ --mode train \ # 设置mode为训练模式 --output_dir facades_train \ # 输出地址 --max_epochs 200 \ # 最大神经元熟练 --input_dir facades/train \ # 输入训练集所在地址 --which_direction BtoA # 方向 # 测试模型 python pix2pix.py \ --mode test \ #设置测试模式 --output_dir facades_test \ # 输出地址 --input_dir facades/val \ # 输入地址 --checkpoint facades_train # 检查点保存
测试结果:shell
facades_train ├── checkpoint ├── events.out.tfevents.1534087226.learner-pc ├── events.out.tfevents.1534126535.learner-pc ├── graph.pbtxt ├── model-80000.data-00000-of-00001 ├── model-80000.index ├── model-80000.meta └── options.json
其中facades_train记录的是检查点checkpointjson
facades_test ├── events.out.tfevents.1534229330.learner-pc ├── graph.pbtxt ├── images │ ├── 1-inputs.png .... │ └── 1-targets.png .... ├── index.html └── options.json
其中facades_test记录的是训练的结果,能够打开index.html进行查看具体的内容网络
你须要制做图片A,B,而后合成一张图片,做为一个训练图片。测试
其余数据集请见https://github.com/pprp/pix2pix-tensorflowthis
示意图:
# Resize source images, 如上图,进行resize python tools/process.py \ --input_dir photos/original \ --operation resize \ --output_dir photos/resized # Create images with blank centers # 如上图,建立空白 python tools/process.py \ --input_dir photos/resized \ --operation blank \ --output_dir photos/blank # Combine resized images with blanked images # 结合两张图片 python tools/process.py \ --input_dir photos/resized \ --b_dir photos/blank \ --operation combine \ --output_dir photos/combined # Split into train/val set # 将图片进行分配 python tools/split.py \ --dir photos/combined
若是您有两个目录,a
而且b
具备相应的图像(相同的名称,相同的尺寸,不一样的数据),您能够将它们与process.py
:
python tools/process.py \ --input_dir a \ --b_dir b \ --operation combine \ --output_dir c
这使得图像成为pix2pix.py
指望的并排组合图像。
对于着色,理想状况下,您的图像应具备相同的宽高比。您可使用resize命令调整大小并裁剪它们:
python tools/process.py \ --input_dir photos/original \ --operation resize \ --output_dir photos/resized
不须要其余处理,着色模式(参见下面的训练部分)使用单个图像而不是图像对。
因为图片是成对的,你能够决定图片的方向是AtoB
or BtoA
以maps数据集为例:
python pix2pix.py \ --mode train \ --output_dir maps_train \ --max_epochs 200 \ --input_dir maps/train \ --which_direction BtoA
pix2pix.py
包括使用单个图像而不是成对处理着色的特殊代码,使用以下所示:
python pix2pix.py \ --mode train \ --output_dir photos_train \ --max_epochs 200 \ --input_dir photos / train \ --lab_colorization
在该模式中,图像A是黑白图像(仅亮度),图像B包含该图像的颜色通道(没有亮度信息)。
您可使用tensorboard查看损失和计算图:
tensorboard --logdir = facades_train
若是您但愿在网络培训时编写正在进行的图片,请使用--display_freq 50
。这将facades_train/index.html
使用当前的训练输入和输出更新每50个步骤。
测试完成--mode test
。您应该指定要使用的检查点--checkpoint
,这应该指向output_dir
您以前建立的--mode train
以maps数据集为例:
python pix2pix.py \ --mode test \ --output_dir maps_test \ --input_dir maps/val \ checkpoint maps_train
测试模式将从提供的检查点加载一些配置选项,所以您无需指定which_direction
实例。
测试运行将输出一个HTML文件facades_test/index.html
,显示输入/输出/目标图像集
Validation of the code was performed on a Linux machine with a ~1.3 TFLOPS Nvidia GTX 750 Ti GPU and an Azure NC6 instance with a K80 GPU.
git clone https://github.com/affinelayer/pix2pix-tensorflow.git cd pix2pix-tensorflow python tools/download-dataset.py facades sudo nvidia-docker run \ --volume $PWD:/prj \ --workdir /prj \ --env PYTHONUNBUFFERED=x \ affinelayer/pix2pix-tensorflow \ python pix2pix.py \ --mode train \ --output_dir facades_train \ --max_epochs 200 \ --input_dir facades/train \ --which_direction BtoA sudo nvidia-docker run \ --volume $PWD:/prj \ --workdir /prj \ --env PYTHONUNBUFFERED=x \ affinelayer/pix2pix-tensorflow \ python pix2pix.py \ --mode test \ --output_dir facades_test \ --input_dir facades/val \ --checkpoint facades_train
nvidia-docker能够参看以前的文章进行安装
主要是官方给出的说明:references