Browse Source

更新

tags/V2.7.3^2^2
chenyukun 1 year ago
parent
commit
2379c9e814
11 changed files with 293 additions and 163 deletions
  1. +31
    -28
      .idea/workspace.xml
  2. +134
    -0
      common/YmlConstant.py
  3. +35
    -6
      concurrency/IntelligentRecognitionProcess.py
  4. +0
    -3
      concurrency/PullStreamThread.py
  5. +0
    -43
      config/ModelConfig.py
  6. +46
    -43
      util/AliyunSdk.py
  7. +2
    -2
      util/Cv2Utils.py
  8. +11
    -10
      util/GPUtils.py
  9. +11
    -10
      util/ImgBaiduSdk.py
  10. +17
    -14
      util/LogUtils.py
  11. +6
    -4
      util/OcrBaiduSdk.py

+ 31
- 28
.idea/workspace.xml View File

@@ -5,14 +5,17 @@
</component>
<component name="ChangeListManager">
<list default="true" id="4f7dccd9-8f92-4a6e-90cc-33890d102263" name="Changes" comment="Changes">
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/concurrency/FeedbackThread.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/FeedbackThread.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/common/YmlConstant.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/YmlConstant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/concurrency/IntelligentRecognitionProcess.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/IntelligentRecognitionProcess.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/service/Dispatcher.py" beforeDir="false" afterPath="$PROJECT_DIR$/service/Dispatcher.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/KafkaUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/KafkaUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/ModelUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/ModelUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/YmlUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/YmlUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/concurrency/PullStreamThread.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/PullStreamThread.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/ModelConfig.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/util/AliyunSdk.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/AliyunSdk.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/Cv2Utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/Cv2Utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/GPUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/GPUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/ImgBaiduSdk.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/ImgBaiduSdk.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/LogUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/LogUtils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/util/OcrBaiduSdk.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/OcrBaiduSdk.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -131,28 +134,28 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;true&quot;,
&quot;WebServerToolWindowPanel.toolwindow.highlight.mappings&quot;: &quot;true&quot;,
&quot;WebServerToolWindowPanel.toolwindow.highlight.symlinks&quot;: &quot;true&quot;,
&quot;WebServerToolWindowPanel.toolwindow.show.date&quot;: &quot;false&quot;,
&quot;WebServerToolWindowPanel.toolwindow.show.permissions&quot;: &quot;false&quot;,
&quot;WebServerToolWindowPanel.toolwindow.show.size&quot;: &quot;false&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/tuoheng/codenew/tuoheng_alg&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;project.structure.last.edited&quot;: &quot;SDK&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2816092&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "true",
"WebServerToolWindowPanel.toolwindow.highlight.mappings": "true",
"WebServerToolWindowPanel.toolwindow.highlight.symlinks": "true",
"WebServerToolWindowPanel.toolwindow.show.date": "false",
"WebServerToolWindowPanel.toolwindow.show.permissions": "false",
"WebServerToolWindowPanel.toolwindow.show.size": "false",
"last_opened_file_path": "D:/tuoheng/codenew/tuoheng_dsp",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"project.structure.last.edited": "SDK",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2816092",
"settings.editor.selected.configurable": "preferences.pluginManager",
"vue.rearranger.settings.migration": "true"
}
}</component>
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\tuoheng\codenew\tuoheng_alg\test\cuda" />
@@ -492,7 +495,7 @@
<workItem from="1683244481879" duration="9171000" />
<workItem from="1683332505792" duration="23325000" />
<workItem from="1683506530261" duration="919000" />
<workItem from="1683507482567" duration="1422000" />
<workItem from="1683507482567" duration="15434000" />
</task>
<servers />
</component>

+ 134
- 0
common/YmlConstant.py View File

@@ -158,3 +158,137 @@ def get_kafka_results_topic(context):

def get_kafka_recording_result_topic(context):
return context["kafka"]["topic"]["dsp-recording-result-topic"]


def get_aliyun_access_key(context):
return context["aliyun"]["access_key"]


def get_aliyun_access_secret(context):
return context["aliyun"]["access_secret"]


def get_aliyun_oss_endpoint(context):
return context["aliyun"]["oss"]["endpoint"]


