taojx修改一些配置

V0.1.0
陶俊鑫 2 years ago
parent 5b6ef6d6f6
commit 89746c13ca

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}",
"justMyCode": true,
"purpose": ["debug-in-terminal"],
}
]
}

@ -0,0 +1,13 @@
{
"cSpell.words": [
"fastdeploy",
"imread",
"imshow",
"rtsp",
"yolov"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}

@ -1,7 +1,7 @@
import yaml
from pathlib import Path
def get_configs(ymal_files):
yaml_path = Path(__file__).parent / ymal_files
def get_configs(yaml_files):
yaml_path = Path(__file__).parent.parent / yaml_files
with yaml_path.open("r", encoding="utf-8") as f:
return yaml.load(f, Loader=yaml.FullLoader)

@ -1,9 +0,0 @@
def rtsp_para(scource):
if scource.split('://')[0] == 'rtsp':
return True
else:
return False

@ -2,6 +2,8 @@
def det_img(model_inference,images_frame,confidence,label_name_list):
assert images_frame is not None
result = model_inference.predict(images_frame)
bbox_list = result.boxes

@ -1,18 +1,18 @@
detect_0:
source : rtsp://admin:@192.168.10.18
model: /home/yaxin/xbank/xbank_poc_test/config_phone.yaml
source : /home/tp/taojx/xbank_test_videos/0711-1/0711-1_10.avi
model: ./config_phone.yaml
detect_1:
source : rtsp://admin:@192.168.10.12
model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
# detect_1:
# source : rtsp://admin:@192.168.10.12
# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
detect_2:
source : rtsp://admin:@192.168.10.18
model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
# detect_2:
# source : rtsp://admin:@192.168.10.18
# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
detect_3:
source : rtsp://admin:@192.168.10.11
model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
# detect_3:
# source : rtsp://admin:@192.168.10.11
# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
# detect_4:
# source : rtsp://admin:@192.168.10.11

@ -1,6 +1,6 @@
# load model file
model: /home/yaxin/xbank/xbank_poc_test/model_file/yolov5.onnx
model_cache: /home/yaxin/xbank/xbank_poc_test/tensort_cache/yolov5.trt
model: ./model_file/yolov5.onnx
model_cache: ./tensort_cache/yolov5.trt
# label and bbox message set
model_parameter:
@ -11,7 +11,7 @@ model_parameter:
relevancy_para : 0
confidence : 0.2
save_path : /home/yaxin/xbank/xbank_poc_test/save_path/hands
save_path : ./save_path/hands
# save_path_original : /home/yaxin/xbank/xbank_poc_test/save_path_original/hands
# test_path : /home/yaxin/xbank/xbank_poc_test/test_save_path/hands
save_path_original : False

@ -1,6 +1,6 @@
# load model file
model: /home/yaxin/xbank/xbank_poc_test/model_file/yolov8.onnx
model_cache: /home/yaxin/xbank/xbank_poc_test/tensort_cache/yolov8.trt
model: ./model_file/yolov8.onnx
model_cache: ./tensort_cache/yolov8.trt
# label and bbox message set
model_parameter:
@ -11,7 +11,7 @@ model_parameter:
relevancy_para : False
confidence : 0.2
save_path : /home/yaxin/xbank/xbank_poc_test/save_path/sleep
save_path : ./save_path/sleep
# save_path_original : /home/yaxin/xbank/xbank_poc_test/save_path_original/sleep
# test_path : /home/yaxin/xbank/xbank_poc_test/test_save_path/sleep
save_path_original : False

@ -1,9 +1,6 @@
#coding: utf-8
from main_process import data_load
import multiprocessing
from analysis_data.config_load import get_configs
from model_load.model_load import Load_model
import time
from multiprocessing import Pool
@ -25,12 +22,14 @@ def get_args_list(args_data):
if __name__ == "__main__":
# 加载配置文件
args = '/home/yaxin/xbank/xbank_poc_test/config_det.yaml'
args_data = get_configs(ymal_files=args)
args = './config_det.yaml'
args_data = get_configs(yaml_files=args)
args_list = get_args_list(args_data)
process_num = len(args_list)
print(f"args_list:{args_list}")
with Pool(process_num) as pool:
pool.map(data_load, args_list)

@ -1,16 +1,13 @@
from analysis_result.get_model_result import det_img
from analysis_result.same_model_img import same_model_img_analysis_labels, model_labels_selet
from model_load.model_load import Load_model
from model_load.model_load import load_model
from drawing_img.drawing_img import drawing_frame
from analysis_data.data_rtsp import rtsp_para
from analysis_data.data_dir_file import get_dir_file, get_imgframe
from analysis_data.data_load import data_load
from analysis_data.data_dir_file import get_dir_file
from analysis_data.config_load import get_configs
from utils import is_image_file, is_rtsp_or_video
import yaml
import cv2
import os
from pathlib import Path
import time
from datetime import datetime
@ -20,20 +17,20 @@ def data_load(args):
# print('正在运行的进程',msg)
# print(args)
source = args[0]
model_ymal = args[1]
model_yaml = args[1]
# 数据加载
rtsp_source = rtsp_para(source)
rtsp_or_video_source = is_rtsp_or_video(source)
dir_source = os.path.isdir(source)
file_source = os.path.isfile(source)
img_source = is_image_file(source)
# # 模型加载
model_data = get_configs(model_ymal)
model_inference = Load_model(model_file=model_data["model"],
model_data = get_configs(model_yaml)
model_inference = load_model(model_file=model_data["model"],
device=model_data["model_parameter"]['device'],
cache_file=model_data["model_cache"])
if rtsp_source:
if rtsp_or_video_source:
cap = cv2.VideoCapture(source)
@ -49,15 +46,11 @@ def data_load(args):
# cv2.imshow('18',frame)
t1 = time.time()
imgframe_dict = {"path": source, 'frame': frame}
img_frame_dict = {"path": source, 'frame': frame}
images_update = img_process(
imgframe_dict, model_inference, model_data)
img_frame_dict, model_inference, model_data)
# print(type(images_update['frame']))
t2 = time.time()
tx = t2 - t1
print('检测一张图片的时间为:',tx)
# if source == 'rtsp://admin:@192.168.10.18':
# cv2.namedWindow('18',0)
@ -87,10 +80,10 @@ def data_load(args):
t1 = time.time()
images = cv2.imread(img)
imgframe_dict = {"path": img, 'frame': images}
img_frame_dict = {"path": img, 'frame': images}
images_update = img_process(
imgframe_dict, model_inference, model_data)
img_frame_dict, model_inference, model_data)
t2 = time.time()
tx = t2 - t1
@ -101,21 +94,22 @@ def data_load(args):
pass
if file_source:
if img_source:
img_para = True
if img_para:
images = cv2.imread(source)
imgframe_dict = {"path": source, 'frame': images}
img_frame_dict = {"path": source, 'frame': images}
images_update = img_process(
imgframe_dict, model_inference, model_data)
img_frame_dict, model_inference, model_data)
def img_process(images, model_inference, model_data):
# t1 = time.time()
start_point = time.perf_counter()
# 检测每帧图片,返回推理结果
results = det_img(model_inference=model_inference,
images_frame=images['frame'],
@ -149,10 +143,10 @@ def img_process(images, model_inference, model_data):
images.update({"frame": img_save})
imgname = images_save(
img_name = images_save(
images=images['frame'], save_path=model_data["save_path"])
print('sleep:', images['path'], imgname)
print('sleep:', images['path'], img_name)
if model_data['save_path_original']:
images_save(images=images['frame'],
@ -162,9 +156,9 @@ def img_process(images, model_inference, model_data):
else:
# 没检测出来的图片是否保存
if model_data["test_path"]:
imgname = images_save(
img_name = images_save(
images=images['frame'], save_path=model_data["test_path"])
# print('no:',images['path'],imgname)
# print('no:',images['path'],img_name)
else:
pass
@ -178,6 +172,11 @@ def img_process(images, model_inference, model_data):
# t2 = time.time()
end_point = time.perf_counter()
cost = end_point - start_point
print(f"Predicted in {cost * 1000:.2f}ms. {1.0 / cost:.2f} FPS")
return images

@ -19,7 +19,7 @@ def build_option(device, backend, cache_file):
return option
def Load_model(model_file, device, cache_file):
def load_model(model_file, device, cache_file):
"""
加载模型的tensorRT引擎
model_file模型权重 格式".onnx"

@ -0,0 +1,14 @@
def is_image_file(filename):
image_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".webp"]
# 获取文件扩展名并转换为小写
file_extension = filename.split(".")[-1].lower()
return file_extension in image_extensions
def is_rtsp_or_video(source):
if source.startswith("rtsp://"):
return True
video_exts = ["mp4", "avi"]
file_extension = source.split(".")[-1].lower()
return file_extension in video_exts
Loading…
Cancel
Save