Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未实现错误:预先训练的图形输出->新图层_Python_Tensorflow_Machine Learning - Fatal编程技术网

Python 未实现错误:预先训练的图形输出->新图层

Python 未实现错误:预先训练的图形输出->新图层,python,tensorflow,machine-learning,Python,Tensorflow,Machine Learning,我正在将预先训练好的图形的一些输出输入到Tensorflow中的一些附加层中。下面是我的一些代码的演练: 首先,我定义了一个新的tf.Graph,并在预先训练好的模型中加载 detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile('./mobilenetssd/frozen_inferen

我正在将预先训练好的图形的一些输出输入到Tensorflow中的一些附加层中。下面是我的一些代码的演练:

首先,我定义了一个新的tf.Graph,并在预先训练好的模型中加载

detection_graph = tf.Graph()
    with detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile('./mobilenetssd/frozen_inference_graph.pb', 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')
获取加载图形的输入/输出张量,定义占位符,添加一些操作

            image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
            output_matrix = detection_graph.get_tensor_by_name('concat:0')
            labels = tf.placeholder(tf.float32, [None, 1])

            # Adding operations
            outmat_sq = tf.squeeze(output_matrix)
            logits_max = tf.squeeze(tf.math.reduce_max(outmat_sq, reduction_indices=[0]))
            logits_mean = tf.squeeze(tf.math.reduce_mean(outmat_sq, reduction_indices=[0]))
            logodds = tf.concat([logits_max, logits_mean], 0)
            logodds = tf.expand_dims(logodds, 0)
            logodds.set_shape([None, 1204])
定义新层,设置优化器来训练新层

            hidden = tf.contrib.layers.fully_connected(inputs=logodds, num_outputs=500, activation_fn=tf.nn.tanh)
            out = tf.contrib.layers.fully_connected(inputs=hidden, num_outputs=1, activation_fn=tf.nn.sigmoid)

            # Define Loss, Training, and Accuracy 
            loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=out, labels=labels))
            training_step = tf.train.AdamOptimizer(1e-6).minimize(loss, var_list=[hidden, out])
            correct_prediction = tf.equal(tf.round(out), labels)
            accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
运行此代码后,我得到一个NotImplementedError:“尝试更新张量”,tf.Tensor“完全连接/Tanh:0”shape=?,500 dtype=float32错误。这似乎是将模型的两个部分链接在一起的问题。我是否需要将第一个图形的输出传递到某个tf.Variable中,然后再传递到后续的层中?另外,我正在使用TF1.10

对此有任何见解都将不胜感激