提交 8fd11dda 编写于 作者: S SunAhong1993

for pad

上级 16df89ef
...@@ -354,7 +354,7 @@ class PaddleGraph(object): ...@@ -354,7 +354,7 @@ class PaddleGraph(object):
remove_default_attrs(layer.kernel, layer.attrs) remove_default_attrs(layer.kernel, layer.attrs)
edges_in = self.edges_in.get(layer_id, []) edges_in = self.edges_in.get(layer_id, [])
edges_out = self.edges_out.get(layer_id, []) edges_out = self.edges_out.get(layer_id, [])
if len(edges_in) == 0 and len(edges_out) == 0: if len(edges_in) == 0 and len(edges_out) == 0 and layer.outputs[0] not in self.outputs:
continue continue
line = "" line = ""
......
...@@ -16,4 +16,5 @@ ...@@ -16,4 +16,5 @@
from .one_hot import OneHot from .one_hot import OneHot
from .pad_two_input import PadWithTwoInput from .pad_two_input import PadWithTwoInput
from .pad_all_dim2 import PadAllDim2 from .pad_all_dim2 import PadAllDim2
from .pad_all_dim4 import PadAllDim4 from .pad_all_dim4 import PadAllDim4
\ No newline at end of file from .pad_all_dim4_one_input import PadAllDim4WithOneInput
\ No newline at end of file
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
from x2paddle.core.util import *
class PadAllDim4WithOneInput(object):
def __init__(self, pad, value, mode):
self.layer_attrs = {}
self.layer_attrs['mode'] = mode
self.layer_attrs['data_format'] = 'NCHW'
self.layer_attrs['value'] = value
self.pad1 = pad[0: 4]
self.pad2 = pad[4: 9]
def __call__(self, x):
x = paddle.nn.functional.pad(x=x, pad=self.pad1, **self.layer_attrs)
x = paddle.transpose(x, perm=[2, 3, 0, 1])
x = paddle.nn.functional.pad(x=x, pad=self.pad2, **self.layer_attrs)
out = paddle.transpose(x, perm=[2, 3, 0, 1])
return out
\ No newline at end of file
...@@ -415,7 +415,7 @@ class OpSet9(): ...@@ -415,7 +415,7 @@ class OpSet9():
paddle_op = 'paddle.nn.Pad{}D'.format(len(output_shape) - 2) paddle_op = 'paddle.nn.Pad{}D'.format(len(output_shape) - 2)
paddings = np.array(pads).reshape( paddings = np.array(pads).reshape(
(2, -1)).transpose().astype("int32") (2, -1)).transpose().astype("int32")
paddings = np.flip(paddings).flatten().tolist() paddings = np.flip(paddings, axis=0).flatten().tolist()
layer_attrs['padding'] = paddings layer_attrs['padding'] = paddings
else: else:
if data_shape: if data_shape:
...@@ -435,10 +435,16 @@ class OpSet9(): ...@@ -435,10 +435,16 @@ class OpSet9():
if output_shape: if output_shape:
assume_pad |= output_shape and 2 * len(output_shape) == len(pads) # NCHW assume_pad |= output_shape and 2 * len(output_shape) == len(pads) # NCHW
if assume_pad: if assume_pad:
paddle_op = 'paddle.nn.functional.pad' paddle_op = 'paddle.nn.Pad2D'
paddings = np.array(pads).reshape( paddings = np.array(pads).reshape(
(2, -1)).transpose().astype("int32").flatten().tolist() (2, -1)).transpose().astype("int32")
layer_attrs['pad'] = paddings paddings = np.flip(paddings, axis=0).flatten().tolist()
if sum(paddings[:4]) == 0:
paddings = paddings[4:]
layer_attrs['padding'] = paddings
else:
layer_attrs["pad"] = paddings
paddle_op = "custom_layer:PadAllDim4WithOneInput"
else: else:
raise Exception("The padding value {} is wrong!".format(pads)) raise Exception("The padding value {} is wrong!".format(pads))
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
......
...@@ -14,4 +14,7 @@ ...@@ -14,4 +14,7 @@
from .one_hot import one_hot from .one_hot import one_hot
from .pad import custom_pad from .pad_two_input import pad_with_two_input
\ No newline at end of file from .pad_all_dim2 import pad_all_dim2
from .pad_all_dim4 import pad_all_dim4
from .pad_all_dim4_one_input import pad_all_dim4_one_input
\ No newline at end of file
...@@ -14,31 +14,18 @@ ...@@ -14,31 +14,18 @@
import paddle import paddle
def one_hot(self, indices, depth, values, axis): def one_hot(indices, depth, values, axis):
indices_shape = paddle.shape(indices) indices_shape = indices.shape
tmp = paddle.ones_like(indices_shape, dtype="int32") rank = len(indices.shape)
rank = paddle.sum(tmp) real_axis = axis
if axis < 0:
real_axis = axis + rank + 1
depth_range = paddle.arange(end=depth) depth_range = paddle.arange(end=depth)
zero = paddle.zeros([1], dtype="int32") ls = tuple(indices_shape[0: real_axis])
one = paddle.ones([1], dtype="int32") rs = tuple(indices_shape[real_axis: rank])
axis = axis * one targets = paddle.reshape(depth_range, (1,) * (real_axis-0) + tuple(depth_range.shape) + (1,) * (rank-real_axis))
new_axis = axis + rank + 1
cond = paddle.less_than(axis, zero)
real_axis = paddle.where(cond, new_axis, axis)
ls = paddle.slice(indices_shape, axes=[0], starts=[0], ends=real_axis)
rs = paddle.slice(indices_shape, axes=[0], starts=real_axis, ends=rank)
tmp = paddle.ones_like(ls, dtype="int32")
ls_len = paddle.sum(tmp)
ls_list = paddle.ones(ls_len, dtype="int32")
tmp = paddle.ones_like(rs, dtype="int32")
rs_len = paddle.sum(tmp)
rs_list = paddle.ones(rs_len, dtype="int32")
depth_range_shape = paddle.shape(depth_range)
targets_shape = paddle.concat([ls_list, depth_range_shape, rs_list], axis=0)
targets = paddle.reshape(depth_range, targets_shape)
mod = paddle.mod(indices, depth) mod = paddle.mod(indices, depth)
v_shape = paddle.concat([ls, paddle.shape(one), rs], axis=0) v = paddle.reshape(mod, ls + (1,) + rs)
v = paddle.reshape(mod, v_shape)
out = targets == v out = targets == v
out = paddle.cast(out, "float32") out = paddle.cast(out, "float32")
on_value = paddle.slice(values, axes=[0], starts=[1], ends=[2]) on_value = paddle.slice(values, axes=[0], starts=[1], ends=[2])
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
def pad_all_dim2(x, pad, value, mode):
pad = paddle.reshape(pad, shape=[2, -1])
pad = paddle.transpose(pad, perm=[1, 0])
pad = paddle.reverse(pad, axis=[0])
pad = paddle.flatten(pad)
pad = paddle.cast(pad, dtype="int32")
x = paddle.unsqueeze(x, axis=[0, 1])
out = paddle.nn.functional.pad(x=x,
pad=pad,
mode=mode,
data_format='NCHW',
value=value)
out = paddle.squeeze(out, axis=[0, 1])
return out
\ No newline at end of file
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
def pad_all_dim4(x, pad, value, mode):
pad = paddle.reshape(pad, shape=[2, -1])
pad = paddle.transpose(pad, perm=[1, 0])
pad = paddle.reverse(pad, axis=[0])
pad = paddle.flatten(pad)
pad = paddle.cast(pad, dtype="int32")
pad1, pad2 = paddle.split(pad, num_or_sections=2, axis=0)
x = paddle.nn.functional.pad(x=x,
pad=pad1,
mode=mode,
data_format='NCHW',
value=value)
x = paddle.transpose(x, perm=[2, 3, 0, 1])
x = paddle.nn.functional.pad(x=x,
pad=pad2,
mode=mode,
data_format='NCHW',
value=value)
out = paddle.transpose(x, perm=[2, 3, 0, 1])
return out
\ No newline at end of file
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
def pad_all_dim4_one_input(x, pad, value, mode):
x = paddle.nn.functional.pad(x=x,
pad=pad[0: 4],
mode=mode,
data_format='NCHW',
value=value)
x = paddle.transpose(x, perm=[2, 3, 0, 1])
x = paddle.nn.functional.pad(x=x,
pad=pad[4: 9],
mode=mode,
data_format='NCHW',
value=value)
out = paddle.transpose(x, perm=[2, 3, 0, 1])
return out
\ No newline at end of file
...@@ -14,14 +14,15 @@ ...@@ -14,14 +14,15 @@
import paddle import paddle
def custom_pad(self, x, pad, value, mode): def pad_with_two_input(x, pad, value, mode, data_format):
layer_attrs = {}
layer_attrs['mode'] = string(mode)
layer_attrs['data_format'] = string('NCHW')
layer_attrs['value'] = value
pad = paddle.reshape(pad, shape=[2, -1]) pad = paddle.reshape(pad, shape=[2, -1])
pad = paddle.transpose(pad, perm=[1, 0]) pad = paddle.transpose(pad, perm=[1, 0])
pad = paddle.reverse(pad, axis=[0]) pad = paddle.reverse(pad, axis=[0])
pad = paddle.flatten(pad) pad = paddle.flatten(pad)
out = paddle.nn.functional.pad(x=x, pad=pad, **self.layer_attrs) pad = paddle.cast(pad, dtype="int32")
out = paddle.nn.functional.pad(x=x,
pad=pad,
value=value,
mode=mode,
data_format=data_format)
return out return out
\ No newline at end of file
...@@ -106,6 +106,9 @@ class OpSet9(): ...@@ -106,6 +106,9 @@ class OpSet9():
'ReduceMax': ['paddle.max', 'ReduceMax': ['paddle.max',
dict(axes='axis', keepdims='keepdim'), dict(axes='axis', keepdims='keepdim'),
dict(keepdim=1)], dict(keepdim=1)],
'ReduceProd': ['paddle.prod',
dict(axes='axis', keepdims='keepdim'),
dict(keepdim=1)],
# active function # active function
'Relu': ['paddle.nn.functional.relu'], 'Relu': ['paddle.nn.functional.relu'],
'LeakyRelu': ['paddle.nn.functional.leaky_relu', 'LeakyRelu': ['paddle.nn.functional.leaky_relu',
...@@ -380,73 +383,122 @@ class OpSet9(): ...@@ -380,73 +383,122 @@ class OpSet9():
value = node.get_attr('value', 0.) value = node.get_attr('value', 0.)
data_shape = val_x.out_shapes[0] data_shape = val_x.out_shapes[0]
output_shape = node.out_shapes[0] output_shape = node.out_shapes[0]
assume_pad2d = False assume_pad = False
layer_attrs = {} layer_attrs = {}
layer_attrs['mode'] = string(mode) layer_attrs['mode'] = string(mode)
layer_attrs['value'] = value
if not op_independent:
output_name = node.name + '_paded'
else:
output_name = node.name
layer_outputs = [output_name]
if is_pads_attr: if is_pads_attr:
paddings = [] paddings = []
if len(pads) == 4: paddle_op = 'paddle.nn.functional.pad'
assume_pad2d |= mode != 'constant' if len(pads) in [2, 4, 6]:
if data_shape: if data_shape:
assume_pad2d |= data_shape and len(data_shape) == 4 # NCHW assume_pad |= data_shape and 2 * (len(data_shape) - 2) == len(pads) # NCHW
if output_shape: if output_shape:
assume_pad2d |= output_shape and len(output_shape) == 4 # NCHW assume_pad |= output_shape and 2 * (len(output_shape) - 2) == len(pads) # NCHW
if assume_pad2d: if assume_pad:
paddle_op = 'paddle.nn.functional.pad' if len(pads) == 2:
layer_attrs['data_format'] = string('NCHW') data_format = "NCL"
layer_attrs['value'] = value elif len(pads) == 4:
else: data_format = "NCHW"
paddle_op = 'paddle.fluid.layers.pad' else:
layer_attrs["pad_value"] = value data_format = "NCDHW"
if len(pads) == 4:
paddings = np.array(pads).reshape( paddings = np.array(pads).reshape(
(-1, 2)).transpose().flatten().tolist() # SSEE -> SESE (2, -1)).transpose().astype("int32")
paddings = np.flip(paddings, axis=0).flatten().tolist()
layer_attrs['pad'] = paddings
layer_attrs['data_format'] = data_format
else:
if data_shape:
assume_pad |= data_shape and 2 * len(data_shape) == len(pads) # NCHW
if output_shape:
assume_pad |= output_shape and 2 * len(output_shape) == len(pads) # NCHW
if assume_pad:
paddings = np.array(pads).reshape(
(2, -1)).transpose().astype("int32").flatten().tolist()
layer_attrs['pad'] = paddings
else:
raise Exception("The padding value {} is wrong!".format(pads))
elif len(pads) == 8: elif len(pads) == 8:
paddings = np.array(pads).reshape( if data_shape:
(-1, 4)).transpose().flatten().tolist() # SSEE -> SESE assume_pad |= data_shape and 2 * len(data_shape) == len(pads) # NCHW
if sum(paddings[:4]) == 0: if output_shape:
paddle_op = 'paddle.nn.functional.pad' assume_pad |= output_shape and 2 * len(output_shape) == len(pads) # NCHW
paddings = paddings[4:] if assume_pad:
layer_attrs['value'] = value paddings = np.array(pads).reshape(
if 'pad_value' in layer_attrs: (2, -1)).transpose().astype("int32")
layer_attrs.pop('pad_value') paddings = np.flip(paddings, axis=0).flatten().tolist()
tmp_paddings = copy.deepcopy(paddings) if sum(paddings[:4]) == 0:
paddings[0] = tmp_paddings[2] paddings = paddings[4:]
paddings[1] = tmp_paddings[3] layer_attrs['pad'] = paddings
paddings[2] = tmp_paddings[0] else:
paddings[3] = tmp_paddings[1] layer_attrs['pad'] = paddings
if paddle_op == 'paddle.nn.functional.pad': paddle_op = "custom_layer:pad_all_dim4_one_input"
layer_attrs['pad'] = paddings
else:
layer_attrs['paddings'] = paddings
if op_independent:
self.paddle_graph.add_layer(
paddle_op,
inputs={'x': val_x.name},
outputs=[node.name],
**layer_attrs)
else: else:
self.paddle_graph.add_layer( raise Exception("The padding value {} is wrong!".format(pads))
paddle_op, self.paddle_graph.add_layer(
inputs={'x': val_x.name}, paddle_op,
outputs=[node.name + '_paded'], inputs={'x': val_x.name},
**layer_attrs) outputs=layer_outputs,
**layer_attrs)
if not op_independent:
return node.name + '_paded' return node.name + '_paded'
else: else:
if pad_shape[0] == 4: pads_len = val_pad.out_shapes[0][0]
assume_pad2d |= mode != 'constant' if pads_len in [2, 4, 6]:
if data_shape: if data_shape:
assume_pad2d |= data_shape and len(data_shape) == 4 # NCHW assume_pad |= data_shape and 2 * (len(data_shape) - 2) == pads_len # NCHW
if output_shape: if output_shape:
assume_pad2d |= output_shape and len(output_shape) == 4 # NCHW assume_pad |= output_shape and 2 * (len(output_shape) - 2) == pads_len # NCHW
if pad_shape[0] == 8 or not assume_pad2d: if assume_pad:
raise Exception("When the pad shape is 8 and pad is tensor, the op is not supported yet!") if pads_len == 2:
layer_attrs['value'] = value data_format = "NCL"
self.paddle_graph.add_layer( elif pads_len == 4:
"custom_layer:custom_pad", data_format = "NCHW"
inputs={'x': val_x.name, 'pad': val_pad.name}, else:
outputs=[node.name + '_paded'], data_format = "NCDHW"
**layer_attrs) self.paddle_graph.add_layer(
"custom_layer:pad_with_two_input",
inputs={'x': val_x.name, 'pad': val_pad.name},
outputs=layer_outputs,
value=value,
mode=string(mode),
data_format=string(data_format))
else:
if data_shape:
assume_pad |= data_shape and 2 * len(data_shape) == pads_len # NCHW
if output_shape:
assume_pad |= output_shape and 2 * len(output_shape) == pads_len # NCHW
if assume_pad:
if pads_len == 4:
self.paddle_graph.add_layer(
"custom_layer:pad_all_dim2",
inputs={'x': val_x.name, 'pad': val_pad.name},
outputs=layer_outputs,
value=value,
mode=string(mode))
else:
raise Exception("The padding value is wrong!")
elif pads_len == 8:
if data_shape:
assume_pad |= data_shape and 2 * len(data_shape) == pads_len # NCHW
if output_shape:
assume_pad |= output_shape and 2 * len(output_shape) == pads_len # NCHW
if assume_pad:
self.paddle_graph.add_layer(
"custom_layer:pad_all_dim4",
inputs={'x': val_x.name, 'pad': val_pad.name},
outputs=layer_outputs,
value=value,
mode=string(mode))
else:
print(pads_len)
raise Exception("The padding value is wrong!")
if not op_independent: if not op_independent:
return node.name + '_paded' return node.name + '_paded'
...@@ -650,15 +702,11 @@ class OpSet9(): ...@@ -650,15 +702,11 @@ class OpSet9():
inputs={"x": indices.name}, inputs={"x": indices.name},
outputs=[indices_cast], outputs=[indices_cast],
dtype=string('int64')) dtype=string('int64'))
op_name = name_generator("embedding", self.nn_name2id)
output_name = node.name
layer_outputs = [op_name, output_name]
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
'paddle.nn.Embedding', 'paddle.nn.functional.embedding',
inputs={"x": indices_cast}, inputs={"x": indices_cast,
outputs=layer_outputs, "weight": val_x.name},
param_attr=string(val_x.name), outputs=[node.name])
size=val_x.out_shapes[0])
else: else:
from functools import reduce from functools import reduce
reshape_shape = reduce(lambda x, y: x * y, indices_shape) reshape_shape = reduce(lambda x, y: x * y, indices_shape)
...@@ -830,14 +878,21 @@ class OpSet9(): ...@@ -830,14 +878,21 @@ class OpSet9():
starts = self.graph.get_input_node(node, idx=1, copy=True) starts = self.graph.get_input_node(node, idx=1, copy=True)
ends = self.graph.get_input_node(node, idx=2, copy=True) ends = self.graph.get_input_node(node, idx=2, copy=True)
starts_value = _const_weight_or_none(starts) starts_value = _const_weight_or_none(starts)
if starts_value is not None:
starts_value = starts_value.tolist()
ends_value = _const_weight_or_none(ends) ends_value = _const_weight_or_none(ends)
if ends_value is not None:
ends_value = ends_value.tolist()
if len(node.inputs) > 2:
s_len = len(val_x.out_shapes[0])
axes = list(range(s_len))
if len(node.inputs) > 3: if len(node.inputs) > 3:
axes = self.graph.get_input_node(node, idx=3, copy=True) axes_node = self.graph.get_input_node(node, idx=3, copy=True)
axes = _const_weight_or_none(axes, necessary=True) axes = _const_weight_or_none(axes_node, necessary=True).tolist()
if len(node.inputs) > 4: if len(node.inputs) > 4:
steps = self.graph.get_input_node(node, idx=4, copy=True) steps = self.graph.get_input_node(node, idx=4, copy=True)
steps = _const_weight_or_none(steps) steps = _const_weight_or_none(steps).tolist()
layer_attrs = { layer_attrs = {
"axes": axes, "axes": axes,
"starts": starts.name, "starts": starts.name,
...@@ -873,6 +928,8 @@ class OpSet9(): ...@@ -873,6 +928,8 @@ class OpSet9():
layer_attrs['starts'] = starts_cast layer_attrs['starts'] = starts_cast
if ends.dtype != 'int32': if ends.dtype != 'int32':
ends_cast = ends.name + '_cast' ends_cast = ends.name + '_cast'
else:
ends_cast = ends.name
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
'paddle.cast', 'paddle.cast',
inputs={"x": ends.name}, inputs={"x": ends.name},
...@@ -888,6 +945,7 @@ class OpSet9(): ...@@ -888,6 +945,7 @@ class OpSet9():
ends[idx] = 2**31 - 1 ends[idx] = 2**31 - 1
layer_attrs = {"axes": axes, "starts": starts, "ends": ends} layer_attrs = {"axes": axes, "starts": starts, "ends": ends}
if steps is not None: if steps is not None:
layer_attrs['strides'] = steps layer_attrs['strides'] = steps
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
...@@ -1012,6 +1070,12 @@ class OpSet9(): ...@@ -1012,6 +1070,12 @@ class OpSet9():
inputs={'x': val_shape.name}, inputs={'x': val_shape.name},
outputs=[val_shape.name], outputs=[val_shape.name],
shape=val_shape.out_shapes[0]) shape=val_shape.out_shapes[0])
if val_shape.dtype != "int32":
self.paddle_graph.add_layer(
'paddle.cast',
inputs={'x': val_shape.name},
outputs=[val_shape.name],
dtype=string("int32"))
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
'paddle.reshape', 'paddle.reshape',
inputs={'x': val_x.name, inputs={'x': val_x.name,
...@@ -1247,7 +1311,10 @@ class OpSet9(): ...@@ -1247,7 +1311,10 @@ class OpSet9():
@print_mapping_info @print_mapping_info
def Transpose(self, node): def Transpose(self, node):
val_x = self.graph.get_input_node(node, idx=0, copy=True) val_x = self.graph.get_input_node(node, idx=0, copy=True)
perm = node.get_attr('perm') s_len = len(val_x.out_shapes[0])
perm_default = list(range(s_len))
perm_default.reverse()
perm = node.get_attr('perm', perm_default)
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.transpose", "paddle.transpose",
inputs={"x": val_x.name}, inputs={"x": val_x.name},
...@@ -1620,8 +1687,13 @@ class OpSet9(): ...@@ -1620,8 +1687,13 @@ class OpSet9():
val_x = self.graph.get_input_node(node, idx=0, copy=True) val_x = self.graph.get_input_node(node, idx=0, copy=True)
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.shape", "paddle.shape",
inputs={"x": val_x.name}, inputs={"input": val_x.name},
outputs=[node.name]) outputs=[node.name])
self.paddle_graph.add_layer(
'paddle.cast',
inputs={"x": node.name},
outputs=[node.name],
dtype=string('int64'))
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.prod", "paddle.prod",
inputs={"x": node.name}, inputs={"x": node.name},
...@@ -1630,10 +1702,22 @@ class OpSet9(): ...@@ -1630,10 +1702,22 @@ class OpSet9():
@print_mapping_info @print_mapping_info
def Sign(self, node): def Sign(self, node):
val_x = self.graph.get_input_node(node, idx=0, copy=True) val_x = self.graph.get_input_node(node, idx=0, copy=True)
if node.dtype not in ["float16", "float32", "float64"]:
self.paddle_graph.add_layer(
"paddle.cast",
inputs={"x": val_x.name},
outputs=[val_x.name],
dtype=string("float32"))
self.paddle_graph.add_layer( self.paddle_graph.add_layer(
"paddle.sign", "paddle.sign",
inputs={"x": val_x.name}, inputs={"x": val_x.name},
outputs=[node.name]) outputs=[node.name])
if node.dtype not in ["float16", "float32", "float64"]:
self.paddle_graph.add_layer(
"paddle.cast",
inputs={"x": node.name},
outputs=[node.name],
dtype=string(node.dtype))
@print_mapping_info @print_mapping_info
def OneHot(self, node): def OneHot(self, node):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册