python报错

  1. 报错 cannot import name ‘plot_model’ from ‘keras.utils’

from keras.utils import plot_model

改为

from keras.utils.vis_utils import plot_model
  1. 报错 module tensorflow has no attribute reset_default_graph
    添加
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
  1. 报错module ‘scipy.misc’ has no attribute ‘imread’

将scipy.imsc
改为

1 import imageio
2 content_image = imageio.imread
  1. 报错 cannot import name ‘Adam‘ from ‘keras.optimizers‘
1. from keras.optimizers import adam_v2

2. adam_v2.Adam(lr=0.001, beta_1=XX, beta_2=XX, epsilon=XX)
  1. 报错 module ‘tensorflow.compat.v1‘ has no attribute ‘contrib‘
tf.contrib.layers.xavier_initializer()

替换成

 tf.keras.initializers.glorot_normal(
  1. 报错cannot import name ‘to_categorical’ from ‘keras.utils’
from keras.utils import to_categorical

替换为

from tensorflow.keras.utils import to_categorical
  1. 报错GRU(reset_after=False) is not compatible with GRU(reset_after=True)
model = load_model('./models/tr_model.h5')

替换为

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_v2_behavior() # model trained in tf1
model = tf.compat.v1.keras.models.load_model('./models/tr_model.h5')
  1. 报错SyntaxError: Non-UTF-8 code starting with ‘\xe5’ in file E:/21610/python100code/code2.py on line 4, but no encoding declared;
    在代码的最最最最顶上添加
# coding: UTF-8

或者

# coding: gkb
  1. 报错AttributeError: module ‘scipy.misc‘ has no attribute ‘imread‘
    安装pillow
pip install Pillow

替代scipy.imread

content_image = imageio.imread

添加

import imageio
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值