Browse Source

Merge branch 'develop' of gitadmin/tuoheng_alg into release

tags/V2.8.0^2
chenyukun 1 year ago
parent
commit
0041d6327e
11 changed files with 486 additions and 201 deletions
  1. +71
    -46
      .idea/workspace.xml
  2. +10
    -2
      concurrency/FeedbackThread.py
  3. +8
    -0
      concurrency/FileUploadThread.py
  4. +7
    -7
      concurrency/HeartbeatThread.py
  5. +11
    -10
      concurrency/IntelligentRecognitionProcess.py
  6. +1
    -0
      concurrency/PullVideoStreamProcess.py
  7. +4
    -0
      enums/ModelTypeEnum.py
  8. +19
    -18
      service/Dispatcher.py
  9. +26
    -13
      test/线程/Test.py
  10. +3
    -0
      util/Cv2Utils.py
  11. +326
    -105
      util/ModelUtils.py

+ 71
- 46
.idea/workspace.xml View File

@@ -6,9 +6,15 @@
<component name="ChangeListManager">
<list default="true" id="4f7dccd9-8f92-4a6e-90cc-33890d102263" name="Changes" comment="Changes">
<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$/concurrency/FileUploadThread.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/FileUploadThread.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/concurrency/HeartbeatThread.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/HeartbeatThread.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/concurrency/IntelligentRecognitionProcess.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/IntelligentRecognitionProcess.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/concurrency/PullVideoStreamProcess.py" beforeDir="false" afterPath="$PROJECT_DIR$/concurrency/PullVideoStreamProcess.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/enums/ModelTypeEnum.py" beforeDir="false" afterPath="$PROJECT_DIR$/enums/ModelTypeEnum.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/service/Dispatcher.py" beforeDir="false" afterPath="$PROJECT_DIR$/service/Dispatcher.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/线程/Test.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/线程/Test.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/ModelUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/util/ModelUtils.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@@ -128,29 +134,29 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<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_alg",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"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 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;nodejs_package_manager_path&quot;: &quot;npm&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>
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\tuoheng\codenew\tuoheng_alg\enums" />
@@ -167,7 +173,7 @@
<recent name="D:\tuoheng\codenew\tuoheng_alg\font" />
</key>
</component>
<component name="RunManager" selected="Python.test1">
<component name="RunManager" selected="Python.Test">
<configuration name="CpuUtils" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
@@ -190,7 +196,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="csv_test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="Test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@@ -198,12 +204,12 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/读写" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/线程" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/读写/csv_test.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/线程/Test.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
@@ -212,20 +218,20 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="editImage" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<configuration name="csv_test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="$PROJECT_DIR$/../../../software/anaconda/envs/test/python.exe" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/editimage" />
<option name="IS_MODULE_SDK" value="false" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/读写" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/editimage/editImage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/读写/csv_test.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
@@ -234,20 +240,20 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="mysqltest" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<configuration name="editImage" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test" />
<option name="IS_MODULE_SDK" value="true" />
<option name="SDK_HOME" value="$PROJECT_DIR$/../../../software/anaconda/envs/test/python.exe" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/editimage" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/mysqltest.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/editimage/editImage.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
@@ -256,7 +262,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="test (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="mysqltest" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@@ -264,12 +270,12 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/内存优化/slots" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/内存优化/slots/test.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/mysqltest.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
@@ -278,7 +284,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="test (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="tuoheng_alg" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
@@ -286,12 +292,12 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/集合" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test/内存优化/slots" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/集合/test.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/内存优化/slots/test.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
@@ -325,19 +331,19 @@
<list>
<item itemvalue="Python.editImage" />
<item itemvalue="Python.mysqltest" />
<item itemvalue="Python.Test" />
<item itemvalue="Python.test1" />
<item itemvalue="Python.CpuUtils" />
<item itemvalue="Python.csv_test" />
<item itemvalue="Python.test (1)" />
<item itemvalue="Python.test" />
</list>
<recent_temporary>
<list>
<item itemvalue="Python.Test" />
<item itemvalue="Python.test1" />
<item itemvalue="Python.test (1)" />
<item itemvalue="Python.csv_test" />
<item itemvalue="Python.CpuUtils" />
<item itemvalue="Python.test" />
</list>
</recent_temporary>
</component>
@@ -538,7 +544,16 @@
<workItem from="1688083679443" duration="5459000" />
<workItem from="1688344638833" duration="1197000" />
<workItem from="1688441104396" duration="5401000" />
<workItem from="1688524387384" duration="3080000" />
<workItem from="1688524387384" duration="5018000" />
<workItem from="1688611646979" duration="3976000" />
<workItem from="1688688564237" duration="1253000" />
<workItem from="1688953948444" duration="13288000" />
<workItem from="1689120808268" duration="5671000" />
<workItem from="1689297784810" duration="1254000" />
<workItem from="1689341342536" duration="14000" />
<workItem from="1689378621763" duration="831000" />
<workItem from="1689554206797" duration="16635000" />
<workItem from="1689644925650" duration="19947000" />
</task>
<servers />
</component>
@@ -574,6 +589,16 @@
<line>134</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/util/ModelUtils.py</url>
<line>1</line>
<option name="timeStamp" value="7" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/dsp_master.py</url>
<line>1</line>
<option name="timeStamp" value="8" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
@@ -611,7 +636,7 @@
<SUITE FILE_PATH="coverage/tuoheng_alg$IntelligentRecognitionProcess.coverage" NAME="IntelligentRecognitionProcess 覆盖结果" MODIFIED="1682651444560" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/concurrency" />
<SUITE FILE_PATH="coverage/tuoheng_alg$demo3.coverage" NAME="demo3 覆盖结果" MODIFIED="1684809071819" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/元类" />
<SUITE FILE_PATH="coverage/tuoheng_alg$test.coverage" NAME="test 覆盖结果" MODIFIED="1686930120727" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/集合" />
<SUITE FILE_PATH="coverage/tuoheng_alg$Test.coverage" NAME="Test 覆盖结果" MODIFIED="1686531035217" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/ffmpeg11" />
<SUITE FILE_PATH="coverage/tuoheng_alg$Test.coverage" NAME="Test 覆盖结果" MODIFIED="1689663111360" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/线程" />
<SUITE FILE_PATH="coverage/tuoheng_alg$csv_test.coverage" NAME="csv_test 覆盖结果" MODIFIED="1687000802518" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test/读写" />
<SUITE FILE_PATH="coverage/tuoheng_alg$mysqltest.coverage" NAME="mysqltest Coverage Results" MODIFIED="1660868712851" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />
<SUITE FILE_PATH="coverage/tuoheng_alg$asnyc__1_.coverage" NAME="asnyc (1) Coverage Results" MODIFIED="1663458917599" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test" />

