前言
主要是解决由于1.0版本和2.0版本代码实现不同造成的报错
报错一:cannot import name 'Adam' from'keras.optimizers'
报错语句:from keras.optimizers import Adam 正确语句:from keras.optimizers import adam_v2
报错二:module 'tensorflow' has no attribute 'app'
报错语句:
import tensorflow as tf
flags =tf.app.flags
FLAGS = flags.FLAGS
正确语句:
import tensorflow.compat.v1 as tf
flags=tf.app.flags
FLAGS = tf.app.flags.FLAGS
报错三:No module named 'tensorflow.contrib'
报错语句:import tensorflow.contrib.keras as kr
正确语句:import keras as kr
报错四: module 'tensorflow' has no attribute 'placeholder'
错误代码:import tensorflow as tf 正确代码: import tensorflow.compat.v1 as tf tf.disable_v2_behavior() tf.compat.v1.disable_eager_execution()
但是改之后出现错误五
报错五:module 'tensorflow.compat.v1' has no attribute 'contrib'
错误代码:Cell = tf.contrib.rnn.DropoutWrapper(cell, self.keep_pro)
正确代码:Cell =tf.nn.rnn_cell.DropoutWrapper(cell, self.keep_pro)
(此时tf=tensorflow.compat.v1)
报错六: module 'tensorboard.summary._tf.summary' has no attribute 'merge_all'
错误语句:import tensorflow as tf
正确语句:import tensorflow.compat.v1 as tf
报错七:module 'tensorflow' has no attribute 'Session'
解决同六
报错八:module 'keras.utils' has no attribute 'to_categorical'
错误语句:
import keras as kr y_pad = kr.utils.to_categorical(label_id)
正确语句:
import tensorflow as tf y_pad = tf.keras.utils.to_categorical(label_id)
遇到版本不一致问题,可以直接到官网搜索对应的函数,会出来相应的导入路径
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)