未验证 提交 12817b80 编写于 作者: Y Yuantao Feng 提交者: GitHub

Add model file collector, fix some bugs and add some features (#123)

add model path searcher and remove hardwritten file paths from benchmark configs; pack ppresnet, mobilenet & crnn with labels; fix palm det data; add flags to enable models of different precision separately (#123)
上级 933a4171
# OpenCV Zoo Benchmark
Benchmarking different models in the zoo.
Benchmarking the speed of OpenCV DNN inferring different models in the zoo. Result of each model includes the time of its preprocessing, inference and postprocessing stages.
Data for benchmarking will be downloaded and loaded in [data](./data) based on given config.
Time is measured from data preprocess (resize is excluded), to a forward pass of a network, and postprocess to get final results. The final time data presented is averaged from a 100-time run.
## Preparation
1. Install `python >= 3.6`.
......@@ -13,29 +11,29 @@ Time is measured from data preprocess (resize is excluded), to a forward pass of
3. Download data for benchmarking.
1. Download all data: `python download_data.py`
2. Download one or more specified data: `python download_data.py face text`. Available names can be found in `download_data.py`.
3. If download fails, you can download all data from https://pan.baidu.com/s/18sV8D4vXUb2xC9EG45k7bg (code: pvrw). Please place and extract data packages under [./data](./data).
3. You can also download all data from https://pan.baidu.com/s/18sV8D4vXUb2xC9EG45k7bg (code: pvrw). Please place and extract data packages under [./data](./data).
## Benchmarking
Run the following command to benchmark on a given config:
**Linux**:
```shell
export PYTHONPATH=$PYTHONPATH:..
python benchmark.py --cfg ./config/face_detection_yunet.yaml
```
If you are a Windows user and wants to run in CMD/PowerShell, use this command instead:
**Windows**:
- CMD
```shell
set PYTHONPATH=%PYTHONPATH%;..
python benchmark.py --cfg ./config/face_detection_yunet.yaml
```
```shell
set PYTHONPATH=%PYTHONPATH%;..
python benchmark.py --cfg ./config/face_detection_yunet.yaml
```
- PowerShell
```shell
$env:PYTHONPATH=$env:PYTHONPATH+";.."
python benchmark.py --cfg ./config/face_detection_yunet.yaml
```
```shell
$env:PYTHONPATH=$env:PYTHONPATH+";.."
python benchmark.py --cfg ./config/face_detection_yunet.yaml
```
<!--
Omit `--cfg` if you want to benchmark all included models:
```shell
......
......@@ -11,6 +11,9 @@ from utils import METRICS, DATALOADERS
parser = argparse.ArgumentParser("Benchmarks for OpenCV Zoo.")
parser.add_argument('--cfg', '-c', type=str,
help='Benchmarking on the given config.')
parser.add_argument("--fp32", action="store_true", help="Runs models of float32 precision only.")
parser.add_argument("--fp16", action="store_true", help="Runs models of float16 precision only.")
parser.add_argument("--int8", action="store_true", help="Runs models of int8 precision only.")
args = parser.parse_args()
def build_from_cfg(cfg, registery, key=None, name=None):
......@@ -24,14 +27,6 @@ def build_from_cfg(cfg, registery, key=None, name=None):
else:
raise NotImplementedError()
def prepend_pythonpath(cfg):
for k, v in cfg.items():
if isinstance(v, dict):
prepend_pythonpath(v)
else:
if 'path' in k.lower():
cfg[k] = os.path.join(os.environ['PYTHONPATH'].split(os.pathsep)[-1], v)
class Benchmark:
def __init__(self, **kwargs):
self._type = kwargs.pop('type', None)
......@@ -115,16 +110,30 @@ if __name__ == '__main__':
with open(args.cfg, 'r') as f:
cfg = yaml.safe_load(f)
# prepend PYTHONPATH to each path
prepend_pythonpath(cfg)
# Instantiate benchmarking
# Instantiate benchmark
benchmark = Benchmark(**cfg['Benchmark'])
# Instantiate model
model = build_from_cfg(cfg=cfg['Model'], registery=MODELS, key='name')
# Run benchmarking
print('Benchmarking {}:'.format(model.name))
benchmark.run(model)
benchmark.printResults()
model_config = cfg['Model']
model_handler, model_paths = MODELS.get(model_config.pop('name'))
_model_paths = []
if args.fp32 or args.fp16 or args.int8:
if args.fp32:
_model_paths += model_paths['fp32']
if args.fp16:
_model_paths += model_paths['fp16']
if args.int8:
_model_paths += model_paths['int8']
else:
_model_paths = model_paths['fp32'] + model_paths['fp16'] + model_paths['int8']
for model_path in _model_paths:
model = model_handler(*model_path, **model_config)
# Format model_path
for i in range(len(model_path)):
model_path[i] = model_path[i].split('/')[-1]
print('Benchmarking {} with {}'.format(model.name, model_path))
# Run benchmark
benchmark.run(model)
benchmark.printResults()
......@@ -2,7 +2,7 @@ Benchmark:
name: "Face Detection Benchmark"
type: "Detection"
data:
path: "benchmark/data/face_detection"
path: "data/face_detection"
files: ["group.jpg", "concerts.jpg", "dance.jpg"]
sizes: # [[w1, h1], ...], Omit to run at original scale
- [160, 120]
......@@ -16,8 +16,6 @@ Benchmark:
Model:
name: "YuNet"
modelPath: "models/face_detection_yunet/face_detection_yunet_2022mar.onnx"
confThreshold: 0.6
nmsThreshold: 0.3
topK: 5000
......@@ -2,7 +2,7 @@ Benchmark:
name: "Face Recognition Benchmark"
type: "Recognition"
data:
path: "benchmark/data/face_recognition"
path: "data/face_recognition"
files: ["Aaron_Tippin_0001.jpg", "Alvaro_Uribe_0028.jpg", "Alvaro_Uribe_0029.jpg", "Jose_Luis_Rodriguez_Zapatero_0001.jpg"]
metric: # 'sizes' is omitted since this model requires input of fixed size
warmup: 30
......@@ -13,4 +13,3 @@ Benchmark:
Model:
name: "SFace"
modelPath: "models/face_recognition_sface/face_recognition_sface_2021dec.onnx"
\ No newline at end of file
......@@ -2,7 +2,7 @@ Benchmark:
name: "Facial Expression Recognition Benchmark"
type: "Recognition"
data:
path: "benchmark/data/facial_expression_recognition/fer_evaluation"
path: "data/facial_expression_recognition/fer_evaluation"
files: ["RAF_test_0_61.jpg", "RAF_test_0_30.jpg", "RAF_test_6_25.jpg"]
metric: # 'sizes' is omitted since this model requires input of fixed size
warmup: 30
......@@ -13,4 +13,3 @@ Benchmark:
Model:
name: "FacialExpressionRecog"
modelPath: "models/facial_expression_recognition/facial_expression_recognition_mobilefacenet_2022july.onnx"
......@@ -2,7 +2,7 @@ Benchmark:
name: "Hand Pose Estimation Benchmark"
type: "Recognition"
data:
path: "benchmark/data/palm_detection"
path: "data/palm_detection_20230125"
files: ["palm1.jpg", "palm2.jpg", "palm3.jpg"]
sizes: # [[w1, h1], ...], Omit to run at original scale
- [256, 256]
......@@ -15,5 +15,4 @@ Benchmark:
Model:
name: "MPHandPose"
modelPath: "models/handpose_estimation_mediapipe/handpose_estimation_mediapipe_2022may.onnx"
confThreshold: 0.9
......@@ -2,7 +2,7 @@ Benchmark:
name: "Human Segmentation Benchmark"
type: "Base"
data:
path: "benchmark/data/human_segmentation"
path: "data/human_segmentation"
files: ["messi5.jpg", "100040721_1.jpg", "detect.jpg"]
sizes: [[192, 192]]
toRGB: True
......@@ -15,4 +15,3 @@ Benchmark:
Model:
name: "PPHumanSeg"
modelPath: "models/human_segmentation_pphumanseg/human_segmentation_pphumanseg_2021oct.onnx"
\ No newline at end of file
......@@ -2,7 +2,7 @@ Benchmark:
name: "Image Classification Benchmark"
type: "Classification"
data:
path: "benchmark/data/image_classification"
path: "data/image_classification"
files: ["coffee_mug.jpg", "umbrella.jpg", "wall_clock.jpg"]
sizes: [[256, 256]]
toRGB: True
......@@ -15,6 +15,4 @@ Benchmark:
target: "cpu"
Model:
name: "MobileNetV1"
modelPath: "models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr.onnx"
name: "MobileNet"
Benchmark:
name: "Image Classification Benchmark"
type: "Classification"
data:
path: "benchmark/data/image_classification"
files: ["coffee_mug.jpg", "umbrella.jpg", "wall_clock.jpg"]
sizes: [[256, 256]]
toRGB: True
centerCrop: 224
metric:
warmup: 30
repeat: 10
reduction: "median"
backend: "default"
target: "cpu"
Model:
name: "MobileNetV2"
modelPath: "models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr.onnx"
......@@ -2,7 +2,7 @@ Benchmark:
name: "Image Classification Benchmark"
type: "Classification"
data:
path: "benchmark/data/image_classification"
path: "data/image_classification"
files: ["coffee_mug.jpg", "umbrella.jpg", "wall_clock.jpg"]
sizes: [[256, 256]]
toRGB: True
......@@ -16,5 +16,3 @@ Benchmark:
Model:
name: "PPResNet"
modelPath: "models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx"
......@@ -2,7 +2,7 @@ Benchmark:
name: "License Plate Detection Benchmark"
type: "Detection"
data:
path: "benchmark/data/license_plate_detection"
path: "data/license_plate_detection"
files: ["1.jpg", "2.jpg", "3.jpg", "4.jpg"]
sizes: # [[w1, h1], ...], Omit to run at original scale
- [320, 240]
......@@ -15,7 +15,6 @@ Benchmark:
Model:
name: "LPD_YuNet"
modelPath: "models/license_plate_detection_yunet/license_plate_detection_lpd_yunet_2022may.onnx"
confThreshold: 0.8
nmsThreshold: 0.3
topK: 5000
......
......@@ -2,7 +2,7 @@ Benchmark:
name: "Object Detection Benchmark"
type: "Detection"
data:
path: "benchmark/data/object_detection"
path: "data/object_detection"
files: ["1.png", "2.png", "3.png"]
sizes:
- [416, 416]
......@@ -15,7 +15,5 @@ Benchmark:
Model:
name: "NanoDet"
modelPath: "models/object_detection_nanodet/object_detection_nanodet_2022nov.onnx"
prob_threshold: 0.35
iou_threshold: 0.6
......@@ -2,7 +2,7 @@ Benchmark:
name: "Object Detection Benchmark"
type: "Detection"
data:
path: "benchmark/data/object_detection"
path: "data/object_detection"
files: ["1.png", "2.png", "3.png"]
sizes:
- [640, 640]
......@@ -15,8 +15,6 @@ Benchmark:
Model:
name: "YoloX"
modelPath: "models/object_detection_yolox/object_detection_yolox_2022nov.onnx"
confThreshold: 0.35
nmsThreshold: 0.5
objThreshold: 0.5
......@@ -3,7 +3,7 @@ Benchmark:
type: "Tracking"
data:
type: "TrackingVideoLoader"
path: "benchmark/data/object_tracking"
path: "data/object_tracking"
files: ["throw_cup.mp4"]
metric:
type: "Tracking"
......@@ -13,6 +13,3 @@ Benchmark:
Model:
name: "DaSiamRPN"
model_path: "models/object_tracking_dasiamrpn/object_tracking_dasiamrpn_model_2021nov.onnx"
kernel_cls1_path: "models/object_tracking_dasiamrpn/object_tracking_dasiamrpn_kernel_cls1_2021nov.onnx"
kernel_r1_path: "models/object_tracking_dasiamrpn/object_tracking_dasiamrpn_kernel_r1_2021nov.onnx"
\ No newline at end of file
......@@ -2,7 +2,7 @@ Benchmark:
name: "Palm Detection Benchmark"
type: "Detection"
data:
path: "benchmark/data/palm_detection"
path: "data/palm_detection_20230125"
files: ["palm1.jpg", "palm2.jpg", "palm3.jpg"]
sizes: # [[w1, h1], ...], Omit to run at original scale
- [256, 256]
......@@ -15,8 +15,6 @@ Benchmark:
Model:
name: "MPPalmDet"
modelPath: "models/palm_detection_mediapipe/palm_detection_mediapipe_2022may.onnx"
scoreThreshold: 0.5
nmsThreshold: 0.3
topK: 1
......@@ -2,7 +2,7 @@ Benchmark:
name: "Person ReID Benchmark"
type: "Base"
data:
path: "benchmark/data/person_reid"
path: "data/person_reid"
files: ["0030_c1_f0056923.jpg", "0042_c5_f0068994.jpg", "0056_c8_f0017063.jpg"]
sizes: [[128, 256]]
metric:
......@@ -14,4 +14,3 @@ Benchmark:
Model:
name: "YoutuReID"
modelPath: "models/person_reid_youtureid/person_reid_youtu_2021nov.onnx"
\ No newline at end of file
......@@ -2,7 +2,7 @@ Benchmark:
name: "QRCode Detection and Decoding Benchmark"
type: "Detection"
data:
path: "benchmark/data/qrcode"
path: "data/qrcode"
files: ["opencv.png", "opencv_zoo.png"]
sizes:
- [100, 100]
......@@ -16,7 +16,3 @@ Benchmark:
Model:
name: "WeChatQRCode"
detect_prototxt_path: "models/qrcode_wechatqrcode/detect_2021nov.prototxt"
detect_model_path: "models/qrcode_wechatqrcode/detect_2021nov.caffemodel"
sr_prototxt_path: "models/qrcode_wechatqrcode/sr_2021nov.prototxt"
sr_model_path: "models/qrcode_wechatqrcode/sr_2021nov.caffemodel"
\ No newline at end of file
......@@ -2,7 +2,7 @@ Benchmark:
name: "Text Detection Benchmark"
type: "Detection"
data:
path: "benchmark/data/text"
path: "data/text"
files: ["1.jpg", "2.jpg", "3.jpg"]
sizes: # [[w1, h1], ...], Omit to run at original scale
- [640, 480]
......@@ -15,8 +15,7 @@ Benchmark:
Model:
name: "DB"
modelPath: "models/text_detection_db/text_detection_DB_TD500_resnet18_2021sep.onnx"
binaryThreshold: 0.3
polygonThreshold: 0.5
maxCandidates: 200
unclipRatio: 2.0
\ No newline at end of file
unclipRatio: 2.0
......@@ -2,7 +2,7 @@ Benchmark:
name: "Text Recognition Benchmark"
type: "Recognition"
data:
path: "benchmark/data/text"
path: "data/text"
files: ["1.jpg", "2.jpg", "3.jpg"]
metric: # 'sizes' is omitted since this model requires input of fixed size
warmup: 30
......@@ -13,5 +13,3 @@ Benchmark:
Model:
name: "CRNN"
modelPath: "models/text_recognition_crnn/text_recognition_CRNN_EN_2021sep.onnx"
charsetPath: "models/text_recognition_crnn/charset_36_EN.txt"
\ No newline at end of file
Benchmark:
name: "Text Recognition Benchmark"
type: "Recognition"
data:
path: "benchmark/data/text"
files: ["1.jpg", "2.jpg", "3.jpg"]
metric: # 'sizes' is omitted since this model requires input of fixed size
warmup: 30
repeat: 10
reduction: "median"
backend: "default"
target: "cpu"
Model:
name: "CRNN"
modelPath: "models/text_recognition_crnn/text_recognition_CRNN_CN_2021nov.onnx"
charsetPath: "models/text_recognition_crnn/charset_3944_CN.txt"
\ No newline at end of file
......@@ -202,9 +202,9 @@ data_downloaders = dict(
sha='5b741fbf34c1fbcf59cad8f2a65327a5899e66f1',
filename='person_reid.zip'),
palm_detection=Downloader(name='palm_detection',
url='https://drive.google.com/u/0/uc?id=1zYnOsXxYXn-hFIdyIws9louzqjpt8byQ&export=download',
sha='78ed095b685a9bacdd643782716127afe936f366',
filename='palm_detection_20220826.zip'),
url='https://drive.google.com/u/0/uc?id=1Z4KvccTZPeZ0qFLZ6saBt_TvcKYyo9JE&export=download',
sha='4b5bb24a51daab8913957e60245a4eb766c8cf2e',
filename='palm_detection_20230125.zip'),
license_plate_detection=Downloader(name='license_plate_detection',
url='https://drive.google.com/u/0/uc?id=1cf9MEyUqMMy8lLeDGd1any6tM_SsSmny&export=download',
sha='997acb143ddc4531e6e41365fb7ad4722064564c',
......
from pathlib import Path
import glob
import os
from .face_detection_yunet.yunet import YuNet
from .text_detection_db.db import DB
from .text_recognition_crnn.crnn import CRNN
......@@ -7,8 +11,7 @@ from .human_segmentation_pphumanseg.pphumanseg import PPHumanSeg
from .qrcode_wechatqrcode.wechatqrcode import WeChatQRCode
from .object_tracking_dasiamrpn.dasiamrpn import DaSiamRPN
from .person_reid_youtureid.youtureid import YoutuReID
from .image_classification_mobilenet.mobilenet_v1 import MobileNetV1
from .image_classification_mobilenet.mobilenet_v2 import MobileNetV2
from .image_classification_mobilenet.mobilenet import MobileNet
from .palm_detection_mediapipe.mp_palmdet import MPPalmDet
from .handpose_estimation_mediapipe.mp_handpose import MPHandPose
from .license_plate_detection_yunet.lpd_yunet import LPD_YuNet
......@@ -16,18 +19,61 @@ from .object_detection_nanodet.nanodet import NanoDet
from .object_detection_yolox.yolox import YoloX
from .facial_expression_recognition.facial_fer_model import FacialExpressionRecog
class Registery:
class ModuleRegistery:
def __init__(self, name):
self._name = name
self._dict = dict()
self._base_path = Path(__file__).parent
def get(self, key):
'''
Returns a tuple with:
- a module handler,
- a list of model file paths
'''
return self._dict[key]
def register(self, item):
self._dict[item.__name__] = item
'''
Registers given module handler along with paths of model files
'''
# search for model files
model_dir = str(self._base_path / item.__module__.split(".")[1])
fp32_model_paths = []
fp16_model_paths = []
int8_model_paths = []
# onnx
ret_onnx = sorted(glob.glob(os.path.join(model_dir, "*.onnx")))
if "object_tracking" in item.__module__:
# object tracking models usually have multiple parts
fp32_model_paths = [ret_onnx]
else:
for r in ret_onnx:
if "int8" in r:
int8_model_paths.append([r])
elif "fp16" in r: # exclude fp16 for now
fp16_model_paths.append([r])
else:
fp32_model_paths.append([r])
# caffe
ret_caffemodel = sorted(glob.glob(os.path.join(model_dir, "*.caffemodel")))
ret_prototxt = sorted(glob.glob(os.path.join(model_dir, "*.prototxt")))
caffe_models = []
for caffemodel, prototxt in zip(ret_caffemodel, ret_prototxt):
caffe_models += [prototxt, caffemodel]
if caffe_models:
fp32_model_paths.append(caffe_models)
all_model_paths = dict(
fp32=fp32_model_paths,
fp16=fp16_model_paths,
int8=int8_model_paths,
)
self._dict[item.__name__] = (item, all_model_paths)
MODELS = Registery('Models')
MODELS = ModuleRegistery('Models')
MODELS.register(YuNet)
MODELS.register(DB)
MODELS.register(CRNN)
......@@ -37,8 +83,7 @@ MODELS.register(PPHumanSeg)
MODELS.register(WeChatQRCode)
MODELS.register(DaSiamRPN)
MODELS.register(YoutuReID)
MODELS.register(MobileNetV1)
MODELS.register(MobileNetV2)
MODELS.register(MobileNet)
MODELS.register(MPPalmDet)
MODELS.register(MPHandPose)
MODELS.register(LPD_YuNet)
......
......@@ -3,8 +3,7 @@ import argparse
import numpy as np
import cv2 as cv
from mobilenet_v1 import MobileNetV1
from mobilenet_v2 import MobileNetV2
from mobilenet import MobileNet
def str2bool(v):
if v.lower() in ['on', 'yes', 'true', 'y', 't']:
......@@ -26,24 +25,23 @@ try:
except:
print('This version of OpenCV does not support TIM-VX and NPU. Visit https://github.com/opencv/opencv/wiki/TIM-VX-Backend-For-Running-OpenCV-On-NPU for more information.')
all_mobilenets = [
'image_classification_mobilenetv1_2022apr.onnx',
'image_classification_mobilenetv2_2022apr.onnx',
'image_classification_mobilenetv1_2022apr-int8-quantized.onnx',
'image_classification_mobilenetv2_2022apr-int8-quantized.onnx'
]
parser = argparse.ArgumentParser(description='Demo for MobileNet V1 & V2.')
parser.add_argument('--input', '-i', type=str, help='Usage: Set input path to a certain image, omit if using camera.')
parser.add_argument('--model', '-m', type=str, choices=['v1', 'v2', 'v1-q', 'v2-q'], default='v1', help='Usage: Set model type, defaults to image_classification_mobilenetv1_2022apr.onnx (v1).')
parser.add_argument('--model', '-m', type=str, choices=all_mobilenets, default=all_mobilenets[0], help='Usage: Set model type, defaults to image_classification_mobilenetv1_2022apr.onnx (v1).')
parser.add_argument('--backend', '-b', type=int, default=backends[0], help=help_msg_backends.format(*backends))
parser.add_argument('--target', '-t', type=int, default=targets[0], help=help_msg_targets.format(*targets))
parser.add_argument('--label', '-l', type=str, default='./imagenet_labels.txt', help='Usage: Set path to the different labels that will be used during the detection. Default list found in imagenet_labels.txt')
args = parser.parse_args()
if __name__ == '__main__':
# Instantiate ResNet
models = {
'v1': MobileNetV1(modelPath='./image_classification_mobilenetv1_2022apr.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target),
'v2': MobileNetV2(modelPath='./image_classification_mobilenetv2_2022apr.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target),
'v1-q': MobileNetV1(modelPath='./image_classification_mobilenetv1_2022apr-int8-quantized.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target),
'v2-q': MobileNetV2(modelPath='./image_classification_mobilenetv2_2022apr-int8-quantized.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target)
}
model = models[args.model]
# Instantiate MobileNet
model = MobileNet(modelPath=args.model, backendId=args.backend, targetId=args.target)
# Read image and get a 224x224 crop from a 256x256 resized
image = cv.imread(args.input)
......@@ -56,4 +54,3 @@ if __name__ == '__main__':
# Print result
print('label: {}'.format(result))
tench
import numpy as np
import cv2 as cv
class MobileNet:
'''
Works with MobileNet V1 & V2.
'''
def __init__(self, modelPath, topK=1, backendId=0, targetId=0):
self.model_path = modelPath
assert topK >= 1
self.top_k = topK
self.backend_id = backendId
self.target_id = targetId
self.model = cv.dnn.readNet(self.model_path)
self.model.setPreferableBackend(self.backend_id)
self.model.setPreferableTarget(self.target_id)
self.input_names = ''
self.output_names = ''
self.input_size = [224, 224]
self.mean=[0.485, 0.456, 0.406]
self.std=[0.229, 0.224, 0.225]
# load labels
self._labels = self._load_labels()
def _load_labels(self):
return self.LABELS_IMAGENET_1K.splitlines()
@property
def name(self):
return self.__class__.__name__
def setBackend(self, backendId):
self.backend_id = backendId
self.model.setPreferableBackend(self.backend_id)
def setTarget(self, targetId):
self.target_id = targetId
self.model.setPreferableTarget(self.target_id)
def _preprocess(self, image):
input_blob = (image / 255.0 - self.mean) / self.std
input_blob = input_blob.transpose(2, 0, 1)
input_blob = input_blob[np.newaxis, :, :, :]
input_blob = input_blob.astype(np.float32)
return input_blob
def infer(self, image):
# Preprocess
input_blob = self._preprocess(image)
# Forward
self.model.setInput(input_blob, self.input_names)
output_blob = self.model.forward(self.output_names)
# Postprocess
results = self._postprocess(output_blob)
return results
def _postprocess(self, output_blob):
batched_class_id_list = []
for o in output_blob:
class_id_list = o.argsort()[::-1][:self.top_k]
batched_class_id_list.append(class_id_list)
if len(self._labels) > 0:
batched_predicted_labels = []
for class_id_list in batched_class_id_list:
predicted_labels = []
for class_id in class_id_list:
predicted_labels.append(self._labels[class_id])
batched_predicted_labels.append(predicted_labels)
return batched_predicted_labels
else:
return batched_class_id_list
LABELS_IMAGENET_1K = '''tench
goldfish
great white shark
tiger shark
......@@ -997,4 +1076,4 @@ earthstar
hen-of-the-woods
bolete
ear
toilet tissue
toilet tissue'''
import numpy as np
import cv2 as cv
class MobileNetV1:
def __init__(self, modelPath, labelPath=None, topK=1, backendId=0, targetId=0):
self.model_path = modelPath
self.label_path = labelPath
assert topK >= 1
self.top_k = topK
self.backend_id = backendId
self.target_id = targetId
self.model = cv.dnn.readNet(self.model_path)
self.model.setPreferableBackend(self.backend_id)
self.model.setPreferableTarget(self.target_id)
self.input_names = ''
self.output_names = ''
self.input_size = [224, 224]
self.mean=[0.485, 0.456, 0.406]
self.std=[0.229, 0.224, 0.225]
# load labels
self._labels = self._load_labels()
def _load_labels(self):
labels = []
if self.label_path is not None:
with open(self.label_path, 'r') as f:
for line in f:
labels.append(line.strip())
return labels
@property
def name(self):
return self.__class__.__name__
def setBackend(self, backendId):
self.backend_id = backendId
self.model.setPreferableBackend(self.backend_id)
def setTarget(self, targetId):
self.target_id = targetId
self.model.setPreferableTarget(self.target_id)
def _preprocess(self, image):
input_blob = (image / 255.0 - self.mean) / self.std
input_blob = input_blob.transpose(2, 0, 1)
input_blob = input_blob[np.newaxis, :, :, :]
input_blob = input_blob.astype(np.float32)
return input_blob
def infer(self, image):
# Preprocess
input_blob = self._preprocess(image)
# Forward
self.model.setInput(input_blob, self.input_names)
output_blob = self.model.forward(self.output_names)
# Postprocess
results = self._postprocess(output_blob)
return results
def _postprocess(self, output_blob):
batched_class_id_list = []
for o in output_blob:
class_id_list = o.argsort()[::-1][:self.top_k]
batched_class_id_list.append(class_id_list)
if len(self._labels) > 0:
batched_predicted_labels = []
for class_id_list in batched_class_id_list:
predicted_labels = []
for class_id in class_id_list:
predicted_labels.append(self._labels[class_id])
batched_predicted_labels.append(predicted_labels)
return batched_predicted_labels
else:
return batched_class_id_list
import numpy as np
import cv2 as cv
class MobileNetV2:
def __init__(self, modelPath, labelPath=None, topK=1, backendId=0, targetId=0):
self.model_path = modelPath
self.label_path = labelPath
assert topK >= 1
self.top_k = topK
self.backend_id = backendId
self.target_id = targetId
self.model = cv.dnn.readNet(self.model_path)
self.model.setPreferableBackend(self.backend_id)
self.model.setPreferableTarget(self.target_id)
self.input_names = ''
self.output_names = ''
self.input_size = [224, 224]
self.mean=[0.485, 0.456, 0.406]
self.std=[0.229, 0.224, 0.225]
# load labels
self._labels = self._load_labels()
def _load_labels(self):
labels = []
if self.label_path is not None:
with open(self.label_path, 'r') as f:
for line in f:
labels.append(line.strip())
return labels
@property
def name(self):
return self.__class__.__name__
def setBackend(self, backendId):
self.backend_id = backendId
self.model.setPreferableBackend(self.backend_id)
def setTarget(self, targetId):
self.target_id = targetId
self.model.setPreferableTarget(self.target_id)
def _preprocess(self, image):
input_blob = (image / 255.0 - self.mean) / self.std
input_blob = input_blob.transpose(2, 0, 1)
input_blob = input_blob[np.newaxis, :, :, :]
input_blob = input_blob.astype(np.float32)
return input_blob
def infer(self, image):
# Preprocess
input_blob = self._preprocess(image)
# Forward
self.model.setInput(input_blob, self.input_names)
output_blob = self.model.forward(self.output_names)
# Postprocess
results = self._postprocess(output_blob)
return results
def _postprocess(self, output_blob):
batched_class_id_list = []
for o in output_blob:
class_id_list = o.argsort()[::-1][:self.top_k]
batched_class_id_list.append(class_id_list)
if len(self._labels) > 0:
batched_predicted_labels = []
for class_id_list in batched_class_id_list:
predicted_labels = []
for class_id in class_id_list:
predicted_labels.append(self._labels[class_id])
batched_predicted_labels.append(predicted_labels)
return batched_predicted_labels
else:
return batched_class_id_list
......@@ -36,12 +36,11 @@ parser.add_argument('--input', '-i', type=str, help='Usage: Set input path to a
parser.add_argument('--model', '-m', type=str, default='image_classification_ppresnet50_2022jan.onnx', help='Usage: Set model path, defaults to image_classification_ppresnet50_2022jan.onnx.')
parser.add_argument('--backend', '-b', type=int, default=backends[0], help=help_msg_backends.format(*backends))
parser.add_argument('--target', '-t', type=int, default=targets[0], help=help_msg_targets.format(*targets))
parser.add_argument('--label', '-l', type=str, default='./imagenet_labels.txt', help='Usage: Set path to the different labels that will be used during the detection. Default list found in imagenet_labels.txt')
args = parser.parse_args()
if __name__ == '__main__':
# Instantiate ResNet
model = PPResNet(modelPath=args.model, labelPath=args.label, backendId=args.backend, targetId=args.target)
model = PPResNet(modelPath=args.model, backendId=args.backend, targetId=args.target)
# Read image and get a 224x224 crop from a 256x256 resized
image = cv.imread(args.input)
......@@ -54,4 +53,3 @@ if __name__ == '__main__':
# Print result
print('label: {}'.format(result))
tench
goldfish
great white shark
tiger shark
hammerhead
electric ray
stingray
cock
hen
ostrich
brambling
goldfinch
house finch
junco
indigo bunting
robin
bulbul
jay
magpie
chickadee
water ouzel
kite
bald eagle
vulture
great grey owl
European fire salamander
common newt
eft
spotted salamander
axolotl
bullfrog
tree frog
tailed frog
loggerhead
leatherback turtle
mud turtle
terrapin
box turtle
banded gecko
common iguana
American chameleon
whiptail
agama
frilled lizard
alligator lizard
Gila monster
green lizard
African chameleon
Komodo dragon
African crocodile
American alligator
triceratops
thunder snake
ringneck snake
hognose snake
green snake
king snake
garter snake
water snake
vine snake
night snake
boa constrictor
rock python
Indian cobra
green mamba
sea snake
horned viper
diamondback
sidewinder
trilobite
harvestman
scorpion
black and gold garden spider
barn spider
garden spider
black widow
tarantula
wolf spider
tick
centipede
black grouse
ptarmigan
ruffed grouse
prairie chicken
peacock
quail
partridge
African grey
macaw
sulphur-crested cockatoo
lorikeet
coucal
bee eater
hornbill
hummingbird
jacamar
toucan
drake
red-breasted merganser
goose
black swan
tusker
echidna
platypus
wallaby
koala
wombat
jellyfish
sea anemone
brain coral
flatworm
nematode
conch
snail
slug
sea slug
chiton
chambered nautilus
Dungeness crab
rock crab
fiddler crab
king crab
American lobster
spiny lobster
crayfish
hermit crab
isopod
white stork
black stork
spoonbill
flamingo
little blue heron
American egret
bittern
crane
limpkin
European gallinule
American coot
bustard
ruddy turnstone
red-backed sandpiper
redshank
dowitcher
oystercatcher
pelican
king penguin
albatross
grey whale
killer whale
dugong
sea lion
Chihuahua
Japanese spaniel
Maltese dog
Pekinese
Shih-Tzu
Blenheim spaniel
papillon
toy terrier
Rhodesian ridgeback
Afghan hound
basset
beagle
bloodhound
bluetick
black-and-tan coonhound
Walker hound
English foxhound
redbone
borzoi
Irish wolfhound
Italian greyhound
whippet
Ibizan hound
Norwegian elkhound
otterhound
Saluki
Scottish deerhound
Weimaraner
Staffordshire bullterrier
American Staffordshire terrier
Bedlington terrier
Border terrier
Kerry blue terrier
Irish terrier
Norfolk terrier
Norwich terrier
Yorkshire terrier
wire-haired fox terrier
Lakeland terrier
Sealyham terrier
Airedale
cairn
Australian terrier
Dandie Dinmont
Boston bull
miniature schnauzer
giant schnauzer
standard schnauzer
Scotch terrier
Tibetan terrier
silky terrier
soft-coated wheaten terrier
West Highland white terrier
Lhasa
flat-coated retriever
curly-coated retriever
golden retriever
Labrador retriever
Chesapeake Bay retriever
German short-haired pointer
vizsla
English setter
Irish setter
Gordon setter
Brittany spaniel
clumber
English springer
Welsh springer spaniel
cocker spaniel
Sussex spaniel
Irish water spaniel
kuvasz
schipperke
groenendael
malinois
briard
kelpie
komondor
Old English sheepdog
Shetland sheepdog
collie
Border collie
Bouvier des Flandres
Rottweiler
German shepherd
Doberman
miniature pinscher
Greater Swiss Mountain dog
Bernese mountain dog
Appenzeller
EntleBucher
boxer
bull mastiff
Tibetan mastiff
French bulldog
Great Dane
Saint Bernard
Eskimo dog
malamute
Siberian husky
dalmatian
affenpinscher
basenji
pug
Leonberg
Newfoundland
Great Pyrenees
Samoyed
Pomeranian
chow
keeshond
Brabancon griffon
Pembroke
Cardigan
toy poodle
miniature poodle
standard poodle
Mexican hairless
timber wolf
white wolf
red wolf
coyote
dingo
dhole
African hunting dog
hyena
red fox
kit fox
Arctic fox
grey fox
tabby
tiger cat
Persian cat
Siamese cat
Egyptian cat
cougar
lynx
leopard
snow leopard
jaguar
lion
tiger
cheetah
brown bear
American black bear
ice bear
sloth bear
mongoose
meerkat
tiger beetle
ladybug
ground beetle
long-horned beetle
leaf beetle
dung beetle
rhinoceros beetle
weevil
fly
bee
ant
grasshopper
cricket
walking stick
cockroach
mantis
cicada
leafhopper
lacewing
dragonfly
damselfly
admiral
ringlet
monarch
cabbage butterfly
sulphur butterfly
lycaenid
starfish
sea urchin
sea cucumber
wood rabbit
hare
Angora
hamster
porcupine
fox squirrel
marmot
beaver
guinea pig
sorrel
zebra
hog
wild boar
warthog
hippopotamus
ox
water buffalo
bison
ram
bighorn
ibex
hartebeest
impala
gazelle
Arabian camel
llama
weasel
mink
polecat
black-footed ferret
otter
skunk
badger
armadillo
three-toed sloth
orangutan
gorilla
chimpanzee
gibbon
siamang
guenon
patas
baboon
macaque
langur
colobus
proboscis monkey
marmoset
capuchin
howler monkey
titi
spider monkey
squirrel monkey
Madagascar cat
indri
Indian elephant
African elephant
lesser panda
giant panda
barracouta
eel
coho
rock beauty
anemone fish
sturgeon
gar
lionfish
puffer
abacus
abaya
academic gown
accordion
acoustic guitar
aircraft carrier
airliner
airship
altar
ambulance
amphibian
analog clock
apiary
apron
ashcan
assault rifle
backpack
bakery
balance beam
balloon
ballpoint
Band Aid
banjo
bannister
barbell
barber chair
barbershop
barn
barometer
barrel
barrow
baseball
basketball
bassinet
bassoon
bathing cap
bath towel
bathtub
beach wagon
beacon
beaker
bearskin
beer bottle
beer glass
bell cote
bib
bicycle-built-for-two
bikini
binder
binoculars
birdhouse
boathouse
bobsled
bolo tie
bonnet
bookcase
bookshop
bottlecap
bow
bow tie
brass
brassiere
breakwater
breastplate
broom
bucket
buckle
bulletproof vest
bullet train
butcher shop
cab
caldron
candle
cannon
canoe
can opener
cardigan
car mirror
carousel
carpenters kit
carton
car wheel
cash machine
cassette
cassette player
castle
catamaran
CD player
cello
cellular telephone
chain
chainlink fence
chain mail
chain saw
chest
chiffonier
chime
china cabinet
Christmas stocking
church
cinema
cleaver
cliff dwelling
cloak
clog
cocktail shaker
coffee mug
coffeepot
coil
combination lock
computer keyboard
confectionery
container ship
convertible
corkscrew
cornet
cowboy boot
cowboy hat
cradle
crane
crash helmet
crate
crib
Crock Pot
croquet ball
crutch
cuirass
dam
desk
desktop computer
dial telephone
diaper
digital clock
digital watch
dining table
dishrag
dishwasher
disk brake
dock
dogsled
dome
doormat
drilling platform
drum
drumstick
dumbbell
Dutch oven
electric fan
electric guitar
electric locomotive
entertainment center
envelope
espresso maker
face powder
feather boa
file
fireboat
fire engine
fire screen
flagpole
flute
folding chair
football helmet
forklift
fountain
fountain pen
four-poster
freight car
French horn
frying pan
fur coat
garbage truck
gasmask
gas pump
goblet
go-kart
golf ball
golfcart
gondola
gong
gown
grand piano
greenhouse
grille
grocery store
guillotine
hair slide
hair spray
half track
hammer
hamper
hand blower
hand-held computer
handkerchief
hard disc
harmonica
harp
harvester
hatchet
holster
home theater
honeycomb
hook
hoopskirt
horizontal bar
horse cart
hourglass
iPod
iron
jack-o-lantern
jean
jeep
jersey
jigsaw puzzle
jinrikisha
joystick
kimono
knee pad
knot
lab coat
ladle
lampshade
laptop
lawn mower
lens cap
letter opener
library
lifeboat
lighter
limousine
liner
lipstick
Loafer
lotion
loudspeaker
loupe
lumbermill
magnetic compass
mailbag
mailbox
maillot
maillot
manhole cover
maraca
marimba
mask
matchstick
maypole
maze
measuring cup
medicine chest
megalith
microphone
microwave
military uniform
milk can
minibus
miniskirt
minivan
missile
mitten
mixing bowl
mobile home
Model T
modem
monastery
monitor
moped
mortar
mortarboard
mosque
mosquito net
motor scooter
mountain bike
mountain tent
mouse
mousetrap
moving van
muzzle
nail
neck brace
necklace
nipple
notebook
obelisk
oboe
ocarina
odometer
oil filter
organ
oscilloscope
overskirt
oxcart
oxygen mask
packet
paddle
paddlewheel
padlock
paintbrush
pajama
palace
panpipe
paper towel
parachute
parallel bars
park bench
parking meter
passenger car
patio
pay-phone
pedestal
pencil box
pencil sharpener
perfume
Petri dish
photocopier
pick
pickelhaube
picket fence
pickup
pier
piggy bank
pill bottle
pillow
ping-pong ball
pinwheel
pirate
pitcher
plane
planetarium
plastic bag
plate rack
plow
plunger
Polaroid camera
pole
police van
poncho
pool table
pop bottle
pot
potters wheel
power drill
prayer rug
printer
prison
projectile
projector
puck
punching bag
purse
quill
quilt
racer
racket
radiator
radio
radio telescope
rain barrel
recreational vehicle
reel
reflex camera
refrigerator
remote control
restaurant
revolver
rifle
rocking chair
rotisserie
rubber eraser
rugby ball
rule
running shoe
safe
safety pin
saltshaker
sandal
sarong
sax
scabbard
scale
school bus
schooner
scoreboard
screen
screw
screwdriver
seat belt
sewing machine
shield
shoe shop
shoji
shopping basket
shopping cart
shovel
shower cap
shower curtain
ski
ski mask
sleeping bag
slide rule
sliding door
slot
snorkel
snowmobile
snowplow
soap dispenser
soccer ball
sock
solar dish
sombrero
soup bowl
space bar
space heater
space shuttle
spatula
speedboat
spider web
spindle
sports car
spotlight
stage
steam locomotive
steel arch bridge
steel drum
stethoscope
stole
stone wall
stopwatch
stove
strainer
streetcar
stretcher
studio couch
stupa
submarine
suit
sundial
sunglass
sunglasses
sunscreen
suspension bridge
swab
sweatshirt
swimming trunks
swing
switch
syringe
table lamp
tank
tape player
teapot
teddy
television
tennis ball
thatch
theater curtain
thimble
thresher
throne
tile roof
toaster
tobacco shop
toilet seat
torch
totem pole
tow truck
toyshop
tractor
trailer truck
tray
trench coat
tricycle
trimaran
tripod
triumphal arch
trolleybus
trombone
tub
turnstile
typewriter keyboard
umbrella
unicycle
upright
vacuum
vase
vault
velvet
vending machine
vestment
viaduct
violin
volleyball
waffle iron
wall clock
wallet
wardrobe
warplane
washbasin
washer
water bottle
water jug
water tower
whiskey jug
whistle
wig
window screen
window shade
Windsor tie
wine bottle
wing
wok
wooden spoon
wool
worm fence
wreck
yawl
yurt
web site
comic book
crossword puzzle
street sign
traffic light
book jacket
menu
plate
guacamole
consomme
hot pot
trifle
ice cream
ice lolly
French loaf
bagel
pretzel
cheeseburger
hotdog
mashed potato
head cabbage
broccoli
cauliflower
zucchini
spaghetti squash
acorn squash
butternut squash
cucumber
artichoke
bell pepper
cardoon
mushroom
Granny Smith
strawberry
orange
lemon
fig
pineapple
banana
jackfruit
custard apple
pomegranate
hay
carbonara
chocolate sauce
dough
meat loaf
pizza
potpie
burrito
red wine
espresso
cup
eggnog
alp
bubble
cliff
coral reef
geyser
lakeside
promontory
sandbar
seashore
valley
volcano
ballplayer
groom
scuba diver
rapeseed
daisy
yellow ladys slipper
corn
acorn
hip
buckeye
coral fungus
agaric
gyromitra
stinkhorn
earthstar
hen-of-the-woods
bolete
ear
toilet tissue
......@@ -9,9 +9,8 @@ import numpy as np
import cv2 as cv
class PPResNet:
def __init__(self, modelPath, labelPath=None, topK=1, backendId=0, targetId=0):
def __init__(self, modelPath, topK=1, backendId=0, targetId=0):
self._modelPath = modelPath
self._labelPath = labelPath
assert topK >= 1
self._topK = topK
self._backendId = backendId
......@@ -31,12 +30,7 @@ class PPResNet:
self._labels = self._load_labels()
def _load_labels(self):
labels = []
if self._labelPath is not None:
with open(self._labelPath, 'r') as f:
for line in f:
labels.append(line.strip())
return labels
return self.LABELS_IMAGENET_1K.splitlines()
@property
def name(self):
......@@ -88,3 +82,1003 @@ class PPResNet:
else:
return batched_class_id_list
LABELS_IMAGENET_1K = '''tench
goldfish
great white shark
tiger shark
hammerhead
electric ray
stingray
cock
hen
ostrich
brambling
goldfinch
house finch
junco
indigo bunting
robin
bulbul
jay
magpie
chickadee
water ouzel
kite
bald eagle
vulture
great grey owl
European fire salamander
common newt
eft
spotted salamander
axolotl
bullfrog
tree frog
tailed frog
loggerhead
leatherback turtle
mud turtle
terrapin
box turtle
banded gecko
common iguana
American chameleon
whiptail
agama
frilled lizard
alligator lizard
Gila monster
green lizard
African chameleon
Komodo dragon
African crocodile
American alligator
triceratops
thunder snake
ringneck snake
hognose snake
green snake
king snake
garter snake
water snake
vine snake
night snake
boa constrictor
rock python
Indian cobra
green mamba
sea snake
horned viper
diamondback
sidewinder
trilobite
harvestman
scorpion
black and gold garden spider
barn spider
garden spider
black widow
tarantula
wolf spider
tick
centipede
black grouse
ptarmigan
ruffed grouse
prairie chicken
peacock
quail
partridge
African grey
macaw
sulphur-crested cockatoo
lorikeet
coucal
bee eater
hornbill
hummingbird
jacamar
toucan
drake
red-breasted merganser
goose
black swan
tusker
echidna
platypus
wallaby
koala
wombat
jellyfish
sea anemone
brain coral
flatworm
nematode
conch
snail
slug
sea slug
chiton
chambered nautilus
Dungeness crab
rock crab
fiddler crab
king crab
American lobster
spiny lobster
crayfish
hermit crab
isopod
white stork
black stork
spoonbill
flamingo
little blue heron
American egret
bittern
crane
limpkin
European gallinule
American coot
bustard
ruddy turnstone
red-backed sandpiper
redshank
dowitcher
oystercatcher
pelican
king penguin
albatross
grey whale
killer whale
dugong
sea lion
Chihuahua
Japanese spaniel
Maltese dog
Pekinese
Shih-Tzu
Blenheim spaniel
papillon
toy terrier
Rhodesian ridgeback
Afghan hound
basset
beagle
bloodhound
bluetick
black-and-tan coonhound
Walker hound
English foxhound
redbone
borzoi
Irish wolfhound
Italian greyhound
whippet
Ibizan hound
Norwegian elkhound
otterhound
Saluki
Scottish deerhound
Weimaraner
Staffordshire bullterrier
American Staffordshire terrier
Bedlington terrier
Border terrier
Kerry blue terrier
Irish terrier
Norfolk terrier
Norwich terrier
Yorkshire terrier
wire-haired fox terrier
Lakeland terrier
Sealyham terrier
Airedale
cairn
Australian terrier
Dandie Dinmont
Boston bull
miniature schnauzer
giant schnauzer
standard schnauzer
Scotch terrier
Tibetan terrier
silky terrier
soft-coated wheaten terrier
West Highland white terrier
Lhasa
flat-coated retriever
curly-coated retriever
golden retriever
Labrador retriever
Chesapeake Bay retriever
German short-haired pointer
vizsla
English setter
Irish setter
Gordon setter
Brittany spaniel
clumber
English springer
Welsh springer spaniel
cocker spaniel
Sussex spaniel
Irish water spaniel
kuvasz
schipperke
groenendael
malinois
briard
kelpie
komondor
Old English sheepdog
Shetland sheepdog
collie
Border collie
Bouvier des Flandres
Rottweiler
German shepherd
Doberman
miniature pinscher
Greater Swiss Mountain dog
Bernese mountain dog
Appenzeller
EntleBucher
boxer
bull mastiff
Tibetan mastiff
French bulldog
Great Dane
Saint Bernard
Eskimo dog
malamute
Siberian husky
dalmatian
affenpinscher
basenji
pug
Leonberg
Newfoundland
Great Pyrenees
Samoyed
Pomeranian
chow
keeshond
Brabancon griffon
Pembroke
Cardigan
toy poodle
miniature poodle
standard poodle
Mexican hairless
timber wolf
white wolf
red wolf
coyote
dingo
dhole
African hunting dog
hyena
red fox
kit fox
Arctic fox
grey fox
tabby
tiger cat
Persian cat
Siamese cat
Egyptian cat
cougar
lynx
leopard
snow leopard
jaguar
lion
tiger
cheetah
brown bear
American black bear
ice bear
sloth bear
mongoose
meerkat
tiger beetle
ladybug
ground beetle
long-horned beetle
leaf beetle
dung beetle
rhinoceros beetle
weevil
fly
bee
ant
grasshopper
cricket
walking stick
cockroach
mantis
cicada
leafhopper
lacewing
dragonfly
damselfly
admiral
ringlet
monarch
cabbage butterfly
sulphur butterfly
lycaenid
starfish
sea urchin
sea cucumber
wood rabbit
hare
Angora
hamster
porcupine
fox squirrel
marmot
beaver
guinea pig
sorrel
zebra
hog
wild boar
warthog
hippopotamus
ox
water buffalo
bison
ram
bighorn
ibex
hartebeest
impala
gazelle
Arabian camel
llama
weasel
mink
polecat
black-footed ferret
otter
skunk
badger
armadillo
three-toed sloth
orangutan
gorilla
chimpanzee
gibbon
siamang
guenon
patas
baboon
macaque
langur
colobus
proboscis monkey
marmoset
capuchin
howler monkey
titi
spider monkey
squirrel monkey
Madagascar cat
indri
Indian elephant
African elephant
lesser panda
giant panda
barracouta
eel
coho
rock beauty
anemone fish
sturgeon
gar
lionfish
puffer
abacus
abaya
academic gown
accordion
acoustic guitar
aircraft carrier
airliner
airship
altar
ambulance
amphibian
analog clock
apiary
apron
ashcan
assault rifle
backpack
bakery
balance beam
balloon
ballpoint
Band Aid
banjo
bannister
barbell
barber chair
barbershop
barn
barometer
barrel
barrow
baseball
basketball
bassinet
bassoon
bathing cap
bath towel
bathtub
beach wagon
beacon
beaker
bearskin
beer bottle
beer glass
bell cote
bib
bicycle-built-for-two
bikini
binder
binoculars
birdhouse
boathouse
bobsled
bolo tie
bonnet
bookcase
bookshop
bottlecap
bow
bow tie
brass
brassiere
breakwater
breastplate
broom
bucket
buckle
bulletproof vest
bullet train
butcher shop
cab
caldron
candle
cannon
canoe
can opener
cardigan
car mirror
carousel
carpenters kit
carton
car wheel
cash machine
cassette
cassette player
castle
catamaran
CD player
cello
cellular telephone
chain
chainlink fence
chain mail
chain saw
chest
chiffonier
chime
china cabinet
Christmas stocking
church
cinema
cleaver
cliff dwelling
cloak
clog
cocktail shaker
coffee mug
coffeepot
coil
combination lock
computer keyboard
confectionery
container ship
convertible
corkscrew
cornet
cowboy boot
cowboy hat
cradle
crane
crash helmet
crate
crib
Crock Pot
croquet ball
crutch
cuirass
dam
desk
desktop computer
dial telephone
diaper
digital clock
digital watch
dining table
dishrag
dishwasher
disk brake
dock
dogsled
dome
doormat
drilling platform
drum
drumstick
dumbbell
Dutch oven
electric fan
electric guitar
electric locomotive
entertainment center
envelope
espresso maker
face powder
feather boa
file
fireboat
fire engine
fire screen
flagpole
flute
folding chair
football helmet
forklift
fountain
fountain pen
four-poster
freight car
French horn
frying pan
fur coat
garbage truck
gasmask
gas pump
goblet
go-kart
golf ball
golfcart
gondola
gong
gown
grand piano
greenhouse
grille
grocery store
guillotine
hair slide
hair spray
half track
hammer
hamper
hand blower
hand-held computer
handkerchief
hard disc
harmonica
harp
harvester
hatchet
holster
home theater
honeycomb
hook
hoopskirt
horizontal bar
horse cart
hourglass
iPod
iron
jack-o-lantern
jean
jeep
jersey
jigsaw puzzle
jinrikisha
joystick
kimono
knee pad
knot
lab coat
ladle
lampshade
laptop
lawn mower
lens cap
letter opener
library
lifeboat
lighter
limousine
liner
lipstick
Loafer
lotion
loudspeaker
loupe
lumbermill
magnetic compass
mailbag
mailbox
maillot
maillot
manhole cover
maraca
marimba
mask
matchstick
maypole
maze
measuring cup
medicine chest
megalith
microphone
microwave
military uniform
milk can
minibus
miniskirt
minivan
missile
mitten
mixing bowl
mobile home
Model T
modem
monastery
monitor
moped
mortar
mortarboard
mosque
mosquito net
motor scooter
mountain bike
mountain tent
mouse
mousetrap
moving van
muzzle
nail
neck brace
necklace
nipple
notebook
obelisk
oboe
ocarina
odometer
oil filter
organ
oscilloscope
overskirt
oxcart
oxygen mask
packet
paddle
paddlewheel
padlock
paintbrush
pajama
palace
panpipe
paper towel
parachute
parallel bars
park bench
parking meter
passenger car
patio
pay-phone
pedestal
pencil box
pencil sharpener
perfume
Petri dish
photocopier
pick
pickelhaube
picket fence
pickup
pier
piggy bank
pill bottle
pillow
ping-pong ball
pinwheel
pirate
pitcher
plane
planetarium
plastic bag
plate rack
plow
plunger
Polaroid camera
pole
police van
poncho
pool table
pop bottle
pot
potters wheel
power drill
prayer rug
printer
prison
projectile
projector
puck
punching bag
purse
quill
quilt
racer
racket
radiator
radio
radio telescope
rain barrel
recreational vehicle
reel
reflex camera
refrigerator
remote control
restaurant
revolver
rifle
rocking chair
rotisserie
rubber eraser
rugby ball
rule
running shoe
safe
safety pin
saltshaker
sandal
sarong
sax
scabbard
scale
school bus
schooner
scoreboard
screen
screw
screwdriver
seat belt
sewing machine
shield
shoe shop
shoji
shopping basket
shopping cart
shovel
shower cap
shower curtain
ski
ski mask
sleeping bag
slide rule
sliding door
slot
snorkel
snowmobile
snowplow
soap dispenser
soccer ball
sock
solar dish
sombrero
soup bowl
space bar
space heater
space shuttle
spatula
speedboat
spider web
spindle
sports car
spotlight
stage
steam locomotive
steel arch bridge
steel drum
stethoscope
stole
stone wall
stopwatch
stove
strainer
streetcar
stretcher
studio couch
stupa
submarine
suit
sundial
sunglass
sunglasses
sunscreen
suspension bridge
swab
sweatshirt
swimming trunks
swing
switch
syringe
table lamp
tank
tape player
teapot
teddy
television
tennis ball
thatch
theater curtain
thimble
thresher
throne
tile roof
toaster
tobacco shop
toilet seat
torch
totem pole
tow truck
toyshop
tractor
trailer truck
tray
trench coat
tricycle
trimaran
tripod
triumphal arch
trolleybus
trombone
tub
turnstile
typewriter keyboard
umbrella
unicycle
upright
vacuum
vase
vault
velvet
vending machine
vestment
viaduct
violin
volleyball
waffle iron
wall clock
wallet
wardrobe
warplane
washbasin
washer
water bottle
water jug
water tower
whiskey jug
whistle
wig
window screen
window shade
Windsor tie
wine bottle
wing
wok
wooden spoon
wool
worm fence
wreck
yawl
yurt
web site
comic book
crossword puzzle
street sign
traffic light
book jacket
menu
plate
guacamole
consomme
hot pot
trifle
ice cream
ice lolly
French loaf
bagel
pretzel
cheeseburger
hotdog
mashed potato
head cabbage
broccoli
cauliflower
zucchini
spaghetti squash
acorn squash
butternut squash
cucumber
artichoke
bell pepper
cardoon
mushroom
Granny Smith
strawberry
orange
lemon
fig
pineapple
banana
jackfruit
custard apple
pomegranate
hay
carbonara
chocolate sauce
dough
meat loaf
pizza
potpie
burrito
red wine
espresso
cup
eggnog
alp
bubble
cliff
coral reef
geyser
lakeside
promontory
sandbar
seashore
valley
volcano
ballplayer
groom
scuba diver
rapeseed
daisy
yellow ladys slipper
corn
acorn
hip
buckeye
coral fungus
agaric
gyromitra
stinkhorn
earthstar
hen-of-the-woods
bolete
ear
toilet tissue'''
......@@ -8,7 +8,7 @@ import numpy as np
import cv2 as cv
class DaSiamRPN:
def __init__(self, model_path, kernel_cls1_path, kernel_r1_path, backend_id=0, target_id=0):
def __init__(self, kernel_cls1_path, kernel_r1_path, model_path, backend_id=0, target_id=0):
self._model_path = model_path
self._kernel_cls1_path = kernel_cls1_path
self._kernel_r1_path = kernel_r1_path
......
......@@ -52,9 +52,9 @@ def visualize(image, bbox, score, isLocated, fps=None, box_color=(0, 255, 0),tex
if __name__ == '__main__':
# Instantiate DaSiamRPN
model = DaSiamRPN(
model_path=args.model_path,
kernel_cls1_path=args.kernel_cls1_path,
kernel_r1_path=args.kernel_r1_path
kernel_r1_path=args.kernel_r1_path,
model_path=args.model_path,
)
# Read from args.input
......@@ -92,4 +92,4 @@ if __name__ == '__main__':
# Visualize
frame = visualize(frame, bbox, score, isLocated, fps=tm.getFPS())
cv.imshow('DaSiamRPN Demo', frame)
tm.reset()
\ No newline at end of file
tm.reset()
0
1
2
3
4
5
6
7
8
9
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
0
1
2
3
4
5
6
7
8
9
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
:
;
<
=
>
?
@
[
\
]
^
_
`
{
|
}
~
......@@ -41,7 +41,6 @@ parser.add_argument('--input', '-i', type=str, help='Usage: Set path to the inpu
parser.add_argument('--model', '-m', type=str, default='text_recognition_CRNN_EN_2021sep.onnx', help='Usage: Set model path, defaults to text_recognition_CRNN_EN_2021sep.onnx.')
parser.add_argument('--backend', '-b', type=int, default=backends[0], help=help_msg_backends.format(*backends))
parser.add_argument('--target', '-t', type=int, default=targets[0], help=help_msg_targets.format(*targets))
parser.add_argument('--charset', '-c', type=str, default='charset_36_EN.txt', help='Usage: Set the path to the charset file corresponding to the selected model.')
parser.add_argument('--save', '-s', type=str, default=False, help='Usage: Set “True” to save a file with results. Invalid in case of camera input. Default will be set to “False”.')
parser.add_argument('--vis', '-v', type=str2bool, default=True, help='Usage: Default will be set to “True” and will open a new window to show results. Set to “False” to stop visualizations from being shown. Invalid in case of camera input.')
parser.add_argument('--width', type=int, default=736,
......@@ -61,7 +60,7 @@ def visualize(image, boxes, texts, color=(0, 255, 0), isClosed=True, thickness=2
if __name__ == '__main__':
# Instantiate CRNN for text recognition
recognizer = CRNN(modelPath=args.model, charsetPath=args.charset)
recognizer = CRNN(modelPath=args.model)
# Instantiate DB for text detection
detector = DB(modelPath='../text_detection_db/text_detection_DB_IC15_resnet18_2021sep.onnx',
inputSize=[args.width, args.height],
......
......@@ -21,63 +21,63 @@ parser.add_argument("--dataset_root", "-dr", type=str, required=True, help="Root
args = parser.parse_args()
models = dict(
mobilenetv1=dict(
name="MobileNetV1",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr.onnx"),
topK=5),
mobilenetv1_q=dict(
name="MobileNetV1",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr-int8-quantized.onnx"),
topK=5),
mobilenetv2=dict(
name="MobileNetV2",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr.onnx"),
topK=5),
mobilenetv2_q=dict(
name="MobileNetV2",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr-int8-quantized.onnx"),
topK=5),
ppresnet=dict(
name="PPResNet",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx"),
topK=5),
ppresnet_q=dict(
name="PPResNet",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_ppresnet/image_classification_ppresnet50_2022jan-act_int8-wt_int8-quantized.onnx"),
topK=5),
yunet=dict(
name="YuNet",
topic="face_detection",
modelPath=os.path.join(root_dir, "models/face_detection_yunet/face_detection_yunet_2022mar.onnx"),
topK=5000,
confThreshold=0.3,
nmsThreshold=0.45),
yunet_q=dict(
name="YuNet",
topic="face_detection",
modelPath=os.path.join(root_dir, "models/face_detection_yunet/face_detection_yunet_2022mar-act_int8-wt_int8-quantized.onnx"),
topK=5000,
confThreshold=0.3,
nmsThreshold=0.45),
sface=dict(
name="SFace",
topic="face_recognition",
modelPath=os.path.join(root_dir, "models/face_recognition_sface/face_recognition_sface_2021dec.onnx")),
sface_q=dict(
name="SFace",
topic="face_recognition",
modelPath=os.path.join(root_dir, "models/face_recognition_sface/face_recognition_sface_2021dec-act_int8-wt_int8-quantized.onnx")),
crnn=dict(
name="CRNN",
topic="text_recognition",
modelPath=os.path.join(root_dir, "models/text_recognition_crnn/text_recognition_CRNN_EN_2021sep.onnx"),
charsetPath=os.path.join(root_dir, "models/text_recognition_crnn/charset_36_EN.txt")),
mobilenetv1=dict(
name="MobileNetV1",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr.onnx"),
topK=5),
mobilenetv1_q=dict(
name="MobileNetV1",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr-int8-quantized.onnx"),
topK=5),
mobilenetv2=dict(
name="MobileNetV2",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr.onnx"),
topK=5),
mobilenetv2_q=dict(
name="MobileNetV2",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr-int8-quantized.onnx"),
topK=5),
ppresnet=dict(
name="PPResNet",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx"),
topK=5),
ppresnet_q=dict(
name="PPResNet",
topic="image_classification",
modelPath=os.path.join(root_dir, "models/image_classification_ppresnet/image_classification_ppresnet50_2022jan-act_int8-wt_int8-quantized.onnx"),
topK=5),
yunet=dict(
name="YuNet",
topic="face_detection",
modelPath=os.path.join(root_dir, "models/face_detection_yunet/face_detection_yunet_2022mar.onnx"),
topK=5000,
confThreshold=0.3,
nmsThreshold=0.45),
yunet_q=dict(
name="YuNet",
topic="face_detection",
modelPath=os.path.join(root_dir, "models/face_detection_yunet/face_detection_yunet_2022mar-act_int8-wt_int8-quantized.onnx"),
topK=5000,
confThreshold=0.3,
nmsThreshold=0.45),
sface=dict(
name="SFace",
topic="face_recognition",
modelPath=os.path.join(root_dir, "models/face_recognition_sface/face_recognition_sface_2021dec.onnx")),
sface_q=dict(
name="SFace",
topic="face_recognition",
modelPath=os.path.join(root_dir, "models/face_recognition_sface/face_recognition_sface_2021dec-act_int8-wt_int8-quantized.onnx")),
crnn=dict(
name="CRNN",
topic="text_recognition",
modelPath=os.path.join(root_dir, "models/text_recognition_crnn/text_recognition_CRNN_EN_2021sep.onnx"),
charsetPath=os.path.join(root_dir, "models/text_recognition_crnn/charset_36_EN.txt")),
)
datasets = dict(
......@@ -107,7 +107,8 @@ def main(args):
model_name = models[model_key].pop("name")
model_topic = models[model_key].pop("topic")
model = MODELS.get(model_name)(**models[model_key])
model_handler, _ = MODELS.get(model_name)
model = model_handler(**models[model_key])
# Instantiate dataset
dataset_key = args.dataset.lower()
......@@ -124,6 +125,5 @@ def main(args):
dataset.eval(model)
dataset.print_result()
if __name__ == "__main__":
main(args)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册