文章目录
封装python 模型 SDK
准备好python api函数
C++调用python api
生成so文件
调用模型SDK
demo
makefile
执行demo
封装python 模型 SDK
准备好python api函数
python代码
# webcam_test.py
global g_model
def load_model(wkspace_dir,cfg_file):
# prepare object that handles inference plus adds predictions on top of image
global g_model
print("wkspace_dir: %s" % wkspace_dir)
print("cfg_file: %s" % cfg_file)
# os.chdir('/home/bob/wkspace/git/maskrcnn-benchmark/demo')
os.chdir(wkspace_dir)
# load config from file and command-line arguments
# cfg.merge_from_file("r50_1204.yaml")
cfg.merge_from_file(cfg_file)
# cfg.merge_from_list(args.opts)
cfg.freeze()
coco_demo = COCODemo(
cfg,
confidence_threshold=0.7,
show_mask_heatmaps=False,
masks_per_dim=2,
min_image_size=480,
)
g_model = coco_demo
def forward(image):
global g_model
print('image path is: %s' %image)
image=cv2.imread(image)
predictions = g_model.compute_prediction(image)
predictions = g_model.select_top_predictions(predictions)
scores = predictions.get_field("scores").tolist()