Browse Source

[to #42322933] Fix bug for demo service

在demo service场景,同时调用同一个视频文件,会导致ffmpeg处理同名视频的冲突。通过uuid生成唯一的文件名解决这个冲突。
        Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10518178
master
lllcho.lc yingda.chen 3 years ago
parent
commit
41b35619e8
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      modelscope/models/cv/action_detection/action_detection_onnx.py

+ 5
- 2
modelscope/models/cv/action_detection/action_detection_onnx.py View File

@@ -4,6 +4,7 @@ import os
import os.path as osp import os.path as osp
import shutil import shutil
import subprocess import subprocess
import uuid


import cv2 import cv2
import numpy as np import numpy as np
@@ -84,7 +85,9 @@ class ActionDetONNX(Model):
def forward_video(self, video_name, scale): def forward_video(self, video_name, scale):
min_size, max_size = self._get_sizes(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): if osp.exists(tmp_dir):
shutil.rmtree(tmp_dir) shutil.rmtree(tmp_dir)
os.makedirs(tmp_dir) os.makedirs(tmp_dir)
@@ -110,6 +113,7 @@ class ActionDetONNX(Model):
len(frame_names) * self.temporal_stride, len(frame_names) * self.temporal_stride,
self.temporal_stride)) self.temporal_stride))
batch_imgs = [self.parse_frames(names) for names in frame_names] batch_imgs = [self.parse_frames(names) for names in frame_names]
shutil.rmtree(tmp_dir)


N, _, T, H, W = batch_imgs[0].shape N, _, T, H, W = batch_imgs[0].shape
scale_min = min_size / min(H, W) scale_min = min_size / min(H, W)
@@ -128,7 +132,6 @@ class ActionDetONNX(Model):
'timestamp': t, 'timestamp': t,
'actions': res 'actions': res
} for t, res in zip(timestamp, results)] } for t, res in zip(timestamp, results)]
shutil.rmtree(tmp_dir)
return results return results


def forward(self, video_name): def forward(self, video_name):


Loading…
Cancel
Save