+ 10
- 2
concurrency/FeedbackThread.py View File

@@ -37,7 +37,8 @@ class FeedbackThread(Thread):
dsp_recording_result_topic = self.__context["kafka"]["topic"]["dsp-recording-result-topic"]
while True:
logger.info("问题反馈发送消息循环")
feedback = {}
feedback = None
recording = None
try:
fb = self.getFeedback()
if fb is not None and len(fb) > 0:
@@ -45,10 +46,17 @@ class FeedbackThread(Thread):
recording = fb.get("recording")
if feedback is not None and len(feedback) > 0:
kafkaProducer.sender(dsp_alg_results_topic, feedback["request_id"], feedback, 1)
feedback = None
if recording is not None and len(recording) > 0:
kafkaProducer.sender(dsp_recording_result_topic, recording["request_id"], recording, 1)
recording = None
else:
time.sleep(1)
except Exception:
logger.error("问题反馈异常:{}, requestId:{}", format_exc(), feedback.get("request_id"))
if feedback and feedback.get("request_id"):
logger.error("问题反馈异常:{}, requestId:{}", format_exc(), feedback.get("request_id"))
elif recording and recording.get("request_id"):
logger.error("问题反馈异常:{}, requestId:{}", format_exc(), recording.get("request_id"))
else:
logger.error("问题反馈异常:{}", format_exc())
logger.info("问题反馈线程执行完成")

+ 8
- 0
concurrency/FileUploadThread.py View File

@@ -64,6 +64,7 @@ class ImageFileUpload(FileUpload):
if image_dict is not None and len(image_dict) > 0:
image_result = handle_image(high_score_image, image_dict, picture_similarity,
similarity, frame_step, analyse_type)
del image_dict
if image_result:
# 图片帧数编码
task = []
@@ -150,6 +151,13 @@ def handle_image(high_score_image, frame_all, picture_similarity, similarity, fr
diff_frame_num = frame_all[0][2] - high_score_image.get("current_frame")
if diff_frame_num < frame_step:
flag = False
# if diff_frame_num >= frame_step:
# hash1 = ImageUtils.dHash(high_score_image.get("or_frame"))
# hash2 = ImageUtils.dHash(frame_all[0][1])
# dist = ImageUtils.Hamming_distance(hash1, hash2)
# similarity_1 = 1 - dist * 1.0 / 64
# if similarity_1 != 1:
# flag = True
det_result = frame_all[1]
model_info = []
if flag and det_result is not None and len(det_result) > 0:

+ 7
- 7
concurrency/HeartbeatThread.py View File

@@ -58,11 +58,11 @@ class Heartbeat(Thread):
analyse_time=TimeUtils.now_date_to_str())})

def run(self):
logger.info("开始启动心跳线程!requestId:{}", self.__request_id)
hb_init_num = 0
start_time = time.time()
while True:
try:
try:
logger.info("开始启动心跳线程!requestId:{}", self.__request_id)
hb_init_num = 0
start_time = time.time()
while True:
if time.time() - start_time > 43200:
logger.info("心跳线程运行超时!!!!requestId:{}", self.__request_id)
break
@@ -79,6 +79,6 @@ class Heartbeat(Thread):
if hb_init_num % 30 == 0:
self.sendhbMessage(AnalysisStatus.RUNNING.value)
hb_init_num += 3
except Exception:
logger.error("心跳线程异常:{}, requestId:{}", format_exc(), self.__request_id)
except Exception:
logger.error("心跳线程异常:{}, requestId:{}", format_exc(), self.__request_id)
logger.info("心跳线程停止完成!requestId:{}", self.__request_id)

