Пример #1
0
    def createYoloDetectThread(self, config):

        # 为每个检测线程分配sessionId
        sessionId = randomUtils.getRandomStr()
        # 加载模型
        dmVersionBean = modelVersionService.getDMVersionBean(
            config['dmtvid'])[0]
        modelConfig = {}
        modelConfig["weights"] = dmVersionBean['ckptModelSavePath']
        modelConfig["device"] = ''
        # 创建检测对象
        detectThread = detectServiceThread(modelConfig)

        # 加载检测参数
        detectConfig = detectConfigUtils.getBasicDetectConfig(
            str(config['source'].replace(" ", "")),
            outPath=ConstantUtils.videoDetectOut + sessionId)

        detectThread.setDetectConfig(detectConfig)

        # 开始线程
        detectThread.start()

        yoloDetectThreadMap[sessionId] = detectThread

        #把sessionId放入到redis中供监控线程监控
        ConstantUtils.updateDetectSessionTime(sessionId)

        result = {
            ConstantUtils.serviceSessionId: sessionId,
            ConstantUtils.videoPlayUrl:
            ConstantUtils.streamPlayPrefix + sessionId
        }

        return resultPackerUtils.packCusResult(result)
    def detectImage(self, dtsServiceKey, dtsSecret, threshold, imgData):
        FileNewName = fileUtils.getRandomName(imgData.filename)
        savedPath = ConstantUtils.singleImgDetectSource + FileNewName
        print("图片保存路径:" + savedPath)
        # 保存图片
        imgData.save(savedPath)

        # 获取当前的模型
        detectIns = yoloDetectServiceImpl.getDetectServiceInstance(
            dtsServiceKey)
        if detectIns is not None:
            print("找到相关检测模型...")
            detectConfig = detectConfigUtils.getBasicDetectConfig(
                source=savedPath, outPath=ConstantUtils.singleImgDetectOut)
            detectResult = detectIns.detect(detectConfig)

            result = {
                "imagePath":
                ConstantUtils.imageItemPrefix + "singleImgDetectOut_" +
                FileNewName,
                "detectResult":
                detectResult
            }

            return resultPackerUtils.packCusResult(result)
        else:
            return resultPackerUtils.packErrorMsg(
                resultPackerUtils.EC_NO_EVALUATE_SESSION)
Пример #3
0
    def getVideoDetectResult(self, serviceSessionId, threshold, detectVideo):

        FileNewName = fileUtils.getRandomName(detectVideo.filename)
        savedPath = ConstantUtils.videoDetectSource + FileNewName
        loggerUtils.info("视频保存路径:" + savedPath)
        # 保存图片
        detectVideo.save(savedPath)

        # 获取当前的模型
        detectServiceIns = yoloDetect.getDetectServiceInstance(
            serviceSessionId)
        if detectServiceIns is not None:
            loggerUtils.info("找到相关检测模型...")
            detectConfig = detectConfigUtils.getBasicDetectConfig(
                source=savedPath, outPath=ConstantUtils.videoDetectOut)
            detectServiceIns.detect(detectConfig)

            detectRecordItem = detectRecord(
                videoSavedPath=ConstantUtils.videoDetectOut + FileNewName)
            detectRecordItem.save()

            result = {
                ConstantUtils.videoPlayUrl:
                ConstantUtils.videoPlayPrefix + str(detectRecordItem.dereid)
            }

            return resultPackerUtils.packCusResult(result)
        else:

            return resultPackerUtils.packErrorMsg(
                resultPackerUtils.EC_NO_EVALUATE_SESSION)
Пример #4
0
    def userLogin(self, data):
        userList = userBean.objects(userLoginAccount=data['userLoginAccount'],
                                    userLoginPass=data['userLoginPass'])

        if userList != None and len(userList) > 0:

            resultMap = {"userName": userList[0]['userName']}
            session["userId"] = userList[0]['uid']
            return resultPackerUtils.packCusResult(resultMap)
        else:
            return resultPackerUtils.packErrorMsg(
                resultPackerUtils.EC_NAME_PASS_ERROR)
Пример #5
0
    def getAllCVTaskTypes(self):

        taskTypeList=[
            {
                "cvTaskType":ConstantUtils.CV_TASK_TYPE_CLASSIFY,
                "cvTaskName":ConstantUtils.getCVTaskTypaName(ConstantUtils.CV_TASK_TYPE_CLASSIFY)
            },
            {
                "cvTaskType": ConstantUtils.CV_TASK_TYPE_DETECT,
                "cvTaskName": ConstantUtils.getCVTaskTypaName(ConstantUtils.CV_TASK_TYPE_DETECT)
            }
        ]

        return resultPackerUtils.packCusResult({"taskTypeList":taskTypeList})
