predict.py 1.0 KB
Newer Older
G
gaotingquan 已提交
1 2 3 4 5 6 7 8 9
import os
import sys
__dir__ = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.abspath(os.path.join(__dir__, '../')))

import cv2

from engine import build_engine
from utils import config
W
weishengyu 已提交
10 11 12 13 14 15 16 17


def main():
    args = config.parse_args()
    config_dict = config.get_config(
        args.config, overrides=args.override, show=False)
    config_dict.profiler_options = args.profiler_options
    engine = build_engine(config_dict)
W
weishengyu 已提交
18 19 20
    image_file = "../../images/wangzai.jpg"
    img = cv2.imread(image_file)[:, :, ::-1]
    input_data = {"input_image": img}
G
gaotingquan 已提交
21 22
    data = engine.process(input_data)

G
fix  
gaotingquan 已提交
23 24 25 26 27 28
    # for cls
    if "classification_res" in data:
        print(data["classification_res"])
    # for det
    elif "detection_res" in data:
        print(data["detection_res"])
G
gaotingquan 已提交
29
    # for rec
G
fix  
gaotingquan 已提交
30 31 32 33 34 35 36
    elif "features" in data["pred"]:
        features = data["pred"]["features"]
        print(features)
        print(features.shape)
        print(type(features))
    else:
        print("ERROR")
G
gaotingquan 已提交
37

W
weishengyu 已提交
38 39 40

if __name__ == '__main__':
    main()