def hard_sigmoid(name: str, x, slope: float = 0.2, offset: float = 0.5, data_type='float32'): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) out = paddle.fluid.layers.hard_sigmoid(node_x, slope=slope, offset=offset, name='hard_sigmoid') cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def equal_logical_xor(name: str, x, y, z): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') node_y = paddle.static.data(name='y', shape=y.shape, dtype='float32') node_z = paddle.static.data(name='z', shape=z.shape, dtype='float32') bool_x = paddle.equal(node_x, node_y) bool_y = paddle.equal(node_x, node_z) out = paddle.logical_and(bool_x, bool_y) out = paddle.cast(out, x.dtype) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x, 'y': y, 'z': z}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x', 'y', 'z'], fetchlist=[out], inputs=[x, y, z], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def paddle_shape(name: str, x): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') out = paddle.shape(node_x) out = paddle.cast(out, np.float32) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def pool2d(name: str, x, attrs: dict): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) out = paddle.fluid.layers.pool2d( node_x, pool_size=attrs['pool_size'], pool_type=attrs['pool_type'], pool_stride=attrs['pool_stride'], pool_padding=attrs['pool_padding'], global_pooling=attrs['global_pooling'], ceil_mode=attrs['ceil_mode'], exclusive=attrs['exclusive'], data_format=attrs['data_format']) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def pad3d(name: str, x, in_dtype, pad, data_format, mode, value=0): import paddle as pdpd pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x = pdpd.static.data(name='x', shape=x.shape, dtype=in_dtype) if mode == 'constant': pad_constant = pdpd.nn.Pad3D(padding=pad, mode=mode, value=value, data_format=data_format) out = pad_constant(node_x) else: pad_other_mode = pdpd.nn.Pad3D(padding=pad, mode=mode, data_format=data_format) out = pad_other_mode(node_x) cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def yolo_box(name : str, x, img_size, attrs : dict): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=x.dtype) node_img_size = paddle.static.data(name='img_size', shape=img_size.shape, dtype=img_size.dtype) boxes, scores = paddle.vision.ops.yolo_box(node_x, node_img_size, anchors=attrs['anchors'], class_num=attrs['class_num'], conf_thresh=attrs['conf_thresh'], downsample_ratio=attrs['downsample_ratio'], clip_bbox=attrs['clip_bbox'], name=None, scale_x_y=attrs['scale_x_y']) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run( feed={'x': x, 'img_size': img_size}, fetch_list=[boxes, scores]) # Save inputs in order of ngraph function, to facilite Fuzzy test, # which accepts inputs and outputs in this order as well. saveModel(name, exe, feedkeys=['x', 'img_size'], fetchlist=[boxes, scores], inputs=[x, img_size], outputs=outs, target_dir=sys.argv[1]) return outs
def expand_v2_tensor(name: str, x, out_shape, use_tensor_in_list): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) if use_tensor_in_list: out_shape[0] = paddle.assign( np.array((out_shape[0], )).astype('int32')) out = paddle.expand(node_x, shape=out_shape, name='expand_v2') else: out_shape = np.array(out_shape).astype('int32') node_shape = paddle.assign(out_shape, output=None) out = paddle.expand(node_x, shape=node_shape, name='expand_v2') cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def fill_any_like(name: str, x, value, dtype=None): pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): data = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) out = pdpd.full_like(data, value, dtype=dtype) out = pdpd.cast(out, np.float32) cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def paddle_pow_tensor(name: str, x, y, data_type): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) node_y = paddle.static.data(name='y', shape=y.shape, dtype=data_type) out = paddle.fluid.layers.pow(node_x, node_y, name='pow') out = paddle.cast(out, "float32") cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x, 'y': y}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def paddle_range(name: str, x, start, end, step, out_type): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') # Range op only support fill_constant input, since dynamic op is not supported in ov out = paddle.fluid.layers.range(start, end, step, out_type) out = paddle.cast(out, np.float32) out = paddle.add(node_x, out) #out = paddle.cast(out, np.float32) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def fill_constant_batch_size_like(name: str, x, shape, dtype, value, input_dim_idx=0, output_dim_idx=0): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): like = paddle.static.data(name='x', shape=x.shape, dtype=data_type) out = paddle.fluid.layers.fill_constant_batch_size_like(input=like, shape=shape, \ value=value, dtype=dtype, \ output_dim_idx=output_dim_idx, input_dim_idx=input_dim_idx) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def leaky_relu(name: str, x, alpha: float = 0.02, data_type='float32'): pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) out = pdpd.fluid.layers.leaky_relu(node_x, alpha=alpha, name='leaky_relu') cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def strided_slice(name: str, input_data, attrs: dict): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): Input = paddle.static.data(name='x', shape=input_data.shape, dtype=input_data.dtype) out = paddle.fluid.layers.strided_slice(Input, axes=attrs['axes'], starts=attrs['starts'], ends=attrs['ends'], strides=attrs['strides']) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': input_data}, fetch_list=[out]) # Save inputs in order of ngraph function, to facilite Fuzzy test, # which accepts inputs and outputs in this order as well. saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[input_data], outputs=[outs[0]], target_dir=sys.argv[1]) return outs
def softplus(name: str, x, beta, threshold): import paddle paddle.enable_static() node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') out = paddle.nn.functional.softplus(x=node_x, beta=beta, threshold=threshold) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def matmul(name, x1, x2, x_transpose=False, y_transpose=False): import paddle as pdpd pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x1 = pdpd.static.data(name='x1', shape=x1.shape, dtype=x1.dtype) node_x2 = pdpd.static.data(name='x2', shape=x2.shape, dtype=x2.dtype) result = pdpd.matmul(node_x1, node_x2, x_transpose, y_transpose) #result = pdpd.static.nn.batch_norm(mul_node, use_global_stats=True) cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x1': x1, 'x2': x2}, fetch_list=[result]) saveModel(name, exe, feedkeys=['x1', 'x2'], fetchlist=[result], inputs=[x1, x2], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def reshape(name: str, x, out_shape): import paddle as pdpd pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) out = pdpd.fluid.layers.reshape(x=node_x, shape=out_shape) cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def elementwise_mul(name: str, x, y, axis, in_dtype): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=in_dtype) node_y = paddle.static.data(name='y', shape=y.shape, dtype=in_dtype) out = paddle.fluid.layers.nn.elementwise_mul(node_x, node_y, axis=axis) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x, 'y': y}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def pdpd_pow(name: str, x, y, data_type): pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) out = pdpd.fluid.layers.pow(node_x, y, name='pow') #FuzzyTest supports int32 & float32 if data_type == "int64": out = pdpd.cast(out, "float32") out = pdpd.cast(out, "float32") cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def paddle_dropout(name: str, x, p, paddle_attrs): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') out = paddle.nn.functional.dropout(x=node_x, p=p, training=paddle_attrs['training'], mode=paddle_attrs['mode']) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def hard_swish(name: str, x, threshold=6.0, scale=6.0, offset=3.0, data_type='float32'): pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) out = pdpd.fluid.layers.hard_swish(node_x, threshold=threshold, scale=scale, offset=offset, name='hard_swish') cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def batch_norm2(name : str, x, scale, bias, mean, var, data_layout): import paddle paddle.enable_static() node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') scale_attr = paddle.ParamAttr(name="scale2", initializer=paddle.nn.initializer.Assign(scale)) bias_attr = paddle.ParamAttr(name="bias2", initializer=paddle.nn.initializer.Assign(bias)) out = paddle.static.nn.batch_norm(node_x, epsilon=1e-5, param_attr=scale_attr, bias_attr=bias_attr, moving_mean_name="bn_mean2", moving_variance_name="bn_variance2", use_global_stats=True, data_layout=data_layout) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) paddle.static.global_scope().var("bn_mean2").get_tensor().set(mean, paddle.CPUPlace()) paddle.static.global_scope().var("bn_variance2").get_tensor().set(var, paddle.CPUPlace()) outs = exe.run( feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def paddle_assign_value(name, test_x): import paddle paddle.enable_static() main_program = paddle.static.Program() startup_program = paddle.static.Program() with paddle.static.program_guard(main_program, startup_program): node_x = paddle.static.data( name='x', shape=test_x.shape, dtype=test_x.dtype if test_x.dtype != np.bool else np.int32) node_x = paddle.cast(node_x, dtype=test_x.dtype) const_value = paddle.assign(test_x, output=None) result = paddle.cast(paddle.concat([node_x, const_value], 0), dtype=np.float32) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) if test_x.dtype == np.bool: test_x = test_x.astype(np.int32) outs = exe.run(feed={'x': test_x}, fetch_list=[result]) saveModel(name, exe, feedkeys=['x'], fetchlist=[result], inputs=[test_x], outputs=[outs[0]], target_dir=sys.argv[1])
def adaptive_pool2d(name: str, x, attrs: dict): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) out = paddle.fluid.layers.adaptive_pool2d( input=node_x, pool_size=attrs['pool_size'], pool_type=attrs['pool_type'], require_index=attrs['require_index']) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def layer_norm(name: str, x, begin_norm_axis, scale=True, shift=True, param_attr=None, bias_attr=None): pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): data = pdpd.static.data(name='x', shape=x.shape, dtype=data_type) out = pdpd.static.nn.layer_norm(input=data, scale=scale, shift=shift,\ begin_norm_axis=begin_norm_axis, param_attr=param_attr, bias_attr=bias_attr) cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def generate_flatten_contiguous_range(name: str, x, start_axis, stop_axis, in_dtype): import paddle paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=in_dtype) out = paddle.flatten(node_x, start_axis, stop_axis) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def fill_constant_tensor(name: str, shape: list, dtype, value): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_value = paddle.static.data(name='value', shape=[1], dtype=dtype) x1 = paddle.fluid.layers.fill_constant(shape=shape, value=node_value, dtype=dtype, name='fill_constant1') out = paddle.cast(x1, np.float32) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={"value": value}, fetch_list=[out]) saveModel(name, exe, feedkeys=["value"], fetchlist=[out], inputs=[np.array([value]).astype(dtype)], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def unsqueeze(name: str, x, axes: list): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) out = paddle.fluid.layers.unsqueeze(node_x, axes=axes, name='unsqueeze') cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x'], fetchlist=[out], inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def fill_constant(name: str, shape: list, dtype, value): paddle.enable_static() with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): x1 = paddle.fluid.layers.fill_constant(shape=shape, value=value, dtype=dtype, name='fill_constant') x2 = paddle.fluid.layers.fill_constant(shape=shape, value=value, dtype=dtype, name='fill_constant') out = paddle.add(paddle.cast(x1, np.float32), paddle.cast(x2, np.float32)) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(fetch_list=[out]) saveModel(name, exe, feedkeys=[], fetchlist=[out], inputs=[], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def equal(name: str, x, y): import paddle paddle.enable_static() node_x = paddle.static.data(name='x', shape=x.shape, dtype='float32') node_y = paddle.static.data(name='y', shape=y.shape, dtype='float32') out = paddle.equal(node_x, node_y) out = paddle.cast(out, np.float32) cpu = paddle.static.cpu_places(1) exe = paddle.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(paddle.static.default_startup_program()) outs = exe.run(feed={'x': x, 'y': y}, fetch_list=[out]) saveModel(name, exe, feedkeys=['x', 'y'], fetchlist=[out], inputs=[x, y], outputs=[outs[0]], target_dir=sys.argv[1]) return outs[0]
def split(name: str, x, attrs: dict): import paddle as pdpd pdpd.enable_static() with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()): node_x = pdpd.static.data(name='x', shape=x.shape, dtype=x.dtype) out = pdpd.fluid.layers.split(node_x, num_or_sections=attrs['num_or_sections'], dim=attrs['axis']) cpu = pdpd.static.cpu_places(1) exe = pdpd.static.Executor(cpu[0]) # startup program will call initializer to initialize the parameters. exe.run(pdpd.static.default_startup_program()) outs = exe.run(feed={'x': x}, fetch_list=[out]) print("outputs: ", type(outs), len(outs)) print("out: ", type(out), len(out)) saveModel(name, exe, feedkeys=['x'], fetchlist=out, inputs=[x], outputs=outs, target_dir=sys.argv[1]) return outs[0]