tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 1 of dimension 0 out o
导入模型时参数不匹配导致这个问题,检查预训练模型是否和你的模型参数匹配。
tensorflow.python.framework.errors_impl.InvalidArgumentError: Retval[0] does not have value
这个问题定位出来了,是我做分割任务时,不可以使用tf.losses.get_total_loss(add_regularization_losses=True),这句话去掉就ok了,没有太明白这个缘故。
Key regression/Variable not found in checkpoint.........
1、首先是自己定义的参数变量是否和保存的参数变量的类型是一致的
2、在文件下面是否有一个叫做chockpoint的东西存在
3、最后如果运行多次出现NotFoundError (see above for traceback): Key Variable_4 not found in checkpoint [[Node: save_2/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT,这种情况,请使用tf.reset_default_graph(),还有就是这句话要放在前面一点。
4、还有就是保存好了模型,如果使用的是spyder请先关闭,之后在尝试读入模型如果以上都无法解决你的问题,请删除模型之后,重新写入,再载入试试。
5、
把
saver.restore(sess,"./mnist/data/convolutional.ckpt")
改成
module_file = tf.train.latest_checkpoint('mnist/data/convolutional.ckpt')
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
if module_file is not None:
saver.restore(sess, module_file)
这几种方法分情况可用,具体的还是要看自己的模型,tf.estimator默认会在模型的保存路径下自动索引checkpiont里面的模型,这部分要注意。