【问题标题】:Tensorflow - Where's the input node for my Convolutional Neural Network?Tensorflow - 我的卷积神经网络的输入节点在哪里?
【发布时间】:2018-04-06 04:53:24
【问题描述】:

我已经成功地在我的 PC 中使用 Python 接口为 Tensorflow 构建了一个卷积神经网络,现在我想将上述 CNN 用于 Android 的 Tensorflow。然而,当我使用tf.GraphDef()(gf.ParseFromString(open('F:/python_machine_learning_codes/graph_optimized.pb','rb').read()),然后是[n.name + '=>' + n.op for n in gf.node])查看模型中的节点列表时,我得到了这些:

['enqueue_input/random_shuffle_queue=>RandomShuffleQueueV2',
 'random_shuffle_queue_DequeueMany/n=>Const',
 'random_shuffle_queue_DequeueMany=>QueueDequeueManyV2',
 'Reshape/shape=>Const',
 'Reshape=>Reshape',
 #... the rest of the CNN's processing layers up to...
 'softmax_tensor=>Softmax']

我知道名为softmax_tensor 的节点是输出节点(这是我用来查看结果的),但是上面哪一个是输入节点?

【问题讨论】:

  • 从名字上看,“enqueue_input”节点似乎是个不错的候选...
  • 我试过了,得到了这个异常:java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'RandomShuffleQueueV2' with these attrs. Registered devices: [CPU], Registered kernels: <no registered kernels>。顺便说一句,该节点在回溯中的形状是这样的:[[Node: enqueue_input/random_shuffle_queue = RandomShuffleQueueV2[capacity=1000, component_types=[DT_INT64, DT_INT32, DT_FLOAT], container="", min_after_dequeue=250, seed=1, seed2=4, shapes=[[], [], [64,64,3]], shared_name=""]()]]
  • 这是关于您没有在设备上为[CPU] 执行操作RandomShuffleQueueV2,因此您无法启动图表。
  • 我用代码with tf.device("/gpu:0"): tf.app.run()训练了神经网络。这对问题有影响吗?
  • 另外,OpenCV 的 dnn_modern 模块也不识别 RandomShuffleQueueV2。

标签: python tensorflow


【解决方案1】:

事实证明,我一直在经历这一切都错了。我当时使用的图形冻结代码不是用于导出的代码。升级到最新的 Tensorflow 版本后,我只需要这样做:

feature_spec = {"x": tf.placeholder(dtype=tf.float32, shape=[None, 64*64*3])}
serving_input_fn = tf.estimator.export.build_raw_serving_input_receiver_fn(feature_spec)
model_version_path = mnist_classifier.export_savedmodel(
    "F:/python_machine_learning_codes/estimator_exported_model",
    serving_input_receiver_fn = serving_input_fn,
    assets_extra=None,
    as_text=False,
    checkpoint_path=None
    )

并且占位符节点正确显示在图表的开头,可以用作输入节点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2023-03-08
    • 2016-10-20
    • 2019-08-18
    • 2018-05-17
    • 2017-07-30
    • 2017-08-31
    相关资源
    最近更新 更多