+ 11
- 10
concurrency/IntelligentRecognitionProcess.py View File

@@ -334,9 +334,11 @@ def process(frame):
results = wait(analyze_result, timeout=60, return_when=ALL_COMPLETED)
completed_futures = results.done
det_xywh = {}
ex = None
for r in completed_futures:
if r.exception():
raise r.exception()
ex = r.exception()
return None, None, None, ex
p_result, code, allowedList, label_arraylist, rainbows = r.result()
if allowedList is not None:
det_xywh[code] = {}
@@ -356,11 +358,7 @@ def process(frame):
yc = int(ai_result[2])
x2 = int(ai_result[3])
y2 = int(ai_result[4])
tl = (xc, yc)
tr = (x2, yc)
br = (x2, y2)
bl = (xc, y2)
box = [tl, tr, br, bl]
box = [(xc, yc), (x2, yc), (x2, y2), (xc, y2)]
else:
box = ai_result[1]
draw_painting_joint(box, copy_frame, label_array, score, color, "leftTop")
@@ -375,7 +373,7 @@ def process(frame):
or_frame = add_water_pic(or_frame, logo, requestId)
copy_frame = add_water_pic(copy_frame, logo, requestId)
frame_merge = video_conjuncing(or_frame, copy_frame)
return frame_result, frame_merge, det_xywh
return frame_result, frame_merge, det_xywh, ex
except ServiceException as s:
raise s
except Exception as e:
@@ -506,7 +504,9 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
check = False
for result in t.map(process, frames):
if result is not None:
frame_result, frame_merge, det_xywh = result
frame_result, frame_merge, det_xywh, ex = result
if ex:
raise ex
write_or_video_result = tt.submit(write_or_video, frame_result[1], orFilePath,
or_video_file, frame_result[3],
frame_result[4],
@@ -529,7 +529,6 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
if len(det_xywh) > 0:
check = True
putQueue(image_queue, {"image": (frame_result, det_xywh)}, requestId)

if check:
task_status[1] = 1
if not check:
@@ -690,7 +689,9 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
check = False
for result in t.map(process, frames):
if result is not None:
frame_result, frame_merge, det_xywh = result
frame_result, frame_merge, det_xywh, ex = result
if ex:
raise ex
write_ai_video_result = tt.submit(write_ai_video, frame_merge, aiFilePath,
ai_video_file, frame_result[3],
frame_result[4],

+ 1
- 0
concurrency/PullVideoStreamProcess.py View File

@@ -56,6 +56,7 @@ class PullVideoStreamProcess(Process):
retry_count += 1
if retry_count > 10:
logger.error("心跳线程异常重试失败!requestId:{}", self._msg.get("request_id"))
del hb
raise Exception("心跳线程启动失败")
if not hb.is_alive():
logger.warning("心跳线程异常等待中, requestId:{}", self._msg.get("request_id"))

+ 4
- 0
enums/ModelTypeEnum.py View File

@@ -41,6 +41,10 @@ class ModelType(Enum):

CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement')

DROWING_MODEL = ("17", "017", "人员落水模型", 'drowning')

NOPARKING_MODEL = ("18", "018", "城市违章模型", 'noParking')

def checkCode(code):
for model in ModelType:
if model.value[1] == code:

+ 19
- 18
service/Dispatcher.py View File

@@ -99,29 +99,29 @@ class DispatcherService:
logger.info("(♥◠‿◠)ノ゙ DSP【算法调度服务】启动成功 ლ(´ڡ`ლ)゙")
# 循环消息处理
start_time = time.time()
persistent_time = time.time()
full_count = 0
# persistent_time = time.time()
# full_count = 0
while True:
try:
# 检查任务进程运行情况,去除活动的任务
self.check_process_task()
start_time = self.check_service_resource(start_time)
if len(self.__listeningProcesses) > 0:
now = time.time()
requestIds = list(self.__listeningProcesses.keys())
requestId = requestIds[-1]
task_process = self.__listeningProcesses.get(requestId)
end_time = now - task_process.start_proccess_time
if end_time > 80 and task_process.pullQueue.full() and time.time() - persistent_time < 10:
full_count += 1
if full_count > 4:
logger.error("服务器资源限制, 暂无资源可以使用! requestId:{}", requestId)
task_process.sendEvent({"command": "stop_ex"})
full_count = 0
persistent_time = time.time()
if end_time > 80 and task_process.pullQueue.full() and time.time() - persistent_time >= 10:
full_count = 0
persistent_time = time.time()
# if len(self.__listeningProcesses) > 0:
# now = time.time()
# requestIds = list(self.__listeningProcesses.keys())
# requestId = requestIds[-1]
# task_process = self.__listeningProcesses.get(requestId)
# end_time = now - task_process.start_proccess_time
# if end_time > 80 and task_process.pullQueue.full() and time.time() - persistent_time < 10:
# full_count += 1
# if full_count > 4:
# logger.error("服务器资源限制, 暂无资源可以使用! requestId:{}", requestId)
# task_process.sendEvent({"command": "stop_ex"})
# full_count = 0
# persistent_time = time.time()
# if end_time > 80 and task_process.pullQueue.full() and time.time() - persistent_time >= 10:
# full_count = 0
# persistent_time = time.time()
self.start_feedback_thread()
msg = customerKafkaConsumer.poll()
time.sleep(1)
@@ -135,6 +135,7 @@ class DispatcherService:
m.topic, m.offset, m.partition, message, requestId)
topic_method = self.__analysisType.get(m.topic)
topic_method[2](m.topic, message, topic_method[0])

except Exception:
logger.exception("主线程异常:{}", format_exc())


+ 26
- 13
test/线程/Test.py View File

@@ -33,16 +33,29 @@ def aa(aa):
# test = Test()
# test.process()
# print(3//2)
with ThreadPoolExecutor(max_workers=10) as t:
aa = t.submit(aa, "aaa")
results = wait([aa], timeout=60, return_when=ALL_COMPLETED)
completed_futures = results.done
for f in completed_futures:
if f.exception():
raise f.exception()
else:
print(f"Task {f.result()} succeeded")

dsp算法交互 V 2.7.4转测
1. 修复算法交互分析后上传大视频失败问题bug
2. 修改百度图片子线程异常信息父级线程不打印问题bug
# with ThreadPoolExecutor(max_workers=10) as t:
# aa = t.submit(aa, "aaa")
# results = wait([aa], timeout=60, return_when=ALL_COMPLETED)
# completed_futures = results.done
# for f in completed_futures:
# if f.exception():
# raise f.exception()
# else:
# print(f"Task {f.result()} succeeded")
def test1(message):
while True:
time.sleep(1)
print(message)

message = {"a": "1", "b": "2", "c": "3"}

aa = message
print(aa is message)
message = None
print(aa)
print(message)
# with ThreadPoolExecutor(max_workers=10) as t:
# t.submit(test1, message)
# print("1111111111111111111111111111111")
# del message
# print("aaa", message)

+ 3
- 0
util/Cv2Utils.py View File

@@ -885,6 +885,7 @@ def clear_push_p(push_p, requestId):
push_p.stdin.close()
push_p.terminate()
push_p.wait()
del push_p
except Exception:
logger.error("推流管道异常:{}, requestId: {}", format_exc(), requestId)

@@ -893,6 +894,7 @@ def close_or_write_stream(or_video_file, requestId):
try:
if or_video_file:
or_video_file.release()
del or_video_file
except Exception:
logger.info("关闭原视频写流管道异常:{}, requestId:{}", format_exc(), requestId)

@@ -901,6 +903,7 @@ def close_ai_write_stream(ai_video_file, requestId):
try:
if ai_video_file:
ai_video_file.release()
del ai_video_file
except Exception:
logger.info("关闭AI视频写流管道异常:{}, requestId:{}", format_exc(), requestId)


+ 326
- 105
util/ModelUtils.py View File

@@ -2,7 +2,7 @@
import sys
from pickle import dumps, loads
from traceback import format_exc
import time
from loguru import logger

from common.Constant import COLOR
@@ -15,11 +15,14 @@ from util.TorchUtils import select_device

sys.path.extend(['..', '../AIlib2'])
from AI import AI_process, AI_process_forest, get_postProcess_para, AI_Seg_process, ocr_process
import time
from segutils.segmodel import SegModel
from segutils.trafficUtils import tracfficAccidentMixFunction
from models.experimental import attempt_load
from utils.torch_utils import select_device
from utilsK.queRiver import get_labelnames, get_label_arrays, save_problem_images
from utilsK.queRiver import get_labelnames, get_label_arrays, save_problem_images, riverDetSegMixProcess
from utilsK.drownUtils import mixDrowing_water_postprocess
from utilsK.noParkingUtils import mixNoParking_road_postprocess
from obbUtils.shipUtils import OBB_infer
from obbUtils.load_obb_model import load_model_decoder_OBB
import torch
@@ -36,22 +39,25 @@ class RiverModel:
def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
try:
logger.info("########################加载河道模型########################, requestId:{}", requestId)
trtFlag_det = True
trtFlag_seg = True
# 公共变量
par = {
'device': str(device),
'labelnames': ["排口", "水生植被", "其它", "漂浮物", "污染排口", "菜地", "违建", "岸坡垃圾"],
'detModelpara': [],
'seg_nclass': 2,
'segRegionCnt': 1,
'slopeIndex': [5, 6, 7],
'segPar': {
'modelSize': (640, 360),
'mean': (0.485, 0.456, 0.406),
'std': (0.229, 0.224, 0.225),
'numpy': False,
'RGB_convert_first': True
'RGB_convert_first': True,
'mixFunction': {
'function': riverDetSegMixProcess,
'pars': {
'slopeIndex': [5, 6, 7],
'riverIou': 0.1
}
}
},
'postFile': {
"name": "post_process",
@@ -59,50 +65,45 @@ class RiverModel:
"iou_thres": 0.45,
"classes": 5,
"rainbows": COLOR
}
},
# "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
'Detweights': "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name),
# '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
'Segweights': '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
}
if trtFlag_det:
par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name)
else:
par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
if trtFlag_seg:
par['segweights'] = '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
else:
par['segweights'] = '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
mode = 'others'
postPar = None
segPar = par.get('segPar')
par['trtFlag_seg'] = True if par['Segweights'].endswith('.engine') else False
par['trtFlag_det'] = True if par['Detweights'].endswith('.engine') else False
mode, postPar, segPar = par.get('mode', 'others'), par.get('postPar'), par.get('segPar')
new_device = select_device(par.get('device'))
names = par.get('labelnames')
half = new_device.type != 'cpu'
Detweights = par.get('detweights') # 升级后的检测模型
if trtFlag_det:
Detweights = par.get('Detweights')
if par['trtFlag_det']:
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
model = runtime.deserialize_cuda_engine(f.read())
else:
model = attempt_load(Detweights, map_location=new_device)
if half:
model.half()
Segweights = par.get('segweights')
if trtFlag_seg:
Segweights = par.get('Segweights')
if par['trtFlag_seg']:
with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
segmodel = runtime.deserialize_cuda_engine(f.read())
else:
segmodel = SegModel(nclass=par.get('seg_nclass'), weights=Segweights, device=new_device)
conf_thres = par.get('postFile').get("conf_thres")
iou_thres = par.get('postFile').get("iou_thres")
# classes = par.get('postFile').get("classes")
rainbows = par.get('postFile').get("rainbows")
conf_thres, iou_thres = par.get('postFile').get("conf_thres"), par.get('postFile').get("iou_thres")
classes, rainbows = par.get('postFile').get("classes"), par.get('postFile').get("rainbows")
ovlap_thres_crossCategory = par.get('postFile').get("ovlap_thres_crossCategory")
objectPar = {
'half': half,
'device': new_device,
'conf_thres': conf_thres,
'ovlap_thres_crossCategory': ovlap_thres_crossCategory,
'iou_thres': iou_thres,
'allowedList': [],
'slopeIndex': par.get('slopeIndex'),
'segRegionCnt': par.get('segRegionCnt'),
'trtFlag_det': trtFlag_det,
'trtFlag_seg': trtFlag_seg
'trtFlag_det': par['trtFlag_det'],
'trtFlag_seg': par['trtFlag_seg']
}
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
@@ -154,7 +155,7 @@ def model_process(param):
# frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
try:
return AI_process([param[0]], param[1], param[2], param[3], param[4], param[5], objectPar=param[6],
font=param[7], segPar=param[8], mode=param[9], postPar=param[10])
font=param[7], segPar=loads(dumps(param[8])), mode=param[9], postPar=param[10])
except ServiceException as s:
raise s
except Exception:
@@ -172,23 +173,25 @@ class River2Model:
def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
try:
logger.info("########################加载河道检测模型########################, requestId:{}", requestId)
trtFlag_det = True, # 检测模型是否采用TRT
trtFlag_seg = True, # 分割模型是否采用TRT
# 公共变量
par = {
'device': str(device),
'labelnames': [
"漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", "蓝藻"],
'detModelpara': [],
'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只",
"蓝藻"],
'seg_nclass': 2,
'segRegionCnt': 1,
'slopeIndex': [1, 3, 4, 7],
'segPar': {
'modelSize': (640, 360),
'mean': (0.485, 0.456, 0.406),
'std': (0.229, 0.224, 0.225),
'numpy': False,
'RGB_convert_first': True
'RGB_convert_first': True,
'mixFunction': {
'function': riverDetSegMixProcess,
'pars': {
'slopeIndex': [1, 3, 4, 7],
'riverIou': 0.1
}
}
},
'postFile': {
"name": "post_process",
@@ -197,24 +200,20 @@ class River2Model:
"ovlap_thres_crossCategory": 0.65,
"classes": 5,
"rainbows": COLOR
}
},
# "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
'Detweights': "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name),
# '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
'Segweights': '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
}
if trtFlag_det:
par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name)