def get_aliyun_oss_bucket(context):
return context["aliyun"]["oss"]["bucket"]


def get_aliyun_oss_connect_timeout(context):
return context["aliyun"]["oss"]["connect_timeout"]


def get_aliyun_vod_ecsRegionId(context):
return context["aliyun"]["vod"]["ecsRegionId"]


def get_aliyun_vod_cateId(context):
return context["aliyun"]["vod"][context["dsp"]["active"]]["CateId"]


def get_gpu_order(context):
return context["gpu"]["order"]


def get_gpu_limit(context):
return context["gpu"]["limit"]


def get_gpu_maxLoad(context):
return context["gpu"]["maxLoad"]


def get_gpu_maxMemory(context):
return context["gpu"]["maxMemory"]


def get_gpu_includeNan(context):
return context["gpu"]["includeNan"]


def get_gpu_excludeID(context):
return context["gpu"]["excludeID"]


def get_gpu_excludeUUID(context):
return context["gpu"]["excludeUUID"]


def get_baidu_vehicle_APP_ID(context):
return context["baidu"]["vehicle"]["APP_ID"]


def get_baidu_vehicle_API_KEY(context):
return context["baidu"]["vehicle"]["API_KEY"]


def get_baidu_vehicle_SECRET_KEY(context):
return context["baidu"]["vehicle"]["SECRET_KEY"]


def get_baidu_person_APP_ID(context):
return context["baidu"]["person"]["APP_ID"]


def get_baidu_person_API_KEY(context):
return context["baidu"]["person"]["API_KEY"]


def get_baidu_person_SECRET_KEY(context):
return context["baidu"]["person"]["SECRET_KEY"]


def get_baidu_ocr_APP_ID(context):
return context["baidu"]["orc"]["APP_ID"]


def get_baidu_ocr_API_KEY(context):
return context["baidu"]["orc"]["API_KEY"]


def get_baidu_ocr_SECRET_KEY(context):
return context["baidu"]["orc"]["SECRET_KEY"]


def get_log_base_path(context):
return context["log"]["base_path"]


def get_log_enable_file(context):
return context["log"]["enable_file_log"]


def get_log_log_name(context):
return context["log"]["log_name"]


def get_log_rotation(context):
return context["log"]["rotation"]


def get_log_retention(context):
return context["log"]["retention"]


def get_log_log_fmt(context):
return context["log"]["log_fmt"]


def get_log_level(context):
return context["log"]["level"]


def get_log_enqueue(context):
return context["log"]["enqueue"]


def get_log_encoding(context):
return context["log"]["encoding"]


def get_log_enable_stderr(context):
return context["log"]["enable_stderr"]



+ 35
- 6
concurrency/IntelligentRecognitionProcess.py View File

