实践过程
下载并解压该GitHub项目。
在images文件夹中新建output文件夹和train文件夹。
在train文件夹文件夹中放入你的数据集。
在images文件夹中style文件夹放入你的风格图片。
导入包:这是我反复测试得到的,pip install scipy==1.2.1和pip install keras==2.1.2,使用这些版本会减少很多报错。
训练模型:python train.py --style 风格图片名。注意:风格图片名不要带.jpg文件后缀。
应用模型:自行参考该项目: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
以上就是我实践过程中出现的问题,希望对大家有帮助!
吐槽一句:尽量模仿作者的运行环境(包括导入包的版本)能省好多好多事儿啊……
本文档详细介绍了使用Keras进行神经风格迁移的实践步骤,包括项目下载、数据组织、环境配置以及常见报错的解决方法。特别强调了安装特定版本的scipy和keras可以避免许多错误,例如:keras==2.1.2。通过实例解释了如何训练模型和应用模型,并提供了针对各种报错的解决方案,如调整vgg16.py代码、安装缺失模块等。
8468

被折叠的 条评论
为什么被折叠?



