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

你可能感兴趣的:(python,keras,tensorflow)