小编Jos*_*ert的帖子

import_meta_graph因数据丢失而失败:不是稳定的(错误的魔术数字)

语境

我在尝试解决另一个错误时遇到了这个问题。第一个错误(原始问题)是,当我尝试还原元图时,我会得到Cannot find KeyError: "The name 'multi_rnn_cell_6' refers to an Operation not in the graph."。在尝试为该问题创建MVCE时,我发现了此错误。

问题

创建一些操作,保存元图和变量,然后尝试加载图和变量的简单脚本失败。该问题似乎与TF使用的格式有关。

MVCE

import tensorflow as tf
import numpy as np
import os
import glob

class ImportIssue(object):
    def __init__(self,load=False,model_scope = 'model',checkpoint='checkpoint'):
        try:
            os.makedirs(checkpoint)
        except:
            pass

        save_file = os.path.join(checkpoint,'model')
        print("Save file: {}".format(save_file))

        graph = tf.Graph()
        with graph.as_default():
            if load:
                # load model if requested
                model_to_load = "{}.meta".format(tf.train.latest_checkpoint(checkpoint))
                print("Loading model: {}".format(model_to_load))
                rest = tf.train.import_meta_graph(model_to_load)
            else:
                # else create one
                with tf.variable_scope(model_scope):
                    inputs = tf.placeholder(shape=(None,10,10),dtype=tf.float32)
                    cell …
Run Code Online (Sandbox Code Playgroud)

python serialization python-3.x tensorflow

5
推荐指数
2
解决办法
2266
查看次数

标签 统计

python ×1

python-3.x ×1

serialization ×1

tensorflow ×1