提交 f9ae67ef 编写于 作者: Eric.Lee2021's avatar Eric.Lee2021 🚴🏻

add face detect wrid face

上级 409d75ee
cfg_model=yolo
classes=1
gpus = 0
num_workers = 8
batch_size = 8
img_size = 416
multi_scale = True
epochs = 100
train=./yolo_widerface_open_train/anno/train.txt
valid=./yolo_widerface_open_train/anno/train.txt
names=./cfg/face.names
#finetune_model=./coco_model/yolov3_coco.pt
finetune_model = ./weights-yolov3-face/latest_416.pt
lr_step = 10,20,30
lr0 = 0.0001
......@@ -55,7 +55,6 @@ def refine_hand_bbox(bbox,img_shape):
return (x1,y1,x2,y2)
def detect(
model_path,
root_path,
cfg,
data_cfg,
img_size=416,
......@@ -94,12 +93,20 @@ def detect(
colors = [(v // 32 * 64 + 64, (v // 8) % 4 * 64, v % 8 * 32) for v in range(1, num_classes + 1)][::-1]
video_capture = cv2.VideoCapture(0)
video_capture = cv2.VideoCapture("./video/bean.mp4")
# url="http://admin:admin@192.168.43.1:8081"
# video_capture=cv2.VideoCapture(url)
video_writer = None
loc_time = time.localtime()
str_time = time.strftime("%Y-%m-%d_%H-%M-%S", loc_time)
save_video_path = "./demo/demo_{}.mp4".format(str_time)
#-------------------------------------------------
while True:
ret, im0 = video_capture.read()
if ret:
t = time.time()
# im0 = cv2.imread("samples/5.png")
img = process_data(im0, img_size)
if use_cuda:
torch.cuda.synchronize()
......@@ -140,8 +147,11 @@ def detect(
# Draw bounding boxes and labels of detections
for *xyxy, conf, cls_conf, cls in detections:
label = '%s %.2f' % (classes[int(cls)], conf)
# label = '%s' % (classes[int(cls)])
# print(conf, cls_conf)
# xyxy = refine_hand_bbox(xyxy,im0.shape)
plot_one_box(xyxy, im0, label=label, color=(255,255,0))
plot_one_box(xyxy, im0, label=label, color=(155,55,255),line_thickness = 3)
s2 = time.time()
print("detect time: {} \n".format(s2 - t))
......@@ -153,33 +163,31 @@ def detect(
cv2.namedWindow('image',0)
cv2.imshow("image", im0)
key = cv2.waitKey(1)
if video_writer is None:
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
video_writer = cv2.VideoWriter(save_video_path, fourcc, fps=25, frameSize = (im0.shape[1], im0.shape[0]))
video_writer.write(im0)
if key == 27:
break
else:
break
cv2.destroyAllWindows()
video_writer.release()
if __name__ == '__main__':
pattern = 'yolo'
if "-tiny" in pattern:
model_path = './weights-yolov3-person-tiny/latest_320.pt' # 检测模型路径
root_path = './test_images/'# 测试文件夹
model_cfg = pattern # 模型类型
else:
model_path = './weights-yolov3-hand/latest_416.pt' # 检测模型路径
root_path = './test_images/'# 测试文件夹
model_cfg = 'yolov3' # 模型类型
voc_config = 'cfg/hand.data' # 模型相关配置文件
voc_config = 'cfg/face.data' # 模型相关配置文件
model_path = './weights-yolov3-face/latest_416.pt' # 检测模型路径
model_cfg = 'yolo' # yolo / yolo-tiny
img_size = 416 # 图像尺寸
conf_thres = 0.25# 检测置信度
nms_thres = 0.45 # nms 阈值
conf_thres = 0.36# 检测置信度
nms_thres = 0.5 # nms 阈值
with torch.no_grad():#设置无梯度运行
detect(
model_path = model_path,
root_path = root_path,
cfg = model_cfg,
data_cfg = voc_config,
img_size=img_size,
......
......@@ -202,7 +202,8 @@ def train(data_cfg ='cfg/voc.data',
if __name__ == '__main__':
train(data_cfg='cfg/hand.data')
# train(data_cfg="cfg/hand.data")
train(data_cfg = "cfg/face.data")
print('well done ~ ')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册