Tensorflow踩坑笔记,记录各种报错和解决方法

不知道是不是错觉,tensorflow比pytorch容易报错,记录一下踩的坑。
随时更新。

1 Loaded runtime CuDNN library: 7.4.1 but source was compiled with: 7.6.0

初始环境:tensorflow2.0(gpu)、CUDA 10.0、Cudnn 7.4.1、Windows 10

训练卷积神经网络(使用Conv2d类时)报错:

Loaded runtime CuDNN library: 7.4.1 but source was compiled with: 7.6.0.

然而官网的 tensorflow2.0(gpu)的环境要求却写了CUDA 10.0、Cudnn 7.4,误导作用明显。
报错直接提示了解决方案,把Cudnn升级到7.6.0即可,升级方法和安装Cudnn方法相同,去官网下载对应的Cudnn版本,覆盖源文件即可。也可以参考下面的参考资料。

参考资料:
版本不匹配||Loaded runtime CuDNN library: 7.4.2 but source was compiled with: 7.6.0. CuDNN library major

2 自定义的模型不能保存

环境:tensorflow2.0(gpu)、CUDA 10.0、Cudnn 7.6.0、Windows 10

使用tf.keras.models.save_model(model, 'path')保存模型时报错:

ValueError: Model <resnet.Resnet object at 0x000001A9E61DBC50> cannot be saved because the input shapes have not been set. Usually, input shapes are automatically determined from calling .fit() or .predict(). To manually set the shapes, call model._set_inputs(inputs).

参考资料:
1.stackoverflow
2.Github: Model cannot be saved because the input shapes have not been set. #39906

我的解决方案:
model初始化后,在build()中指定input_shape后,再写上model.compute_output_shape(input_shape=(None, 32, 32, 3))即可。
Tensorflow踩坑笔记,记录各种报错和解决方法
可以保存了:
Tensorflow踩坑笔记,记录各种报错和解决方法

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2022年6月15日 上午11:56
下一篇 2022年6月15日 上午11:58

相关推荐