From 41b35619e83cc46d9592ecffbac1ff0d2ce2966a Mon Sep 17 00:00:00 2001 From: "lllcho.lc" Date: Tue, 25 Oct 2022 20:31:53 +0800 Subject: [PATCH] [to #42322933] Fix bug for demo service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在demo service场景,同时调用同一个视频文件,会导致ffmpeg处理同名视频的冲突。通过uuid生成唯一的文件名解决这个冲突。 Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10518178 --- .../models/cv/action_detection/action_detection_onnx.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modelscope/models/cv/action_detection/action_detection_onnx.py b/modelscope/models/cv/action_detection/action_detection_onnx.py index 1c8be354..223d77f7 100644 --- a/modelscope/models/cv/action_detection/action_detection_onnx.py +++ b/modelscope/models/cv/action_detection/action_detection_onnx.py @@ -4,6 +4,7 @@ import os import os.path as osp import shutil import subprocess +import uuid import cv2 import numpy as np @@ -84,7 +85,9 @@ class ActionDetONNX(Model): def forward_video(self, video_name, scale): min_size, max_size = self._get_sizes(scale) - tmp_dir = osp.join(self.tmp_dir, osp.basename(video_name)[:-4]) + tmp_dir = osp.join( + self.tmp_dir, + str(uuid.uuid1()) + '_' + osp.basename(video_name)[:-4]) if osp.exists(tmp_dir): shutil.rmtree(tmp_dir) os.makedirs(tmp_dir) @@ -110,6 +113,7 @@ class ActionDetONNX(Model): len(frame_names) * self.temporal_stride, self.temporal_stride)) batch_imgs = [self.parse_frames(names) for names in frame_names] + shutil.rmtree(tmp_dir) N, _, T, H, W = batch_imgs[0].shape scale_min = min_size / min(H, W) @@ -128,7 +132,6 @@ class ActionDetONNX(Model): 'timestamp': t, 'actions': res } for t, res in zip(timestamp, results)] - shutil.rmtree(tmp_dir) return results def forward(self, video_name):