demo.py 2.2 KB
Newer Older
S
syyxsxx 已提交
1
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
S
syyxsxx 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#
# 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 sys
import os
import argparse
import deploy


def arg_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_dir",
        "-m",
        type=str,
        default=None,
        help="path to openvino model .xml file")
    parser.add_argument(
S
syyxsxx 已提交
30
        "--img", "-i", type=str, default=None, help="path to an image files")
S
syyxsxx 已提交
31 32

    parser.add_argument(
S
syyxsxx 已提交
33
        "--img_list", "-l", type=str, default=None, help="Path to a imglist")
S
syyxsxx 已提交
34 35

    parser.add_argument(
S
syyxsxx 已提交
36
        "--cfg_file",
S
syyxsxx 已提交
37 38 39 40 41
        "-c",
        type=str,
        default=None,
        help="Path to PaddelX model yml file")

S
syyxsxx 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55
    parser.add_argument(
        "--thread_num",
        "-t",
        type=int,
        default=1,
        help="Path to PaddelX model yml file")

    parser.add_argument(
        "--input_shape",
        "-ip",
        type=str,
        default=None,
        help=" image input shape of model [NCHW] like [1,3,224,244] ")

S
syyxsxx 已提交
56 57 58 59 60 61
    return parser


def main():
    parser = arg_parser()
    args = parser.parse_args()
S
syyxsxx 已提交
62
    model_nb = args.model_dir
S
syyxsxx 已提交
63
    model_yaml = args.cfg_file
S
syyxsxx 已提交
64 65
    thread_num = args.thread_num
    input_shape = args.input_shape
S
syyxsxx 已提交
66 67
    input_shape = input_shape[1:-1].split(",", 3)
    shape = list(map(int, input_shape))
S
syyxsxx 已提交
68
    #model init
S
syyxsxx 已提交
69 70
    predictor = deploy.Predictor(model_nb, model_yaml, thread_num, shape)

S
syyxsxx 已提交
71
    #predict
S
syyxsxx 已提交
72
    if (args.img_list != None):
S
syyxsxx 已提交
73 74 75 76 77 78 79 80 81 82
        f = open(args.img_list)
        lines = f.readlines()
        for im_path in lines:
            print(im_path)
            predictor.predict(im_path.strip('\n'))
        f.close()
    else:
        im_path = args.img
        predictor.predict(im_path)

S
syyxsxx 已提交
83

S
syyxsxx 已提交
84 85
if __name__ == "__main__":
    main()