美文网首页我爱编程
Week5- CycleGAN试用感受

Week5- CycleGAN试用感受

作者: Feather轻飞 | 来源:发表于2018-03-14 10:01 被阅读0次

    https://github.com/vanhuyz/CycleGAN-TensorFlow

    First, download a dataset, e.g. apple2orange

    $ bash download_dataset.sh apple2orange

    http://ju.outofmemory.cn/entry/326146

    https://github.com/yuxiaofelicia/CycleGAN-TensorFlow

    https://github.com/tensorflow/models/blob/master/research/slim/nets/cyclegan.py

    https://mlnotebook.github.io/post/GAN4/#buildmodel

    我倒是下载了它的数据集

    深度学习数据集好大

    下载都下载好久

    https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix

    这个是原著作者的

    命令行下载数据集的时候也下载好久。

    我可找不到这么多数据集来train人家

    我可能只能用pretained模型来搞我自己的应用

    伯克利的原作者也上传了大量的训练好的模型了

    1. 下载项目代码

    git clone https://github.com/vanhuyz/CycleGAN-TensorFlow.git

    2. 将图片转换成tfrecords格式

    这个项目中提供了一个build_data脚本,用于将图片转换成tfrecords形式。假设我们的图片存放在~/datasets/man2woman/a_resized/和 ~/datasets/man2woman/b_resized目录下,对应的命令就是:

    python3 build_data.py \

        --X_input_dir ~/Downloads/man2woman/a_resized/ \

        --Y_input_dir ~/Downloads/man2woman/b_resized/ \

        --X_output_file ~/Downloads/man2woman/man.tfrecords \

        --Y_output_file ~/Downloads/man2woman/woman.tfrecords

    3. 训练

    训练的命令为:

    python train.py \

        --X ~/datasets/man2woman/man.tfrecords \

        --Y ~/datasets/man2woman/woman.tfrecords \

        --image_size 256

    训练的过程比较漫长,此时可以打开TensorBoard来观察训练情况(运行这个命令时需要将“20170715-1622”改成机器中对应的文件夹,下同):

    tensorboard --logdir checkpoints/20170715-1622

    4. 导出模型并执行单张图片

    导出模型的方法为:

    python export_graph.py \

        --checkpoint_dir checkpoints/20170715-1622 \

        --XtoY_model man2woman.pb \

        --YtoX_model woman2man.pb  \

        --image_size 256

    对单张图片进行转换(将data/test.jpg替换为对应的输入图片地址):

    python inference.py \

    --model pretrained/man2woman.pb  \

    --input data/test.jpg  \

    --output data/output.jpg \

    --image_size 256

    Felicias-MacBook-Air:~ felicia$ cd CycleGAN-TensorFlow

    Felicias-MacBook-Air:CycleGAN-TensorFlow felicia$ python build_data.py \

    > --X_input_dir ~/Downloads/man2woman/a_resized/ \

    > --Y_input_dir ~/Downloads/man2woman/b_resized/ \

    > --X_output_file ~/Downloads/man2woman/man.tfrecords \

    > --Y_output_file ~/Downloads/man2woman/woman.tfrecords

    Traceback (most recent call last):

     File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, infrom tensorflow.python.pywrap_tensorflow_internal import * File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in_pywrap_tensorflow_internal = swig_import_helper() File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/Users/felicia/anaconda3/lib/python3.6/imp.py", line 243, in load_module return load_dynamic(name, filename, file) File "/Users/felicia/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic return _load(spec)ImportError: dlopen(/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: @rpath/libcublas.8.0.dylib Referenced from: /Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so Reason: image not foundDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "build_data.py", line 1, inimport tensorflow as tf File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, infrom tensorflow.python import * File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 51, infrom tensorflow.python import pywrap_tensorflow File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, inraise ImportError(msg)ImportError: Traceback (most recent call last): File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, infrom tensorflow.python.pywrap_tensorflow_internal import * File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper()

      File "/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper

        _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)

      File "/Users/felicia/anaconda3/lib/python3.6/imp.py", line 243, in load_module

        return load_dynamic(name, filename, file)

      File "/Users/felicia/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic

        return _load(spec)

    ImportError: dlopen(/Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: @rpath/libcublas.8.0.dylib

      Referenced from: /Users/felicia/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so

      Reason: image not found

    Failed to load the native TensorFlow runtime.

    See https://www.tensorflow.org/install/install_sources#common_installation_problems

    for some common reasons and solutions.  Include the entire stack trace

    above this error message when asking for help.

    好像是因为装了1.1和1.5

    卸载了1.5就可以顺利import了

    没办法 不

    DATA_ROOT=./datasets/ae_photos 

    name=style_cezanne_pretrained 

    model=one_direction_test 

    phase=test 

    loadSize=256 

    fineSize=256 

    resize_or_crop="scale_width" 

    th test.lua

    相关文章

      网友评论

        本文标题:Week5- CycleGAN试用感受

        本文链接:https://www.haomeiwen.com/subject/bkywaxtx.html