假设我有一个操作my_op
,定义如下:
name: "Const"
op: "Const"
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "value"
value {
tensor {
dtype: DT_INT32
tensor_shape {
dim {
size: 2
}
}
tensor_content: "\001\000\000\000\001\000\000\000"
}
}
}
我可以访问图形中的操作,但不能访问构造代码。我想复制操作并更改其某些属性:
name: "PrettyConst"
op: "Const"
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "value"
value {
tensor {
dtype: DT_FLOAT32
tensor_shape {
dim {
size: 8
}
}
tensor_content: "\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000"
}
}
}
虽然我可以通过将图形另存为txt、修改文件内容并将其还原回来来轻松地完成,但在python中找不到一种简单的方法。我认为应该有可能做到以下几点:
op_def_copy = op.node_def.copy()
op_def_copy.name = "PrettyConst"
op_def_copy.attr["dtype"] = 0
# and also do something with the content, whatever
graph.append(tf.Operation(op_def_copy))
不过,tf.contrig.graph_editor
似乎能够做到这一点。你知道吗
@jdehesa很好地回答了这个问题。我有更多的工具:
必须从文本表示中解析^{} 消息,然后才能从中构建^{} 。你可以这样做:
注意,如果您正在构建的操作需要一些输入,那么您可能需要向^{} 传递额外的参数。你知道吗
相关问题 更多 >
编程相关推荐