@@ -433,6 +433,12 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
ExceptionType.SERVICE_INNER_EXCEPTION.value[1],
analyse_time=TimeUtils.now_date_to_str())}
finally:
if ttt:
ttt.shutdown(False)
if tt:
tt.shutdown(False)
if t:
t.shutdown(False)
if cv2tool:
cv2tool.close()
if pullProcess is not None and pullProcess.is_alive():
@@ -577,6 +583,12 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
ExceptionType.SERVICE_INNER_EXCEPTION.value[1],
analyse_time=TimeUtils.now_date_to_str())}
finally:
if ttt:
ttt.shutdown(False)
if tt:
tt.shutdown(False)
if t:
t.shutdown(False)
if cv2tool is not None:
cv2tool.close()
if pullProcess is not None and pullProcess.is_alive():
@@ -609,23 +621,38 @@ class PhotosIntelligentRecognitionProcess(IntelligentRecognitionProcess):
if dataBack is None or dataBack.get("plateImage") is None or len(dataBack.get("plateImage")) == 0:
result = orc.license_plate_recognition(image, self.msg.get("request_id"))
score = ''
if result is None or result.get("words_result") is None:
if result is None or result.get("words_result") is None or len(result.get("words_result")) == 0:
logger.error("车牌识别为空: {}", result)
carCode = ''
else:
carCode = result.get("words_result").get("number")
for word in result.get("words_result"):
if word is not None and word.get("number") is not None:
if len(carCode) == 0:
carCode = word.get("number")
else:
carCode = carCode + "," + word.get("number")
else:
result = orc.license_plate_recognition(dataBack.get("plateImage")[0], self.msg.get("request_id"))
score = dataBack.get("plateImage")[1]
if result is None or result.get("words_result") is None:
if result is None or result.get("words_result") is None or len(result.get("words_result")) == 0:
result = orc.license_plate_recognition(image, self.msg.get("request_id"))
if result is None or result.get("words_result") is None:
if result is None or result.get("words_result") is None or len(result.get("words_result")) == 0:
logger.error("车牌识别为空: {}", result)
carCode = ''
else:
carCode = result.get("words_result").get("number")
for word in result.get("words_result"):
if word is not None and word.get("number") is not None:
if len(carCode) == 0:
carCode = word.get("number")
else:
carCode = carCode + "," + word.get("number")
else:
carCode = result.get("words_result").get("number")
for word in result.get("words_result"):
if word is not None and word.get("number") is not None:
if len(carCode) == 0:
carCode = word.get("number")
else:
carCode = carCode + "," + word.get("number")
if len(carCode) > 0:
plate_result = {'type': str(3), 'modelCode': model_type_code, 'carUrl': imageUrl,
'carCode': carCode,
@@ -1236,6 +1263,8 @@ class ScreenRecordingProcess(Process):
ExceptionType.SERVICE_INNER_EXCEPTION.value[0],
ExceptionType.SERVICE_INNER_EXCEPTION.value[1])}
finally:
if t:
t.shutdown(False)
if cv2tool:
cv2tool.close()
if hb:

+ 0
- 3
concurrency/PullStreamThread.py View File

@@ -3,12 +3,9 @@ import time
from queue import Queue
from threading import Thread

import GPUtil
from loguru import logger

from entity.FeedBack import recording_feedback
from enums.ExceptionEnum import ExceptionType
from enums.RecordingStatusEnum import RecordingStatus
from exception.CustomerException import ServiceException
from util import GPUtils
from util.Cv2Utils import Cv2Util

+ 0
- 43
config/ModelConfig.py View File

@@ -1,43 +0,0 @@
# -*- coding: utf-8 -*-
import sys

sys.path.extend(['..', '../AIlib'])
from segutils.segmodel import SegModel, get_largest_contours
from utils.torch_utils import select_device
from models.experimental import attempt_load
from utilsK.queRiver import get_labelnames, get_label_arrays, post_process_
from AI import AI_process, AI_process_forest, get_postProcess_para


class ModelConfig():
def __init__(self):
postFile = '../AIlib/conf/para.json'
self.conf_thres, self.iou_thres, self.classes, self.rainbows = get_postProcess_para(postFile)


class SZModelConfig(ModelConfig):

def __init__(self):
super(SZModelConfig, self).__init__()
labelnames = "../AIlib/weights/yolov5/class8/labelnames.json" ##对应类别表
self.names = get_labelnames(labelnames)
self.label_arraylist = get_label_arrays(self.names, self.rainbows, outfontsize=40,
fontpath="../AIlib/conf/platech.ttf")


class LCModelConfig(ModelConfig):
def __init__(self):
super(LCModelConfig, self).__init__()
labelnames = "../AIlib/weights/forest/labelnames.json"
self.names = get_labelnames(labelnames)
self.label_arraylist = get_label_arrays(self.names, self.rainbows, outfontsize=40, fontpath="../AIlib/conf/platech.ttf")


class RFModelConfig(ModelConfig):
def __init__(self):
super(RFModelConfig, self).__init__()
labelnames = "../AIlib/weights/road/labelnames.json"
self.names = get_labelnames(labelnames)
imageW = 1536
outfontsize=int(imageW/1920*40)
self.label_arraylist = get_label_arrays(self.names, self.rainbows, outfontsize=outfontsize, fontpath="../AIlib/conf/platech.ttf")

+ 46
- 43
util/AliyunSdk.py View File

@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
import oss2
import time

from aliyunsdkvod.request.v20170321.GetPlayInfoRequest import GetPlayInfoRequest

