加入公司

main
wangchunlin 3 years ago
parent 8f6244bd1e
commit 6ed89d0a02

@ -58,7 +58,7 @@
<script> <script>
var dic_class={};//创建一个字典; var dic_class={};//创建一个字典;
dic_class["外破"]=["外破ljp4500张四类v5v3", "外破ljp4500张四类v5v7", "外破ljp4500张四类v5v7m", "烟火与塔吊"] dic_class["外破"]=["外破ljp4500张四类v5v3", "外破ljp4500张四类v5v7", "外破ljp4500张四类v5v7m", "烟火与塔吊", "外破ljp4500张四类v5v7m6", "yolov3-tiny四类(正式使用)", "yolov3-tiny两类(正式使用)"]
dic_class["山火"]=["小模型", "大模型", "泛模型"] dic_class["山火"]=["小模型", "大模型", "泛模型"]
dic_class["绝缘子"]=["绝缘子缺陷ljp2000张两类v5v7"] dic_class["绝缘子"]=["绝缘子缺陷ljp2000张两类v5v7"]
dic_class["一般物体80类"]=["v5sv7"] dic_class["一般物体80类"]=["v5sv7"]
@ -90,8 +90,8 @@ document.addEventListener("paste", function () {
// 字典 dict // 字典 dict
var model = $('#model option:selected').val(); var model = $('#model option:selected').val();
var model_class = $('#class option:selected').val(); var model_class = $('#class option:selected').val();
console.log("检测类别与使用模型:", model_class, model) console.log("检测类别与使用模型:", Object.keys(dic_class)[model_class-1], ',',dic_class[Object.keys(dic_class)[model_class-1]][model-1])
$.getJSON('/dlurl/', {'url':val, 'model':model, 'class':model_class},function(res){ShowResult(res);}); $.getJSON('/dlurl/', {'url':val, 'model':model, 'class':model_class,'model_name':dic_class[Object.keys(dic_class)[model_class-1]][model-1],'class_name':Object.keys(dic_class)[model_class-1]},function(res){ShowResult(res);});
} }
}); });
</script> </script>
@ -116,6 +116,17 @@ layui.use('upload', function(){
var model_class = $('#class option:selected').val(); var model_class = $('#class option:selected').val();
return model_class; return model_class;
} }
, 'model_name':function(){
var model_class = $('#class option:selected').val();
var model = $('#model option:selected').val();
var model_name=dic_class[Object.keys(dic_class)[model_class-1]][model-1];
return model_name;
}
, 'class_name':function(){
var model_class = $('#class option:selected').val();
var class_name=Object.keys(dic_class)[model_class-1];
return class_name;
}
} }
,done: function(res){ ,done: function(res){
ShowResult(res); ShowResult(res);
@ -157,7 +168,7 @@ layui.use('upload', function(){
}; };
} }
$("#img").prepend(i); $("#img").prepend(i);
$("#img").prepend('<br>' +'<br>' + '<b>'+'<font size="4">'+"检测图片"+res.code+'</font> '+"</b>"+'<br>'); $("#img").prepend('<br>' +'<br>' + '<b>'+'<font size="4">'+"检测信息"+res.code+'</font> '+"</b>"+'<br>');
} }
function AutoResizeImage(maxWidth,maxHeight,objImg){ function AutoResizeImage(maxWidth,maxHeight,objImg){
var img = new Image(); var img = new Image();

@ -5,6 +5,7 @@ import os
import subprocess import subprocess
from datetime import datetime from datetime import datetime
import learn.yolov5.detect as DL import learn.yolov5.detect as DL
import learn.Darknet2Pytorch2Onnx.hy_runonnx as RONNX
from pathlib import PosixPath from pathlib import PosixPath
import requests, os, json import requests, os, json
import cv2 import cv2
@ -45,6 +46,10 @@ def upload(request):
file = request.FILES.get('file') #获取前端上传的文件 file = request.FILES.get('file') #获取前端上传的文件
m_model=request.POST.get('model') m_model=request.POST.get('model')
m_class=request.POST.get('class') m_class=request.POST.get('class')
model_name = request.POST.get("model_name")
class_name = request.POST.get("class_name")
print(request.POST["model_name"])
print(request.POST["class_name"])
fix = datetime.now().strftime('%Y%m%d%H%M%S%f')+'1' #给文件加前缀防止文件名重复 fix = datetime.now().strftime('%Y%m%d%H%M%S%f')+'1' #给文件加前缀防止文件名重复
#以下用绝对路径存储文件,之前我用相对路径一直写不对 #以下用绝对路径存储文件,之前我用相对路径一直写不对
curPath = os.path.abspath( os.path.dirname( __file__ ) ) curPath = os.path.abspath( os.path.dirname( __file__ ) )
@ -56,7 +61,7 @@ def upload(request):
for i in file.chunks(): for i in file.chunks():
f.write(i) f.write(i)
f.close() f.close()
return inference(m_class, m_model, curPath, img_path_res, img_path) return inference(m_class, m_model, curPath, img_path_res, img_path, model_name, class_name)
def dlurl(request): def dlurl(request):
@ -64,6 +69,10 @@ def dlurl(request):
url = request.GET["url"] #获取前端上传的文件 url = request.GET["url"] #获取前端上传的文件
m_model=request.GET["model"] m_model=request.GET["model"]
m_class=request.GET["class"] m_class=request.GET["class"]
model_name = request.GET.get("model_name")
class_name = request.GET.get("class_name")
print(request.GET["model_name"])
print(request.GET["class_name"])
print("m_model:",m_model) print("m_model:",m_model)
print("url:",url) print("url:",url)
name = url.split(r'/')[-1] name = url.split(r'/')[-1]
@ -80,7 +89,7 @@ def dlurl(request):
f.close f.close
#返回给前端的图片路径用相对路径,前端用绝对路径反而加载不了图片 #返回给前端的图片路径用相对路径,前端用绝对路径反而加载不了图片
img_path_res = '/static/detected/'+fix+name img_path_res = '/static/detected/'+fix+name
return inference(m_class, m_model, curPath, img_path_res, img_path) return inference(m_class, m_model, curPath, img_path_res, img_path, model_name, class_name)
''' '''
result = adb_shell("ImageDetect/build/ImageDetect {}".format(img_path)) result = adb_shell("ImageDetect/build/ImageDetect {}".format(img_path))
if result[0]==0: if result[0]==0:
@ -99,31 +108,31 @@ def dlurl(request):
if(int(m_class)==1): if(int(m_class)==1):
if(int(m_model)==1): #小模型 if(int(m_model)==1): #小模型
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火 小模型】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【烟火 小模型】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==2): #大模型 if(int(m_model)==2): #大模型
RR = DL.run(weights=(curPath+"/yolov5/v6m6.pt"), source=img_path, imgsz=(1280, 1280), project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/v6m6.pt"), source=img_path, imgsz=(1280, 1280), project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火 大模型】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【烟火 大模型】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==3): #泛模型 if(int(m_model)==3): #泛模型
RR = DL.run(weights=(curPath+"/yolov5/best.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/best.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火 泛模型】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【烟火 泛模型】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==2): if(int(m_class)==2):
RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【一般物体检测】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【一般物体检测】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==3): if(int(m_class)==3):
RR = DL.run(weights=(curPath+"/yolov5/fire_smoke_towercrane.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/fire_smoke_towercrane.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火+塔吊】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【烟火+塔吊】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==4): if(int(m_class)==4):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v3.0.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v3.0.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==5): if(int(m_class)==5):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==6): if(int(m_class)==6):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0m.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0m.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==7): if(int(m_class)==7):
RR = DL.run(weights=(curPath+"/yolov5/birdpecked_unnormal_version1.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/birdpecked_unnormal_version1.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【绝缘子两类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':"【绝缘子两类】"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
''' '''
@ -131,7 +140,7 @@ def dlurl(request):
def home(request): def home(request):
return render(request, 'home.html') return render(request, 'home.html')
def inference(m_class, m_model, curPath, img_path_res, img_path): def inference(m_class, m_model, curPath, img_path_res, img_path, model_name, class_name):
result = adb_shell("ImageDetect/build/ImageDetect {}".format(img_path)) result = adb_shell("ImageDetect/build/ImageDetect {}".format(img_path))
if result[0]==0: if result[0]==0:
cast = result[1].split("||")[0] cast = result[1].split("||")[0]
@ -150,35 +159,44 @@ def inference(m_class, m_model, curPath, img_path_res, img_path):
if(int(m_class)==1): #外破 if(int(m_class)==1): #外破
if(int(m_model)==1): if(int(m_model)==1):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v3.0.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v3.0.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"vehicle_4class_ljp_v3.0.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==2): if(int(m_model)==2):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"vehicle_4class_ljp_v7.0.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==3): if(int(m_model)==3):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0m.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0m.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【外破四类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"vehicle_4class_ljp_v7.0m.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==4): if(int(m_model)==4):
RR = DL.run(weights=(curPath+"/yolov5/fire_smoke_towercrane.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/fire_smoke_towercrane.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火+塔吊】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"fire_smoke_towercrane.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==5):
RR = DL.run(weights=(curPath+"/yolov5/vehicle_4class_ljp_v7.0m6.pt"), source=img_path, project=(curPath+"/static/detected"),imgsz=(1280,1280))
return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"vehicle_4class_ljp_v7.0m6.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==6):
RR=RONNX.main(curPath+"/Darknet2Pytorch2Onnx/hy_vehicle_4class.onnx", curPath+"/Darknet2Pytorch2Onnx/hy_vehicle_4class.names", img_path, (curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"hy_vehicle_4class.onnx"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==7):
RR=RONNX.main(curPath+"/Darknet2Pytorch2Onnx/hy_vehicle_2class.onnx", curPath+"/Darknet2Pytorch2Onnx/hy_vehicle_2class.names", img_path, (curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"hy_vehicle_2class.onnx"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==2): #山火 if(int(m_class)==2): #山火
if(int(m_model)==1): # 小 if(int(m_model)==1): # 小
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火 小模型】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"v3s.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==2): # 大 if(int(m_model)==2): # 大
RR = DL.run(weights=(curPath+"/yolov5/v6m6.pt"), source=img_path, imgsz=(1280, 1280), project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/v6m6.pt"), source=img_path, imgsz=(1280, 1280), project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火 大模型】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"v6m6.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_model)==3): # 范模型 if(int(m_model)==3): # 范模型
RR = DL.run(weights=(curPath+"/yolov5/best.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/best.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【烟火 泛模型】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"best.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==3): # 绝缘子 if(int(m_class)==3): # 绝缘子
if(int(m_model)==1): if(int(m_model)==1):
RR = DL.run(weights=(curPath+"/yolov5/birdpecked_unnormal_version1.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/birdpecked_unnormal_version1.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【绝缘子两类】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"birdpecked_unnormal_version1.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
if(int(m_class)==4): # 一般物体coco if(int(m_class)==4): # 一般物体coco
if(int(m_model)==1): #yolov5s if(int(m_model)==1): #yolov5s
RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected"))
return JsonResponse({'img_name':img_path_res,'code':"【一般物体检测】"+RR+' <br/> '+mesg, 'flag': True}) return JsonResponse({'img_name':img_path_res,'code':class_name+":"+model_name+",模型: "+"yolov5s.pt"+' <br/> '+RR+' <br/> '+mesg, 'flag': True})
Loading…
Cancel
Save