else:
par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
if trtFlag_seg:
par['segweights'] = '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
else:
par['segweights'] = '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
mode = 'others'
postPar = None
new_device = select_device(par.get('device')) # 指定GPU
par['trtFlag_seg'] = True if par['Segweights'].endswith('.engine') else False
par['trtFlag_det'] = True if par['Detweights'].endswith('.engine') else False
mode, postPar = par.get('mode', 'others'), par.get('postPar')
new_device = select_device(par.get('device'))
names = par.get('labelnames')
half = new_device.type != 'cpu'
Detweights = par.get('detweights') # 升级后的检测模型
if trtFlag_det:
Detweights = par.get('Detweights') # 升级后的检测模型
if par['trtFlag_det']:
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
model = runtime.deserialize_cuda_engine(f.read())
else:
@@ -222,18 +221,15 @@ class River2Model:
if half:
model.half()
segPar = par.get('segPar')
Segweights = par.get('segweights')
if trtFlag_seg:
Segweights = par.get('Segweights')
if par['trtFlag_seg']:
with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
segmodel = runtime.deserialize_cuda_engine(f.read())
else:
segmodel = SegModel(nclass=par.get('seg_nclass'), weights=Segweights, device=new_device)
conf_thres = par.get('postFile').get("conf_thres")
iou_thres = par.get('postFile').get("iou_thres")
# classes = par.get('postFile').get("classes")
rainbows = par.get('postFile').get("rainbows")
postFile = par.get('postFile')
ovlap_thres_crossCategory = postFile.get('ovlap_thres_crossCategory')
conf_thres, iou_thres = par.get('postFile').get("conf_thres"), par.get('postFile').get("iou_thres")
classes, rainbows = par.get('postFile').get("classes"), par.get('postFile').get("rainbows")
ovlap_thres_crossCategory = par.get('postFile').get('ovlap_thres_crossCategory')
objectPar = {
'half': half,
'device': new_device,
@@ -241,10 +237,9 @@ class River2Model:
'ovlap_thres_crossCategory': ovlap_thres_crossCategory,
'iou_thres': iou_thres,
'allowedList': [],
'slopeIndex': par.get('slopeIndex'),
'segRegionCnt': par.get('segRegionCnt'),
'trtFlag_det': trtFlag_det,
'trtFlag_seg': trtFlag_seg
'trtFlag_det': par['trtFlag_det'],
'trtFlag_seg': par['trtFlag_seg']
}
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar,
@@ -267,15 +262,10 @@ class HighWayModel:
s = time.time()
try:
logger.info("########################加载高速模型########################, requestId:{}", requestId)
trtFlag_det = True, # 检测模型是否采用TRT
trtFlag_seg = True, # 分割模型是否采用TRT
# 公共变量
par = {
'device': str(device),
'gpu_name': gpu_name,
'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水",
"事故"],
'slopeIndex': [],
'seg_nclass': 3,
'segRegionCnt': 2,
'segPar': {
@@ -284,44 +274,45 @@ class HighWayModel:
'std': (0.229, 0.224, 0.225),
'predResize': True,
'numpy': False,
'RGB_convert_first': True
},
'postPar': {
'label_csv': '../AIlib2/weights/conf/%s/class_dict.csv' % modeType.value[3],
'speedRoadArea': 16000,
'vehicleArea': 10,
'speedRoadVehicleAngleMin': 15,
'speedRoadVehicleAngleMax': 75,
'roundness': 0.7,
'cls': 9,
'vehicleFactor': 0.1
'RGB_convert_first': True,
'mixFunction': {
'function': tracfficAccidentMixFunction,
'pars': {
'label_csv': '../AIlib2/weights/conf/%s/class_dict.csv' % modeType.value[3],
'speedRoadArea': 16000,
'vehicleArea': 10,
'speedRoadVehicleAngleMin': 15,
'speedRoadVehicleAngleMax': 75,
'roundness': 1.0,
'cls': 9,
'vehicleFactor': 0.1,
'confThres': 0.25,
'roadIou': 0.6
}
}
},
'mode': 'highWay3.0',
'postFile': {
"name": "post_process",
"conf_thres": 0.25,
"iou_thres": 0.25,
"classes": 9,
"rainbows": COLOR
}
},
# "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
'Detweights': "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name),
# '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
'Segweights': '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
}
if trtFlag_det:
par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
else:
par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
if trtFlag_seg:
par['segweights'] = '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (
modeType.value[3], par['gpu_name'])
else:
par['segweights'] = '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
par['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
par['trtFlag_seg'] = True if par['Segweights'].endswith('.engine') else False
par['trtFlag_det'] = True if par['Detweights'].endswith('.engine') else False
mode = par.get('mode', 'others')
postPar = par.get('postPar', None)

postPar = par.get('postPar')
new_device = select_device(par.get('device')) # 指定GPU
names = par.get('labelnames')
half = new_device.type != 'cpu'
Detweights = par.get('detweights') # 升级后的检测模型
if trtFlag_det:
Detweights = par.get('Detweights') # 升级后的检测模型
if par['trtFlag_det']:
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
model = runtime.deserialize_cuda_engine(f.read())
else:
@@ -329,8 +320,8 @@ class HighWayModel:
if half:
model.half()
segPar = par.get('segPar')
Segweights = par.get('segweights')
if trtFlag_seg:
Segweights = par.get('Segweights')
if par['trtFlag_seg']:
with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
segmodel = runtime.deserialize_cuda_engine(f.read())
else:
@@ -340,16 +331,17 @@ class HighWayModel:
iou_thres = par.get('postFile').get("iou_thres")
# classes = par.get('postFile').get("classes")
rainbows = par.get('postFile').get("rainbows")
ovlap_thres_crossCategory = par.get('postFile').get('ovlap_thres_crossCategory')
objectPar = {
'half': half,
'device': new_device,
'conf_thres': conf_thres,
'ovlap_thres_crossCategory': ovlap_thres_crossCategory,
'iou_thres': iou_thres,
'allowedList': [],
'slopeIndex': par.get('slopeIndex'),
'segRegionCnt': par.get('segRegionCnt'),
'trtFlag_det': trtFlag_det,
'trtFlag_seg': trtFlag_seg
'trtFlag_det': par['trtFlag_det'],
'trtFlag_seg': par['trtFlag_seg']
}
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
@@ -382,7 +374,7 @@ def high_process(param):
try:
# frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
return AI_process([param[0]], param[1], param[2], param[3], param[4], param[5], objectPar=param[6],
font=param[7], segPar=param[8], mode=param[9], postPar=loads(dumps(param[10])))
font=param[7], segPar=loads(dumps(param[8])), mode=param[9], postPar=param[10])
except ServiceException as s:
raise s
except Exception:
@@ -393,6 +385,197 @@ def high_process(param):
ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])