from common import YmlConstant
from exception.CustomerException import ServiceException
from enums.ExceptionEnum import ExceptionType
import json
@@ -10,113 +15,112 @@ from voduploadsdk.AliyunVodUploader import AliyunVodUploader
from voduploadsdk.UploadVideoRequest import UploadVideoRequest


class AliyunOssSdk():
class AliyunOssSdk:

def __init__(self, content, logger, requestId):
self.content = content
def __init__(self, context, log, requestId):
self.__context = context
self.bucket = None
self.logger = logger
self.requestId = requestId
self.__logger = log
self.__requestId = requestId

def get_oss_bucket(self):
if self.bucket is None:
self.logger.info("初始化oss桶, requestId:{}", self.requestId)
auth = oss2.Auth(self.content["aliyun"]["access_key"], self.content["aliyun"]["access_secret"])
self.bucket = oss2.Bucket(auth,
self.content["aliyun"]["oss"]["endpoint"],
self.content["aliyun"]["oss"]["bucket"],
connect_timeout=self.content["aliyun"]["oss"]["connect_timeout"])
self.__logger.info("初始化oss桶, requestId:{}", self.__requestId)
auth = oss2.Auth(YmlConstant.get_aliyun_access_key(self.__context),
YmlConstant.get_aliyun_access_secret(self.__context))
self.bucket = oss2.Bucket(auth, YmlConstant.get_aliyun_oss_endpoint(self.__context),
YmlConstant.get_aliyun_oss_bucket(self.__context),
connect_timeout=YmlConstant.get_aliyun_oss_connect_timeout(self.__context))

def sync_upload_file(self, updatePath, fileByte):
self.logger.info("开始上传文件到oss, requestId:{}", self.requestId)
self.__logger.info("开始上传文件到oss, requestId:{}", self.__requestId)
self.get_oss_bucket()
MAX_RETRIES = 3
retry_count = 0
while True:
try:
self.bucket.put_object(updatePath, fileByte)
self.logger.info("上传文件到oss成功! requestId:{}", self.requestId)
self.__logger.info("上传文件到oss成功! requestId:{}", self.__requestId)
break
except Exception as e:
retry_count += 1
time.sleep(1)
self.logger.info("上传文件到oss失败, 重试次数:{}, requestId:{}", retry_count, self.requestId)
self.__logger.info("上传文件到oss失败, 重试次数:{}, requestId:{}", retry_count, self.__requestId)
if retry_count > MAX_RETRIES:
self.logger.exception("上传文件到oss重试失败:{}, requestId:{}", e, self.requestId)
self.__logger.exception("上传文件到oss重试失败:{}, requestId:{}", e, self.__requestId)
raise e


class ThAliyunVodSdk():
class ThAliyunVodSdk:

def __init__(self, content, logger, requestId):
self.content = content
self.logger = logger
self.requestId = requestId
def __init__(self, context, log, requestId):
self.__context = context
self.__logger = log
self.__requestId = requestId

def init_vod_client(self, accessKeyId, accessKeySecret):
regionId = self.content["aliyun"]["vod"]["ecsRegionId"]
regionId = YmlConstant.get_aliyun_vod_ecsRegionId(self.__context)
return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=30)

