from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
from tensorflow.python.tools import optimize_for_inference_lib
loaded = tf.saved_model.load('models/mnist_test')
infer = loaded.signatures['serving_default']
f = tf.function(infer).get_concrete_function(
flatten_input=tf.TensorSpec(shape=[None, 28, 28, 1],
dtype=tf.float32)) # change this line for your own inputs
f2 = convert_variables_to_constants_v2(f)
graph_def = f2.graph.as_graph_def()
if optimize :
# Remove NoOp nodes
for i in reversed(range(len(graph_def.node))):
if graph_def.node[i].op == 'NoOp':
del graph_def.node[i]
for node in graph_def.node:
for i in reversed(range(len(node.input))):
if node.input[i][0] == '^':
del node.input[i]
# Parse graph's inputs/outputs
graph_inputs = [x.name.rsplit(':')[0] for x in frozen_func.inputs]
graph_outputs = [x.name.rsplit(':')[0] for x in frozen_func.outputs]
graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def,
graph_inputs,
graph_outputs,
tf.float32.as_datatype_enum)
# Export frozen graph
with tf.io.gfile.GFile('optimized_graph.pb', 'wb') as f:
f.write(graph_def.SerializeToString())我有一个元组列表,比方说
tuplist = [('a','b'),('a','c'),('e','f'),('f','c'),('d','z'),('z','x')]
我正在尝试获得以下信息:
('a','b','c','e','f'),('d','z','x')
这是链接在一起的所有元素(就像图论中的树) 上述元组(也可以是列表)中的顺序无关紧要。
我已经设法获得单个元素的所有链接的字典,但我正在努力以一种干净有效的方式获得最终结果......这是我到目前为止的代码:
ll=[('a','b'),('a','c'),('e','f'),('f','c'),('d','z'),('z','x')]
total = {}
total2={}
final=[]
for element in set([item for sublist in ll for item in sublist]):
互换的青春
慕后森
相关分类