# 人员落水模型
class DrowingModel:
__slots__ = "model_conf"

def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
s = time.time()
try:
logger.info("########################加载人员落水模型########################, requestId:{}", requestId)
par = {
'device': str(device),
'labelnames': ["人头", "人", "船只"],
'seg_nclass': 2,
'segRegionCnt': 2,
'segPar': {
'modelSize': (640, 360),
'mean': (0.485, 0.456, 0.406),
'std': (0.229, 0.224, 0.225),
'predResize': True,
'numpy': False,
'RGB_convert_first': True,
'mixFunction': {
'function': mixDrowing_water_postprocess,
'pars': {}
}
},
'postFile': {
"name": "post_process",
"conf_thres": 0.25,
"iou_thres": 0.25,
"classes": 9,
"rainbows": COLOR
},
# "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
'Detweights': "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name),
# '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
'Segweights': '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
}
par['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
par['trtFlag_seg'] = True if par['Segweights'].endswith('.engine') else False
par['trtFlag_det'] = True if par['Detweights'].endswith('.engine') else False
mode = par.get('mode', 'others')
postPar = par.get('postPar', None)

new_device = select_device(par.get('device')) # 指定GPU
names = par.get('labelnames')
half = new_device.type != 'cpu'
Detweights = par.get('Detweights') # 升级后的检测模型
if par['trtFlag_det']:
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
model = runtime.deserialize_cuda_engine(f.read())
else:
model = attempt_load(Detweights, map_location=new_device)
if half:
model.half()
segPar = par.get('segPar')
Segweights = par.get('Segweights')
if par['trtFlag_seg']:
with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
segmodel = runtime.deserialize_cuda_engine(f.read())
else:
seg_nclass = par.get('seg_nclass')
segmodel = SegModel(nclass=seg_nclass, weights=Segweights, device=new_device)
conf_thres = par.get('postFile').get("conf_thres")
iou_thres = par.get('postFile').get("iou_thres")
# classes = par.get('postFile').get("classes")
rainbows = par.get('postFile').get("rainbows")
ovlap_thres_crossCategory = par.get('postFile').get('ovlap_thres_crossCategory')
objectPar = {
'half': half,
'device': new_device,
'conf_thres': conf_thres,
'ovlap_thres_crossCategory': ovlap_thres_crossCategory,
'iou_thres': iou_thres,
'allowedList': [],
'segRegionCnt': par.get('segRegionCnt'),
'trtFlag_det': par['trtFlag_det'],
'trtFlag_seg': par['trtFlag_seg']
}
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
"""
model_param = [None, model, segmodel, names, None, rainbows, objectPar, None, segPar, mode, postPar,
requestId]
self.model_conf = (modeType, allowedList, model_param)
# self.num = 0
except Exception:
logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId)
raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0],
ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId)


# 城市违章模型
class NoParkingModel:
__slots__ = "model_conf"

def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
s = time.time()
try:
logger.info("########################加载城市违章模型########################, requestId:{}", requestId)
par = {
'device': str(device),
'labelnames': ["车辆", "违停"],
'seg_nclass': 4,
'segRegionCnt': 2,
'segPar': {
'modelSize': (640, 360),
'mean': (0.485, 0.456, 0.406),
'std': (0.229, 0.224, 0.225),
'predResize': True,
'numpy': False,
'RGB_convert_first': True, ###分割模型预处理参数
'mixFunction': {
'function': mixNoParking_road_postprocess,
'pars': {
'speedRoadArea': 16000,
'roundness': 0.5,
'cls': 9,
'vehicleArea': 10,
'laneLineArea': 10,
'laneAngleCha': 5
}
}
},
'postFile': {
"name": "post_process",
"conf_thres": 0.25,
"iou_thres": 0.25,
"classes": 9,
"rainbows": COLOR
},
# "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
'Detweights': "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name),
# '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
'Segweights': '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
}
par['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
par['trtFlag_seg'] = True if par['Segweights'].endswith('.engine') else False
par['trtFlag_det'] = True if par['Detweights'].endswith('.engine') else False
mode = par.get('mode', 'others')
postPar = par.get('postPar', None)

new_device = select_device(par.get('device')) # 指定GPU
names = par.get('labelnames')
half = new_device.type != 'cpu'
Detweights = par.get('Detweights') # 升级后的检测模型
if par['trtFlag_det']:
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
model = runtime.deserialize_cuda_engine(f.read())
else:
model = attempt_load(Detweights, map_location=new_device)
if half:
model.half()
segPar = par.get('segPar')
Segweights = par.get('Segweights')
if par['trtFlag_seg']:
with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
segmodel = runtime.deserialize_cuda_engine(f.read())
else:
seg_nclass = par.get('seg_nclass')
segmodel = SegModel(nclass=seg_nclass, weights=Segweights, device=new_device)
conf_thres = par.get('postFile').get("conf_thres")
iou_thres = par.get('postFile').get("iou_thres")
# classes = par.get('postFile').get("classes")
rainbows = par.get('postFile').get("rainbows")
ovlap_thres_crossCategory = par.get('postFile').get('ovlap_thres_crossCategory')
objectPar = {
'half': half,
'device': new_device,
'conf_thres': conf_thres,
'ovlap_thres_crossCategory': ovlap_thres_crossCategory,
'iou_thres': iou_thres,
'allowedList': [],
'segRegionCnt': par.get('segRegionCnt'),
'trtFlag_det': par['trtFlag_det'],
'trtFlag_seg': par['trtFlag_seg']
}
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
"""
model_param = [None, model, segmodel, names, None, rainbows, objectPar, None, segPar, mode, postPar,
requestId]
self.model_conf = (modeType, allowedList, model_param)
# self.num = 0
except Exception:
logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId)
raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0],
ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId)


