Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def gen_codes(self):
codes = list()
for layer in self.layers:
if isinstance(layer, Layer):
codes.append(layer.get_code())
elif isinstance(layer, six.string_types):
codes.append(layer)
return codes
true_node = self.graph.get_node(node_name)
for i, in_name in enumerate(node.inputs):
in_node = graph_copy.get_node(in_name)
if hasattr(in_node, "is_nhwc") and in_node.is_nhwc:
if i == 0:
l = Layer()
l.op = "transpose"
l.inputs = true_node.fluid_code.layers[
0].inputs["x"]
l.param_attr = {"perm": [0, 2, 3, 1]}
l.output = "nhwc_" + l.inputs.layer_name
true_node.fluid_code.layers[0].inputs[
"x"] = l.output
true_node.fluid_code.layers.insert(0, l)
elif i == 1:
l = Layer()
l.op = "transpose"
l.inputs = true_node.fluid_code.layers[
0].inputs["y"]
l.param_attr = {"perm": [0, 2, 3, 1]}
l.output = "nhwc_" + l.inputs.layer_name
true_node.fluid_code.layers[0].inputs[
"y"] = l.output
true_node.fluid_code.layers.insert(0, l)
else:
raise Exception("Unexpected situation happend")
continue
else:
for out_name in node.outputs:
out_node = self.graph.get_node(out_name)
if out_node.layer_type not in elementwise_ops:
assert out_node.fluid_code.layers[
def add_layer(self,
op,
inputs,
output,
param_attr=None,
is_custom_layer=False):
layer = Layer()
layer.op = op
layer.is_custom_layer = is_custom_layer
if inputs is not None:
layer.inputs = inputs
layer.output = output
if param_attr is not None:
layer.param_attr = param_attr
self.layers.append(layer)