def get_play_info(self, videoId):
self.logger.info("开始获取视频地址,videoId:{}, requestId:{}", videoId, self.requestId)
self.__logger.info("开始获取视频地址,videoId:{}, requestId:{}", videoId, self.__requestId)
start = time.time()
while True:
try:
clt = self.init_vod_client(self.content["aliyun"]["access_key"],
self.content["aliyun"]["access_secret"])
request = GetPlayInfoRequest.GetPlayInfoRequest()
clt = self.init_vod_client(YmlConstant.get_aliyun_access_key(self.__context),
YmlConstant.get_aliyun_access_secret(self.__context))
request: GetPlayInfoRequest = GetPlayInfoRequest.GetPlayInfoRequest()
request.set_accept_format('JSON')
request.set_VideoId(videoId)
request.set_AuthTimeout(3600 * 5)
response = json.loads(clt.do_action_with_exception(request))
play_url = response["PlayInfoList"]["PlayInfo"][0]["PlayURL"]
self.logger.info("获取视频地址成功,视频地址: {}, requestId: {}", play_url, self.requestId)
self.__logger.info("获取视频地址成功,视频地址: {}, requestId: {}", play_url, self.__requestId)
return play_url
except Exception as e:
self.logger.error("获取视频地址失败,5秒后重试, requestId: {}", self.requestId)
self.__logger.error("获取视频地址失败,5秒后重试, requestId: {}", self.__requestId)
time.sleep(5)
current_time = time.time()
if "HTTP Status: 403" not in str(e):
self.logger.exception("获取视频地址失败: {}, requestId: {}", e, self.requestId)
self.__logger.exception("获取视频地址失败: {}, requestId: {}", e, self.__requestId)
raise ServiceException(ExceptionType.GET_VIDEO_URL_EXCEPTION.value[0],
ExceptionType.GET_VIDEO_URL_EXCEPTION.value[1])
if "HTTP Status: 403" in str(e) and ("UploadFail" in str(e) or "TranscodeFail" in str(e)):
self.logger.exception("获取视频地址失败: {}, requestId: {}", e, self.requestId)
self.__logger.exception("获取视频地址失败: {}, requestId: {}", e, self.__requestId)
raise ServiceException(ExceptionType.GET_VIDEO_URL_EXCEPTION.value[0],
ExceptionType.GET_VIDEO_URL_EXCEPTION.value[1])
diff_time = current_time - start
if diff_time > 60 * 60 * 2:
self.logger.exception("获取视频地址失败超时异常: {},超时时间:{}, requestId: {}", e, diff_time,
self.requestId)
self.__logger.exception("获取视频地址失败超时异常: {},超时时间:{}, requestId: {}", e, diff_time,
self.__requestId)
raise ServiceException(ExceptionType.GET_VIDEO_URL_TIMEOUT_EXCEPTION.value[0],
ExceptionType.GET_VIDEO_URL_TIMEOUT_EXCEPTION.value[1])

def upload_local_video(self, filePath, file_title, storageLocation=None):
self.logger.info("开始执行vod视频上传, filePath: {}, requestId: {}", filePath, self.requestId)
uploader = AliyunVodUploader(self.content["aliyun"]["access_key"], self.content["aliyun"]["access_secret"])
uploadVideoRequest = UploadVideoRequest(filePath, file_title)
self.logger.info("视频分类:{}", self.content["aliyun"]["vod"][self.content["dsp"]["active"]]["CateId"])
uploadVideoRequest.setCateId(self.content["aliyun"]["vod"][self.content["dsp"]["active"]]["CateId"])
def upload_local_video(self, filePath, file_title):
self.__logger.info("开始执行vod视频上传, filePath: {}, requestId: {}", filePath, self.__requestId)
uploader = AliyunVodUploader(YmlConstant.get_aliyun_access_key(self.__context),
YmlConstant.get_aliyun_access_secret(self.__context))
uploadVideoRequest: UploadVideoRequest = UploadVideoRequest(filePath, file_title)
self.__logger.info("视频分类:{}", YmlConstant.get_aliyun_vod_cateId(self.__context))
uploadVideoRequest.setCateId(YmlConstant.get_aliyun_vod_cateId(self.__context))
# 可以设置视频封面,如果是本地或网络图片可使用UploadImageRequest上传图片到视频点播,获取到ImageURL
# ImageURL示例:https://example.com/sample-****.jpg
# uploadVideoRequest.setCoverURL('<your Image URL>')
# 标签
# uploadVideoRequest.setTags('tag1,tag2')
if storageLocation:
uploadVideoRequest.setStorageLocation(storageLocation)
MAX_RETRIES = 3
retry_count = 0
while True:
try:
result = uploader.uploadLocalVideo(uploadVideoRequest)
self.logger.info("vod视频上传成功, videoId:{}, requestId:{}", result.get("VideoId"), self.requestId)
self.__logger.info("vod视频上传成功, videoId:{}, requestId:{}", result.get("VideoId"), self.__requestId)
return result.get("VideoId")
except AliyunVodException as e:
retry_count += 1
time.sleep(3)
self.logger.error("vod视频上传失败,重试次数:{}, requestId:{}", retry_count, self.requestId)
self.__logger.error("vod视频上传失败,重试次数:{}, requestId:{}", retry_count, self.__requestId)
if retry_count >= MAX_RETRIES:
self.logger.exception("vod视频上传重试失败: {}, requestId:{}", e.message, self.requestId)
self.__logger.exception("vod视频上传重试失败: {}, requestId:{}", e.message, self.__requestId)
raise ServiceException(ExceptionType.SERVICE_INNER_EXCEPTION.value[0],
ExceptionType.SERVICE_INNER_EXCEPTION.value[1])