# 森林模型
class ForestModel:
__slots__ = "model_conf"
@@ -882,7 +1065,7 @@ class CityMangementModel:
par = {
'device': str(device1),
'gpu_name': gpu_name,
'labelnames': ["车辆", "垃圾"],
'labelnames': ["车辆","垃圾","商贩"],
'seg_nclass': 2, # 分割模型类别数目,默认2类
'segRegionCnt': 0,
'slopeIndex': [],
@@ -932,6 +1115,7 @@ class CityMangementModel:
ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId)


# 船只模型
class ShipModel:
__slots__ = "model_conf"
@@ -1296,6 +1480,7 @@ def smogfire_label(width, model_param):
model_param[4] = label_arraylist
model_param[11] = digitFont


def city_mangement_label(width, model_param):
names = model_param[3]
rainbows = model_param[5]
@@ -1308,10 +1493,32 @@ def city_mangement_label(width, model_param):
model_param[11] = digitFont


def drowning_label(width, model_param):
names = model_param[3]
rainbows = model_param[5]
digitFont, label_arraylist = get_label_arraylist(width, names, rainbows)
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
"""
model_param[4] = label_arraylist
model_param[7] = digitFont


def noparking_label(width, model_param):
names = model_param[3]
rainbows = model_param[5]
digitFont, label_arraylist = get_label_arraylist(width, names, rainbows)
"""
frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
"""
model_param[4] = label_arraylist
model_param[7] = digitFont


MODEL_CONFIG = {
# 加载河道模型
ModelType.WATER_SURFACE_MODEL.value[1]: (
lambda x, y, r, t, z : RiverModel(x, y, r, ModelType.WATER_SURFACE_MODEL, t, z),
lambda x, y, r, t, z: RiverModel(x, y, r, ModelType.WATER_SURFACE_MODEL, t, z),
ModelType.WATER_SURFACE_MODEL,
lambda x, y: river_label(x, y),
lambda x: model_process(x)
@@ -1403,6 +1610,20 @@ MODEL_CONFIG = {
ModelType.CITY_MANGEMENT_MODEL,
lambda x, y: city_mangement_label(x, y),
lambda x: forest_process(x)
),
# 人员落水模型
ModelType.DROWING_MODEL.value[1]: (
lambda x, y, r, t, z: DrowingModel(x, y, r, ModelType.DROWING_MODEL, t, z),
ModelType.DROWING_MODEL,
lambda x, y: drowning_label(x, y),
lambda x: model_process(x)
),
# 城市违章模型
ModelType.NOPARKING_MODEL.value[1]: (
lambda x, y, r, t, z: NoParkingModel(x, y, r, ModelType.NOPARKING_MODEL, t, z),
ModelType.NOPARKING_MODEL,
lambda x, y: noparking_label(x, y),
lambda x: model_process(x)
)
}
# ModelConfig = namedtuple('ModelConfig', ('x', 'y', 'z'))

Loading…
Cancel
Save