你好:现在我正在将tensorflow的checkpoint模型转换为caffe模型。我已经成功地读取了图并提取了每个节点中的属性值。我得到了“Conv2D”节点中“dilations”,“strides”和“padding”属性的值以及“weights”节点中的形状,但是我无法获取“shape”属性的值,因为在Conv2D的输入节点中为空。然而,这些形状在tensorboard的图表中显示出来了。 以下是我的代码:
new_saver = tf.train.import_meta_graph(meta_path)
new_saver.restore(sess, tf.train.latest_checkpoint(ckpt_path))
graph_def = sess.graph_def
node_list = graph_def.node
# conv_node, weight_node, from_node are all in node_list
# conv_node: the conv2d node in graph_def
# weight_node: the weights node of conv2d
# from_node: the input feature map node of conv2d
weight_shape_attr = weight_node.attr['shape']
weight_shapes = [dim.size for dim in weight_shape_attr.shape.dim]
strides = [ii for ii in conv_node.attr['strides'].list.i]
dilations = [ii for ii in conv_node.attr['dilations'].list.i]
shapes = from_node.attr['shape'] # this is empty
还有 Tensorboard 图: tensorboard_graph
请注意 Conv2D 节点的输入形状为 ?x79x79x32,它必须存储在模型文件中的某个位置。能否有人提供帮助?任何提示都会很有帮助,谢谢。
_output_shape
,但如何打印所有节点的形状?这个不行:print([n._output_shapes for n in tf.get_default_graph().as_graph_def(add_shapes=True).node])
。 - Primozshapes = node.attr['_output_shapes']
,它会提供另一个protobuf对象,可以沿着这个路径导航到整数值,如:shapes.list.shape[0].dim[0].size
。可能有更方便的访问值的方法,但我不知道。 - dm0_add_shapes
函数? - Danijel