报错
illegal instruction
tensorflow-gpu 1.6.0之后的版本要求gpu支持AVX指令集,老版GPU不支持,切换回1.5.0或之前版本
ValueError: Variable hello/rnn/basic_lstm_cell/weights already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at
因为之前的cell kernel还在运行,如果使用的两个不同的cell,用variable scope指明
with tf.variable_scope('forward'):
self.lstm_fw_cell = rnn_cell.BasicLSTMCell(dim_hidden)
with tf.variable_scope('backward'):
self.lstm_bw_cell = rnn_cell.BasicLSTMCell(dim_hidden)
如果使用的是相同的cell,将cell中的reuse设为True
rnn.BasicLSTMCell(num_hidden, forget_bias=1.0, reuse = True)
报错
Attempting to use uninitialized value AUC/AUC/auc/false_positives
由于除了global variables,tf还会创建一些local variables,比如说像step,将local variables一起初始化就可以
init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
事实证明我太naive了,我在用saver()重新加载之前模型的时候再次遇到了这个问题:
这次错误是:attention_wrapper中Bahdanau Attention的attention_v未初始化,我看了一下源码:
v = variable_scope.get_variable("attention_v", [num_units], dtype=dtype)
是在bahdanau_score函数中初始化的参数,是一个局部变量
解决方法是在restore模型之前重新初始化一下所有参数(大部分教程中并不会这么做,如果ckpt: restore,否则 init)
init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
经高手指导,一个较好处理这类事情的方法:用slim去查看存储的变量,方法见slim函数
然后决定存储哪些或者读取哪些
restorer = tf.train.Saver(restore_variables)
#或者初始化掉部分变量
tf.local_variables_initializer(var1,var2)
报错
TypeError: can't pickle _thread.lock objects
tf0.10.0与之后的版本embedding_attention_seq2seq有些变化,1.10.0版本不会出现,但之后版本会有这个问题
如果想用多个backuts,会调用module_with_buckets,重复调用会使deepcopy(cell) 产生这个错误
修改\yourpath\tensorflow\contrib\legacy_seq2seq\python\ops\seq2seq.py:
#encoder_cell = copy.deepcopy(cell)
encoder_cell = core_rnn_cell.EmbeddingWrapper(
cell, #encoder_cell,
tensorflow上还有一种解决办法不需要修改seq2seq文件:
setattr(tf.contrib.rnn.GRUCell, '__deepcopy__', lambda self, _: self)
setattr(tf.contrib.rnn.BasicLSTMCell, '__deepcopy__', lambda self, _: self)
setattr(tf.contrib.rnn.MultiRNNCell, '__deepcopy__', lambda self, _: self)
报错
Non-ASCII character '\xe6' in file //model.py on line 19, but no encoding declared;
model.py注释中有中文字符,在文件最前面加上
# encoding: utf-8
报错
Unknown command line flag 'f'
jupyter中定义tf.app.flags会出现这个报错,指明f即可
tf.app.flags.DEFINE_string('f', '', 'kernel')