|
| 1 | +# Copyright (C) 2018-2024 Intel Corporation |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +# |
| 5 | +# fill_const paddle model generator |
| 6 | +# |
| 7 | +import numpy as np |
| 8 | +from save_model import saveModel |
| 9 | +import paddle |
| 10 | +import sys |
| 11 | + |
| 12 | + |
| 13 | +def eye(name : str, rows, cols = None, dtype = None): |
| 14 | + paddle.enable_static() |
| 15 | + with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): |
| 16 | + if paddle.__version__ >= '2.0.0': |
| 17 | + x1 = paddle.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill') |
| 18 | + x2 = paddle.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill') |
| 19 | + else: |
| 20 | + x1 = paddle.fluid.layers.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill_constant') |
| 21 | + x2 = paddle.fluid.layers.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill_constant') |
| 22 | + out = paddle.add(x1, x2) |
| 23 | + cpu = paddle.static.cpu_places(1) |
| 24 | + exe = paddle.static.Executor(cpu[0]) |
| 25 | + # startup program will call initializer to initialize the parameters. |
| 26 | + exe.run(paddle.static.default_startup_program()) |
| 27 | + |
| 28 | + outs = exe.run( |
| 29 | + fetch_list=[out]) |
| 30 | + |
| 31 | + saveModel(name, exe, feed_vars=[], fetchlist=[out], inputs=[], outputs=[outs[0]], target_dir=sys.argv[1]) |
| 32 | + |
| 33 | + return outs[0] |
| 34 | + |
| 35 | +def main(): |
| 36 | + eye("eye", 3) |
| 37 | + eye("eye_int32", 2, 3, "int32") |
| 38 | + eye("eye_int64", 2, 3, "int64") |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + main() |
0 commit comments