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