@@ -125,4 +129,3 @@ class ThAliyunVodSdk():
if videoId is None or len(videoId) == 0:
return None
return self.get_play_info(videoId)


+ 2
- 2
util/Cv2Utils.py View File

@@ -14,7 +14,7 @@ from enums.ExceptionEnum import ExceptionType

class Cv2Util():

def __init__(self, pullUrl=None, pushUrl=None, orFilePath=None, aiFilePath=None, requestId=None, content=None,
def __init__(self, pullUrl=None, pushUrl=None, orFilePath=None, aiFilePath=None, requestId=None, context=None,
gpu_ids=None, log=logger):
self.pullUrl = pullUrl
self.pushUrl = pushUrl
@@ -38,7 +38,7 @@ class Cv2Util():
self.p_push_retry_num = 0
self.isGpu = False
self.read_w_h = None
self.content = content
self.context = context
if gpu_ids is not None and len(gpu_ids) > 0:
self.isGpu = True


+ 11
- 10
util/GPUtils.py View File

@@ -1,5 +1,6 @@
import GPUtil

from common import YmlConstant
from enums.ExceptionEnum import ExceptionType
from exception.CustomerException import ServiceException

@@ -18,14 +19,14 @@ from exception.CustomerException import ServiceException
# excludeUUIDexcludeID-除了它使用 UUID 之外,其他相同。(默认 = [])
# 输出
# deviceIDs - 所有可用 GPU 设备 ID 的列表。如果当前负载和内存使用量分别小于maxLoad和maxMemory,则认为 GPU 可用。该列表是根据 排序的order。返回的设备 ID 的最大数量由 限制limit。
def get_gpu_ids(content):
deviceIDs = GPUtil.getAvailable(order=content["gpu"]["order"],
limit=int(content["gpu"]["limit"]),
maxLoad=float(content["gpu"]["maxLoad"]),
maxMemory=float(content["gpu"]["maxMemory"]),
includeNan=content["gpu"]["includeNan"],
excludeID=content["gpu"]["excludeID"],
excludeUUID=content["gpu"]["excludeUUID"])
def get_gpu_ids(context):
deviceIDs = GPUtil.getAvailable(order=YmlConstant.get_gpu_order(context),
limit=int(YmlConstant.get_gpu_limit(context)),
maxLoad=float(YmlConstant.get_gpu_maxLoad(context)),
maxMemory=float(YmlConstant.get_gpu_maxMemory(context)),
includeNan=YmlConstant.get_gpu_includeNan(context),
excludeID=YmlConstant.get_gpu_excludeID(context),
excludeUUID=YmlConstant.get_gpu_excludeUUID(context))
return deviceIDs


@@ -40,8 +41,8 @@ def get_first_gpu_name():
return gps[0].name


def check_gpu_resource(content):
gpu_ids = get_gpu_ids(content)
def check_gpu_resource(context):
gpu_ids = get_gpu_ids(context)
if gpu_ids is None or len(gpu_ids) == 0 or (0 not in gpu_ids and str(0) not in gpu_ids):
raise ServiceException(ExceptionType.NO_GPU_RESOURCES.value[0],
ExceptionType.NO_GPU_RESOURCES.value[1])

+ 11
- 10
util/ImgBaiduSdk.py View File

@@ -2,6 +2,7 @@ import time
from aip import AipImageClassify, AipBodyAnalysis
from loguru import logger

from common import YmlConstant
from enums.BaiduSdkEnum import BAIDUERRORDATA
from enums.ExceptionEnum import ExceptionType
from exception.CustomerException import ServiceException
@@ -10,17 +11,17 @@ from util.ImageUtils import url2Content

class AipImageClassifyClient:

def __init__(self, content):
self.__content = content
def __init__(self, context):
self.__context = context
self.__client = None
self.init_client()
# self.lock = Lock()

def init_client(self):
if self.__client is None:
self.__client = AipImageClassify(str(self.__content["baidu"]["vehicle"]["APP_ID"]),
self.__content["baidu"]["vehicle"]["API_KEY"],
self.__content["baidu"]["vehicle"]["SECRET_KEY"])
self.__client = AipImageClassify(str(YmlConstant.get_baidu_vehicle_APP_ID(self.__context)),
YmlConstant.get_baidu_vehicle_API_KEY(self.__context),
YmlConstant.get_baidu_vehicle_SECRET_KEY(self.__context))

'''
车辆检测
@@ -135,17 +136,17 @@ class AipImageClassifyClient:

class AipBodyAnalysisClient:

def __init__(self, content):
self.__content = content
def __init__(self, context):
self.__context = context
self.__client = None
self.init_client()
# self.lock = Lock()

def init_client(self):
if self.__client is None:
self.__client = AipBodyAnalysis(str(self.__content["baidu"]["person"]["APP_ID"]),
self.__content["baidu"]["person"]["API_KEY"],
self.__content["baidu"]["person"]["SECRET_KEY"])
self.__client = AipBodyAnalysis(str(YmlConstant.get_baidu_person_APP_ID(self.__context)),
YmlConstant.get_baidu_person_API_KEY(self.__context),
YmlConstant.get_baidu_person_SECRET_KEY(self.__context))

'''
人体检测与属性识别

+ 17
- 14
util/LogUtils.py View File

@@ -3,26 +3,29 @@ import sys
import os
from loguru import logger

from common import YmlConstant


# 初始化日志配置
def init_log(content):
def init_log(context):
# 判断日志文件是否存在,不存在创建
if not os.path.exists(content["log"]["base_path"]):
os.makedirs(content["log"]["base_path"])
base_path = YmlConstant.get_log_base_path(context)
if not os.path.exists(base_path):
os.makedirs(base_path)
# 移除日志设置
logger.remove(handler_id=None)
# 打印日志到文件
if content["log"]["enable_file_log"]:
logger.add(content["log"]["base_path"] + content["log"]["log_name"],
rotation=content["log"]["rotation"],
retention=content["log"]["retention"],
format=content["log"]["log_fmt"],
level=content["log"]["level"],
enqueue=content["log"]["enqueue"],
encoding=content["log"]["encoding"])
if YmlConstant.get_log_enable_file(context):
logger.add(base_path + YmlConstant.get_log_log_name(context),
rotation=YmlConstant.get_log_rotation(context),
retention=YmlConstant.get_log_retention(context),
format=YmlConstant.get_log_log_fmt(context),
level=YmlConstant.get_log_level(context),
enqueue=YmlConstant.get_log_enqueue(context),
encoding=YmlConstant.get_log_encoding(context))
# 控制台输出
if content["log"]["enable_stderr"]:
if YmlConstant.get_log_enable_stderr(context):
logger.add(sys.stderr,
format=content["log"]["log_fmt"],
level=content["log"]["level"],
format=YmlConstant.get_log_log_fmt(context),
level=YmlConstant.get_log_level(context),
enqueue=True)

+ 6
- 4
util/OcrBaiduSdk.py View File

@@ -4,6 +4,7 @@ import cv2
from aip import AipOcr
from loguru import logger

from common import YmlConstant
from enums.BaiduSdkEnum import BAIDUERRORDATA
from enums.ExceptionEnum import ExceptionType
from exception.CustomerException import ServiceException
@@ -11,15 +12,16 @@ from exception.CustomerException import ServiceException

class OcrBaiduSdk:

def __init__(self, content):
self.content = content
def __init__(self, context):
self.__context = context
self.client = None
self.init_client()

def init_client(self):
if self.client is None:
self.client = AipOcr(str(self.content["baidu"]["orc"]["APP_ID"]), self.content["baidu"]["orc"]["API_KEY"],
self.content["baidu"]["orc"]["SECRET_KEY"])
self.client = AipOcr(str(YmlConstant.get_baidu_ocr_APP_ID(self.__context)),
YmlConstant.get_baidu_ocr_API_KEY(self.__context),
YmlConstant.get_baidu_ocr_SECRET_KEY(self.__context))

'''
{

Loading…
Cancel
Save