From 84d8e916a6d6c173b58a93e8edd802c311aa3cf7 Mon Sep 17 00:00:00 2001 From: "552068321@qq.com" Date: Tue, 8 Nov 2022 10:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/AlgorithmController.py | 220 +++++++++++++------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/app/controller/AlgorithmController.py b/app/controller/AlgorithmController.py index 3522a89..25897d7 100644 --- a/app/controller/AlgorithmController.py +++ b/app/controller/AlgorithmController.py @@ -242,7 +242,7 @@ from app import file_tool # 启动训练 -#@start_train_algorithm() +@start_train_algorithm() def train_R0DY(params_str, id): from app.yolov5.train_server import train_start params = TrainParams() @@ -261,60 +261,60 @@ def train_R0DY(params_str, id): # 启动验证程序 -# @start_test_algorithm() -# def validate_RODY(params_str, id): -# from app.yolov5.validate_server import validate_start -# params = TrainParams() -# params.read_from_str(params_str) -# weights = params.get('modPath').value # 验证模型绝对路径 -# (filename, extension) = os.path.splitext(weights) # 文件名与后缀名分开 -# img_size = int(filename.split('ROD')[1].split('_')[2]) # 获取图像参数 -# # v_num = int(filename.split('ROD')[1].split('_')[1]) #获取版本号 -# output = params.get('outputPath').value -# batch_size = params.get('batch_size').default -# device = params.get('device').value -# -# validate_start(weights, img_size, batch_size, device, output, id) -# -# -# @start_detect_algorithm() -# def detect_RODY(params_str, id): -# from app.yolov5.detect_server import detect_start -# params = TrainParams() -# params.read_from_str(params_str) -# weights = params.get('modPath').value # 检测模型绝对路径 -# input = params.get('inputPath').value -# outpath = params.get('outputPath').value -# # (filename, extension) = os.path.splitext(weights) # 文件名与后缀名分开 -# # img_size = int(filename.split('ROD')[1].split('_')[2]) #获取图像参数 -# # v_num = int(filename.split('ROD')[1].split('_')[1]) #获取版本号 -# # batch_size = params.get('batch_size').default -# device = params.get('device').value -# -# detect_start(input, weights, outpath, device, id) -# -# -# @start_download_pt() -# def Export_model_RODY(params_str): -# from app.yolov5.export import Start_Model_Export -# import zipfile -# params = TrainParams() -# params.read_from_str(params_str) -# exp_inputPath = params.get('exp_inputPath').value # 模型路径 -# exp_device = params.get('device').value -# modellist = Start_Model_Export(exp_inputPath, exp_device) -# exp_outputPath = exp_inputPath.replace('pt', 'zip') # 压缩文件 -# zipf = zipfile.ZipFile(exp_outputPath, 'w') -# for file in modellist: -# zipf.write(file, arcname=Path(file).name) # 将torchscript和onnx模型压缩 -# -# return exp_outputPath - # zipf.write(modellist[1], arcname=modellist[1]) - # zip_inputpath = os.path.join(exp_outputPath, "inference_model") - # zip_outputPath = os.path.join(exp_outputPath, "inference_model.zip") +@start_test_algorithm() +def validate_RODY(params_str, id): + from app.yolov5.validate_server import validate_start + params = TrainParams() + params.read_from_str(params_str) + weights = params.get('modPath').value # 验证模型绝对路径 + (filename, extension) = os.path.splitext(weights) # 文件名与后缀名分开 + img_size = int(filename.split('ROD')[1].split('_')[2]) # 获取图像参数 + # v_num = int(filename.split('ROD')[1].split('_')[1]) #获取版本号 + output = params.get('outputPath').value + batch_size = params.get('batch_size').default + device = params.get('device').value + + validate_start(weights, img_size, batch_size, device, output, id) -#@obtain_train_param() +@start_detect_algorithm() +def detect_RODY(params_str, id): + from app.yolov5.detect_server import detect_start + params = TrainParams() + params.read_from_str(params_str) + weights = params.get('modPath').value # 检测模型绝对路径 + input = params.get('inputPath').value + outpath = params.get('outputPath').value + # (filename, extension) = os.path.splitext(weights) # 文件名与后缀名分开 + # img_size = int(filename.split('ROD')[1].split('_')[2]) #获取图像参数 + # v_num = int(filename.split('ROD')[1].split('_')[1]) #获取版本号 + # batch_size = params.get('batch_size').default + device = params.get('device').value + + detect_start(input, weights, outpath, device, id) + + +@start_download_pt() +def Export_model_RODY(params_str): + from app.yolov5.export import Start_Model_Export + import zipfile + params = TrainParams() + params.read_from_str(params_str) + exp_inputPath = params.get('exp_inputPath').value # 模型路径 + exp_device = params.get('device').value + modellist = Start_Model_Export(exp_inputPath, exp_device) + exp_outputPath = exp_inputPath.replace('pt', 'zip') # 压缩文件 + zipf = zipfile.ZipFile(exp_outputPath, 'w') + for file in modellist: + zipf.write(file, arcname=Path(file).name) # 将torchscript和onnx模型压缩 + + return exp_outputPath + zipf.write(modellist[1], arcname=modellist[1]) + zip_inputpath = os.path.join(exp_outputPath, "inference_model") + zip_outputPath = os.path.join(exp_outputPath, "inference_model.zip") + + +@obtain_train_param() def returnTrainParams(): # nvmlInit() # gpuDeviceCount = nvmlDeviceGetCount() # 获取Nvidia GPU块数 @@ -347,63 +347,63 @@ def returnTrainParams(): return params_str -# @obtain_test_param() -# def returnValidateParams(): -# # nvmlInit() -# # gpuDeviceCount = nvmlDeviceGetCount() # 获取Nvidia GPU块数 -# # _kernel = [f"cuda:{a}" for a in range(gpuDeviceCount)] -# params_list = [ -# {"index": 0, "name": "modPath", "value": "E:/alg_demo-master/alg_demo/app/yolov5/圆孔_123_RODY_1_640.pt", -# "description": '验证模型路径', "default": "./app/maskrcnn/saved_model/test.pt", "type": "S", 'show': False}, -# {"index": 1, "name": "batch_size", "value": 1, "description": '批次图像数量', "default": 1, "type": "I", -# 'show': False}, -# {"index": 2, "name": "img_size", "value": 640, "description": '训练图像大小', "default": 640, "type": "I", -# 'show': False}, -# {"index": 3, "name": "outputPath", "value": 'E:/aicheck/data_set/11442136178662604800/val_results/', -# "description": '输出结果路径', -# "default": './app/maskrcnn/datasets/M006B_waibi/res', "type": "S", 'show': False}, -# {"index": 4, "name": "device", "value": "0", "description": '训练核心', "default": "cuda", "type": "S", -# "items": '', 'show': False} # _kernel -# ] -# # {"index": 9, "name": "saveEpoch", "value": 2, "description": '保存模型轮次', "default": 2, "type": "I", 'show': True}] -# params_str = json.dumps(params_list) -# return params_str -# -# -# @obtain_detect_param() -# def returnDetectParams(): -# # nvmlInit() -# # gpuDeviceCount = nvmlDeviceGetCount() # 获取Nvidia GPU块数 -# # _kernel = [f"cuda:{a}" for a in range(gpuDeviceCount)] -# params_list = [ -# {"index": 0, "name": "inputPath", "value": 'E:/aicheck/data_set/11442136178662604800/input/', -# "description": '输入图像路径', "default": './app/maskrcnn/datasets/M006B_waibi/JPEGImages', "type": "S", -# 'show': False}, -# {"index": 1, "name": "outputPath", "value": 'E:/aicheck/data_set/11442136178662604800/val_results/', -# "description": '输出结果路径', -# "default": './app/maskrcnn/datasets/M006B_waibi/res', "type": "S", 'show': False}, -# {"index": 0, "name": "modPath", "value": "E:/alg_demo-master/alg_demo/app/yolov5/圆孔_123_RODY_1_640.pt", -# "description": '模型路径', "default": "./app/maskrcnn/saved_model/test.pt", "type": "S", 'show': False}, -# {"index": 3, "name": "device", "value": "0", "description": '推理核', "default": "cpu", "type": "S", -# 'show': False}, -# ] -# # {"index": 9, "name": "saveEpoch", "value": 2, "description": '保存模型轮次', "default": 2, "type": "I", 'show': True}] -# params_str = json.dumps(params_list) -# return params_str -# -# -# @obtain_download_pt_param() -# def returnDownloadParams(): -# params_list = [ -# {"index": 0, "name": "exp_inputPath", "value": 'E:/alg_demo-master/alg_demo/app/yolov5/圆孔_123_RODY_1_640.pt', -# "description": '转化模型输入路径', -# "default": '/mnt/sdc/IntelligentizeAI/IntelligentizeAI/data_set/weights/new磁环检测test_183504733393264640_R-DDM_11.pt/', -# "type": "S", 'show': False}, -# {"index": 1, "name": "device", "value": 'gpu', "description": 'CPU或GPU', "default": 'gpu', "type": "S", -# 'show': False} -# ] -# params_str = json.dumps(params_list) -# return params_str +@obtain_test_param() +def returnValidateParams(): + # nvmlInit() + # gpuDeviceCount = nvmlDeviceGetCount() # 获取Nvidia GPU块数 + # _kernel = [f"cuda:{a}" for a in range(gpuDeviceCount)] + params_list = [ + {"index": 0, "name": "modPath", "value": "E:/alg_demo-master/alg_demo/app/yolov5/圆孔_123_RODY_1_640.pt", + "description": '验证模型路径', "default": "./app/maskrcnn/saved_model/test.pt", "type": "S", 'show': False}, + {"index": 1, "name": "batch_size", "value": 1, "description": '批次图像数量', "default": 1, "type": "I", + 'show': False}, + {"index": 2, "name": "img_size", "value": 640, "description": '训练图像大小', "default": 640, "type": "I", + 'show': False}, + {"index": 3, "name": "outputPath", "value": 'E:/aicheck/data_set/11442136178662604800/val_results/', + "description": '输出结果路径', + "default": './app/maskrcnn/datasets/M006B_waibi/res', "type": "S", 'show': False}, + {"index": 4, "name": "device", "value": "0", "description": '训练核心', "default": "cuda", "type": "S", + "items": '', 'show': False} # _kernel + ] + # {"index": 9, "name": "saveEpoch", "value": 2, "description": '保存模型轮次', "default": 2, "type": "I", 'show': True}] + params_str = json.dumps(params_list) + return params_str + + +@obtain_detect_param() +def returnDetectParams(): + # nvmlInit() + # gpuDeviceCount = nvmlDeviceGetCount() # 获取Nvidia GPU块数 + # _kernel = [f"cuda:{a}" for a in range(gpuDeviceCount)] + params_list = [ + {"index": 0, "name": "inputPath", "value": 'E:/aicheck/data_set/11442136178662604800/input/', + "description": '输入图像路径', "default": './app/maskrcnn/datasets/M006B_waibi/JPEGImages', "type": "S", + 'show': False}, + {"index": 1, "name": "outputPath", "value": 'E:/aicheck/data_set/11442136178662604800/val_results/', + "description": '输出结果路径', + "default": './app/maskrcnn/datasets/M006B_waibi/res', "type": "S", 'show': False}, + {"index": 0, "name": "modPath", "value": "E:/alg_demo-master/alg_demo/app/yolov5/圆孔_123_RODY_1_640.pt", + "description": '模型路径', "default": "./app/maskrcnn/saved_model/test.pt", "type": "S", 'show': False}, + {"index": 3, "name": "device", "value": "0", "description": '推理核', "default": "cpu", "type": "S", + 'show': False}, + ] + # {"index": 9, "name": "saveEpoch", "value": 2, "description": '保存模型轮次', "default": 2, "type": "I", 'show': True}] + params_str = json.dumps(params_list) + return params_str + + +@obtain_download_pt_param() +def returnDownloadParams(): + params_list = [ + {"index": 0, "name": "exp_inputPath", "value": 'E:/alg_demo-master/alg_demo/app/yolov5/圆孔_123_RODY_1_640.pt', + "description": '转化模型输入路径', + "default": '/mnt/sdc/IntelligentizeAI/IntelligentizeAI/data_set/weights/new磁环检测test_183504733393264640_R-DDM_11.pt/', + "type": "S", 'show': False}, + {"index": 1, "name": "device", "value": 'gpu', "description": 'CPU或GPU', "default": 'gpu', "type": "S", + 'show': False} + ] + params_str = json.dumps(params_list) + return params_str if __name__ == '__main__':