更新时间:2022-02-22 GMT+08:00
示例-难例上传
难例上传示例如下所示:
import hilens
import cv2
import numpy as np
def run():
# 构造摄像头
cap = hilens.VideoCapture()
disp = hilens.Display(hilens.HDMI)
hard_sample = hilens.HardSample(0.5,0.5,1) # 1,2为检测模型使用的算法
#hard_sample = hilens.HardSample(0.5,0.5,0) # 0为分类模型使用的算法
hard_sample_flag = False # 是否存在难例上传配置
hard_sample_config = hilens.get_hard_sample_config() # 获取难例配置
if not hard_sample_config:
hilens.warning("hardSampleConfig is empty")
else:
hard_sample_flag = True
data_count = hard_sample_config["hard_sample_setting"][0]["data_count"]
data_current_count = hard_sample_config["hard_sample_setting"][0]["datacur_count"]
upload_jpeg_url = hard_sample_config["hard_sample_setting"][0]["dataset_path"]
model_name = hard_sample_config["hard_sample_setting"][0]["model_name"]
camera_name = "default"
if data_count > data_current_count:
upload_flag = True # upload_flag是否继续上传
else:
upload_flag = False
while True:
# 获取一帧画面
frame = cap.read()
if hard_sample_flag:
if upload_flag:
if hard_sample.hard_sample_detection_filter([[0.,0.,1280.,720.,0.4,1]]): # 检测算法的输入为后处理之后的检测框,每个检测框包括[xmin, ymin, xmax, ymax, conf, label](包括置信度和类别标签)
#if hard_sample.hard_sample_classification_filter([0.2, 0.2, 0.2, 0.2, 0.2],5): # 分类算法的输入为各类别的概率,即模型的输出
hard_sample.upload_jpeg(upload_jpeg_url, data_current_count, model_name, camera_name, frame)
data_current_count += 1
hard_sample_config["hard_sample_setting"][0]["datacur_count"] = data_current_count
if data_current_count == 1 or data_current_count == data_count:
if data_current_count == data_count:
upload_flag = False
hilens.set_hard_sample_config(hard_sample_config) # 更新端侧难例配置文件
#输出到HDMI
disp.show(frame)
if __name__ == '__main__':
#参数【hello】要与基本信息的【检验值】一致。详情请查看开发指南
hilens.init("hello")
run()
hilens.terminate()
父主题: 难例上传模块