调用python训练的模型_C++调用python训练的pytorch模型(三)----- 实战:封装pytorch模型...

文章目录

封装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()

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值