1- from mmdeploy_runtime import Detector
1+ import argparse
22import os
3- import cv2
43import time
5- import numpy as np
6- import argparse
74
8-
9- from avstack . geometry import GlobalOrigin3D
5+ import cv2
6+ import numpy as np
107from avstack .calibration import CameraCalibration
11- from avstack .sensors import ImageData
8+ from avstack .geometry import GlobalOrigin3D
129from avstack .modules .perception .object2dfv import MMDetObjectDetector2D
10+ from avstack .sensors import ImageData
11+ from mmdeploy_runtime import Detector
1312
1413
1514def run_with_timing (detector , img , n_inferences ):
@@ -19,17 +18,13 @@ def run_with_timing(detector, img, n_inferences):
1918 _ = detector (img )
2019 t2 = time .time ()
2120 if i > 1 : # just in case first two times are slow...
22- timing .append ((t2 - t1 )* 1000 )
23- print (f' Timing Results:\n { np .mean (timing ):4.2f} +/- { np .std (timing ):4.2f} ms' )
21+ timing .append ((t2 - t1 ) * 1000 )
22+ print (f" Timing Results:\n { np .mean (timing ):4.2f} +/- { np .std (timing ):4.2f} ms" )
2423
2524
2625def main_mmdeploy (model_path , img , n_inferences = 50 ):
27- detector = Detector (
28- model_path = model_path ,
29- device_name = 'cuda' ,
30- device_id = 0
31- )
32- print ('Running mmdeploy:' )
26+ detector = Detector (model_path = model_path , device_name = "cuda" , device_id = 0 )
27+ print ("Running mmdeploy:" )
3328 run_with_timing (detector , img , n_inferences )
3429
3530
@@ -40,28 +35,34 @@ def main_mmdet(dataset, model, img, n_inferences=50):
4035 gpu = 0 ,
4136 )
4237 cam_calib = CameraCalibration (
43- reference = GlobalOrigin3D ,
44- P = np .random .rand (3 ,4 ),
45- img_shape = img .shape
38+ reference = GlobalOrigin3D , P = np .random .rand (3 , 4 ), img_shape = img .shape
4639 )
4740 img = ImageData (timestamp = 0 , frame = 0 , data = img , calibration = cam_calib , source_ID = 0 )
48- print (' Running mmdetection' )
41+ print (" Running mmdetection" )
4942 run_with_timing (detector , img , n_inferences )
5043
5144
5245if __name__ == "__main__" :
5346 parser = argparse .ArgumentParser ()
54- parser .add_argument ('--dataset' , default = "coco" , type = str , help = "Name of the dataset to use" )
55- parser .add_argument ('--model' , default = "cascade_rcnn" , type = str , help = "Name of the model to use" )
56- parser .add_argument ('--runtime' , default = 'tensorrt' , type = str , help = "NN runtime to use for deploy" )
47+ parser .add_argument (
48+ "--dataset" , default = "coco" , type = str , help = "Name of the dataset to use"
49+ )
50+ parser .add_argument (
51+ "--model" , default = "cascade_rcnn" , type = str , help = "Name of the model to use"
52+ )
53+ parser .add_argument (
54+ "--runtime" , default = "tensorrt" , type = str , help = "NN runtime to use for deploy"
55+ )
5756 args = parser .parse_args ()
58-
59- mmdep_model_path = os .path .join ('mmdeploy_models' , f'{ args .model } _{ args .dataset } _{ args .runtime } ' )
57+
58+ mmdep_model_path = os .path .join (
59+ "mmdeploy_models" , f"{ args .model } _{ args .dataset } _{ args .runtime } "
60+ )
6061 if not os .path .exists (mmdep_model_path ):
6162 raise FileNotFoundError ("Cannot find model for mmdeploy" )
6263
6364 MMDET_BASE = "../../third_party/mmdetection"
6465 img = cv2 .imread (os .path .join (MMDET_BASE , "demo" , "demo.jpg" ))
6566 n_inferences = 20
6667 main_mmdeploy (mmdep_model_path , img , n_inferences = n_inferences )
67- main_mmdet (args .dataset , args .model , img , n_inferences = n_inferences )
68+ main_mmdet (args .dataset , args .model , img , n_inferences = n_inferences )
0 commit comments