Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print(
"1.0.0<=tensorflow<2.0.0 is required, and v1.14.0 is recommended"
)
return
except:
print("Tensorflow is not installed, use \"pip install tensorflow\".")
return
from x2paddle.decoder.tf_decoder import TFDecoder
from x2paddle.op_mapper.tf_op_mapper import TFOpMapper
from x2paddle.op_mapper.tf_op_mapper_nhwc import TFOpMapperNHWC
from x2paddle.optimizer.tf_optimizer import TFOptimizer
print("Now translating model from tensorflow to paddle.")
model = TFDecoder(model_path, define_input_shape=define_input_shape)
mapper = TFOpMapperNHWC(model)
optimizer = TFOptimizer(mapper)
optimizer.delete_redundance_code()
optimizer.strip_graph()
# optimizer.merge_activation()
# optimizer.merge_bias()
mapper.save_inference_model(save_dir, params_merge)
def __init__(self, decoder):
super(TFOpMapperNHWC, self).__init__()
self.decoder = decoder
self.graph = decoder.tf_graph
self.weights = dict()
self.batch_node = None
self.omit_nodes = list()
self.used_custom_layers = dict()
not_placeholder = list()
for name in self.graph.input_nodes:
if self.graph.get_node(name).layer_type != "Placeholder":
not_placeholder.append(name)
for name in not_placeholder:
idx = self.graph.input_nodes.index(name)
del self.graph.input_nodes[idx]
unsupported_ops = set()