Keras快速风格迁移的实践

8次阅读

共计 1819 个字符,预计需要花费 5 分钟才能阅读完成。

本文是对 Github 项目 misgod/fast-neural-style-keras 的实践。


实践过程

  1. 下载并解压该 GitHub 项目。
  2. images 文件夹 中新建 output 文件夹train 文件夹
  3. train 文件夹 文件夹中放入你的数据集。
  4. images 文件夹style 文件夹 放入你的风格图片。
  5. 导入包:这是我反复测试得到的,pip install scipy==1.2.1pip install keras==2.1.2,使用这些版本会减少很多报错。
  6. 训练模型:python train.py --style 风格图片名 。注意:风格图片名不要带.jpg 文件后缀。
  7. 应用模型:自行参考该项目:python transform.py -i image/content/101.jpg -s la_muse -b 0.1 -o out

各种报错的解决方法


报错:ImportError: cannot import name ‘_obtain_input_shape’
参考:https://www.cnblogs.com/sssal…
解决:vgg16.py第 18 行处,使用 keras_applications 代替 keras.applications。


报错:ImportError: cannot import name ‘imsave’
参考:https://blog.csdn.net/weixin_…
解决:pip install scipy==1.2.1


报错:ModuleNotFoundError: No module named ‘sklearn’
解决:pip install sklearn


报错:AttributeError: module ‘keras.backend’ has no attribute ‘image_dim_ordering’
参考:https://blog.csdn.net/w568841…
解决:vgg16.py中第 87 行将 include_top 改为 require_flatten。


报错:FileNotFoundError: [WinError 3] 系统找不到指定的路径。:’images/train/’
解决:在 images 文件夹 中新建train 文件夹


报错:FileNotFoundError: [Errno 2] No such file or directory: ‘images/output/ 风格图片名_0.png’
解决:在 images 文件夹 中新建output 文件夹


报错:Found 0 images belonging to 0 classes.……ZeroDivisionError: integer division or modulo by zero
参考:https://cloud.tencent.com/dev…
解决:图片不能直接放在 train 文件夹 中。需在 train 文件夹 中再新建一个文件夹,再将图片放入新建文件夹中。


报错:ValueError: Error when checking target: expected block5_pool to have shape (None, 8, 8, 512) but got array with shape (1, 256, 256, 3)
参考:https://blog.csdn.net/weixin_41735859/article/details/86288356
解决:pip install keras==2.1.2


报错:ValueError: Input arrays should have the same number of samples as target arrays. Found 0 input samples and 1 target samples.
报错:No module named ‘keras.layers.merge’
报错:AttributeError: module ‘keras.backend’ has no attribute ‘image_dim_ordering’
报错:ImportError: You need to first‘import keras’in order to use‘keras_applications’
报错:ImportError: cannot import name ‘_obtain_input_shape’
以上统一解决:pip install keras==2.1.2


以上就是我实践过程中出现的问题,希望对大家有帮助!
吐槽一句:尽量模仿作者的运行环境(包括导入包的版本)能省好多好多事儿啊……

正文完
 0