|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import re
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.http import HttpResponse, JsonResponse
|
|
|
|
|
import os
|
|
|
|
|
@ -9,9 +10,8 @@ import requests, os, json
|
|
|
|
|
def upload(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
file = request.FILES.get('file') #获取前端上传的文件
|
|
|
|
|
print("************")
|
|
|
|
|
print(file)
|
|
|
|
|
print("************")
|
|
|
|
|
m_model=request.POST.get('model')
|
|
|
|
|
m_class=request.POST.get('class')
|
|
|
|
|
fix = datetime.now().strftime('%Y%m%d%H%M%S%f')+'1' #给文件加前缀防止文件名重复
|
|
|
|
|
#以下用绝对路径存储文件,之前我用相对路径一直写不对
|
|
|
|
|
curPath = os.path.abspath( os.path.dirname( __file__ ) )
|
|
|
|
|
@ -23,13 +23,22 @@ def upload(request):
|
|
|
|
|
for i in file.chunks():
|
|
|
|
|
f.write(i)
|
|
|
|
|
f.close()
|
|
|
|
|
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, 'flag': True})
|
|
|
|
|
if(int(m_class)==1):
|
|
|
|
|
if(int(m_model)==1): #小模型
|
|
|
|
|
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))
|
|
|
|
|
return JsonResponse({'img_name':img_path_res,'code':"【烟火 小模型】"+RR, 'flag': True})
|
|
|
|
|
if(int(m_model)==2): #大模型
|
|
|
|
|
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, 'flag': True})
|
|
|
|
|
if(int(m_class)==2):
|
|
|
|
|
RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected"))
|
|
|
|
|
return JsonResponse({'img_name':img_path_res,'code':"【一般物体检测】"+RR, 'flag': True})
|
|
|
|
|
|
|
|
|
|
def dlurl(request):
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
url = request.GET["url"] #获取前端上传的文件
|
|
|
|
|
m_model=request.GET["model"]
|
|
|
|
|
m_class=request.GET["class"]
|
|
|
|
|
print(m_model)
|
|
|
|
|
print(url)
|
|
|
|
|
name = url.split(r'/')[-1]
|
|
|
|
|
@ -46,12 +55,16 @@ def dlurl(request):
|
|
|
|
|
f.close
|
|
|
|
|
#返回给前端的图片路径用相对路径,前端用绝对路径反而加载不了图片
|
|
|
|
|
img_path_res = '/static/detected/'+fix+name
|
|
|
|
|
if(int(m_model)==1): #小模型
|
|
|
|
|
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))
|
|
|
|
|
return JsonResponse({'img_name':img_path_res,'code':"【小模型】"+RR, 'flag': True})
|
|
|
|
|
if(int(m_model)==2): #大模型
|
|
|
|
|
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, 'flag': True})
|
|
|
|
|
if(int(m_class)==1):
|
|
|
|
|
if(int(m_model)==1): #小模型
|
|
|
|
|
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))
|
|
|
|
|
return JsonResponse({'img_name':img_path_res,'code':"【烟火 小模型】"+RR, 'flag': True})
|
|
|
|
|
if(int(m_model)==2): #大模型
|
|
|
|
|
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, 'flag': True})
|
|
|
|
|
if(int(m_class)==2):
|
|
|
|
|
RR = DL.run(weights=(curPath+"/yolov5/yolov5s.pt"), source=img_path, project=(curPath+"/static/detected"))
|
|
|
|
|
return JsonResponse({'img_name':img_path_res,'code':"【一般物体检测】"+RR, 'flag': True})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|