Пример #6
0
    def launchYoloDetectService(self,
                                sessionId=None,
                                dmtvid=None,
                                isWatch=False):
        #如果模型版本为空 直接返回
        if dmtvid is None:
            return None
        #判断是不是重复加载
        if sessionDmtvMap.keys().__contains__(sessionId):
            if sessionDmtvMap[sessionId] == dmtvid:
                return
        # 根据版本ID获取模型地址
        dmVersionBean = modelVersionService.getDMVersionBean(dmtvid)[0]

        modelConfig = {}
        modelConfig["weights"] = dmVersionBean['ckptModelSavePath']
        modelConfig["device"] = ''

        if modelConfig["weights"] == None:
            return
        detectSerIns = detectServiceThread(modelConfig)

        if sessionId is None:
            sessionId = randomUtils.getRandomStr()

        yoloDetectThreadMap[sessionId] = detectSerIns
        sessionDmtvMap[sessionId] = dmtvid

        # 把sessionId放入到redis中供监控线程监控
        if isWatch:
            ConstantUtils.updateDetectSessionTime(sessionId)

        loggerUtils.info("模型启动完毕...." + sessionId)
        loggerUtils.info("sessions of detectThreadMap:" +
                         str(yoloDetectThreadMap.keys()))

        resultMap = {ConstantUtils.serviceSessionId: sessionId}

        return resultPackerUtils.packCusResult(resultMap)
Пример #7
0
    def getTrainStatistics(self, queryData):
        dataList = detectModelTrainStatistics.objects(
            dmtvid=queryData["dmtvid"], state=ConstantUtils.DATA_STATUS_ACTIVE)
        metrics_mAP_5,metrics_mAP,metrics_precision,metrics_recall=[],[],[],[]
        train_box_loss, train_cls_loss, train_obj_loss = [], [], []
        val_box_loss, val_cls_loss, val_obj_loss = [], [], []
        x_lr0, x_lr1, x_lr2 = [], [], []
        for item in dataList:
            metrics_mAP_5.append(item['metrics_mAP_5'])
            metrics_mAP.append(item['metrics_mAP'])
            metrics_precision.append(item['metrics_precision'])
            metrics_recall.append(item['metrics_recall'])
            train_box_loss.append(item['train_box_loss'])
            train_cls_loss.append(item['train_cls_loss'])
            train_obj_loss.append(item['train_obj_loss'])
            val_box_loss.append(item['val_box_loss'])
            val_cls_loss.append(item['val_cls_loss'])
            val_obj_loss.append(item['val_obj_loss'])
            x_lr0.append(item['x_lr0'])
            x_lr1.append(item['x_lr1'])
            x_lr2.append(item['x_lr2'])

        statisList = []

        statisList.append({
            "statisGroup": "metrics",
            "statisName": "metrics_mAP_5",
            "statisValue": metrics_mAP_5
        })

        statisList.append({
            "statisGroup": "metrics",
            "statisName": "metrics_mAP",
            "statisValue": metrics_mAP
        })

        statisList.append({
            "statisGroup": "metrics",
            "statisName": "metrics_precision",
            "statisValue": metrics_precision
        })

        statisList.append({
            "statisGroup": "metrics",
            "statisName": "metrics_recall",
            "statisValue": metrics_recall
        })

        statisList.append({
            "statisGroup": "train",
            "statisName": "train_box_loss",
            "statisValue": train_box_loss
        })

        statisList.append({
            "statisGroup": "train",
            "statisName": "train_cls_loss",
            "statisValue": train_cls_loss
        })

        statisList.append({
            "statisGroup": "train",
            "statisName": "train_obj_loss",
            "statisValue": train_obj_loss
        })

        statisList.append({
            "statisGroup": "val",
            "statisName": "val_box_loss",
            "statisValue": val_box_loss
        })

        statisList.append({
            "statisGroup": "val",
            "statisName": "val_cls_loss",
            "statisValue": val_cls_loss
        })

        statisList.append({
            "statisGroup": "val",
            "statisName": "val_obj_loss",
            "statisValue": val_obj_loss
        })

        statisList.append({
            "statisGroup": "x",
            "statisName": "x_lr0",
            "statisValue": x_lr0
        })

        statisList.append({
            "statisGroup": "x",
            "statisName": "x_lr1",
            "statisValue": x_lr1
        })
        statisList.append({
            "statisGroup": "x",
            "statisName": "x_lr2",
            "statisValue": x_lr2
        })

        resultMap = {"dataList": statisList}

        return resultPackerUtils.packCusResult(resultMap)