mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
[to #42322933] video_summarization 修改test中的结果可视化
video_summarization 修改test中的结果可视化
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9902499
This commit is contained in:
@@ -106,4 +106,4 @@ class VideoSummarizationPipeline(Pipeline):
|
||||
summary = generate_summary([change_points], [scores], [n_frames],
|
||||
[picks])[0]
|
||||
|
||||
return summary
|
||||
return summary.tolist()
|
||||
|
||||
@@ -166,3 +166,24 @@ def semantic_seg_masks_to_image(masks):
|
||||
mask = mask.astype(bool)
|
||||
draw_img[mask] = color_mask
|
||||
return draw_img
|
||||
|
||||
|
||||
def show_video_summarization_result(video_in_path, result, video_save_path):
|
||||
frame_indexes = result[OutputKeys.OUTPUT]
|
||||
cap = cv2.VideoCapture(video_in_path)
|
||||
for i in range(len(frame_indexes)):
|
||||
idx = frame_indexes[i]
|
||||
success, frame = cap.read()
|
||||
if success is False:
|
||||
raise Exception(video_in_path,
|
||||
' can not be correctly decoded by OpenCV.')
|
||||
if i == 0:
|
||||
size = (frame.shape[1], frame.shape[0])
|
||||
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
|
||||
video_writer = cv2.VideoWriter(video_save_path, fourcc,
|
||||
cap.get(cv2.CAP_PROP_FPS), size,
|
||||
True)
|
||||
if idx == 1:
|
||||
video_writer.write(frame)
|
||||
video_writer.release()
|
||||
cap.release()
|
||||
|
||||
@@ -3,6 +3,7 @@ import unittest
|
||||
|
||||
from modelscope.pipelines import pipeline
|
||||
from modelscope.utils.constant import Tasks
|
||||
from modelscope.utils.cv.image_utils import show_video_summarization_result
|
||||
from modelscope.utils.test_utils import test_level
|
||||
|
||||
|
||||
@@ -10,22 +11,23 @@ class VideoSummarizationTest(unittest.TestCase):
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_run_modelhub(self):
|
||||
|
||||
model_id = 'damo/cv_googlenet_pgl-video-summarization'
|
||||
video_path = 'data/test/videos/video_category_test_video.mp4'
|
||||
summarization_pipeline = pipeline(
|
||||
Tasks.video_summarization,
|
||||
model='damo/cv_googlenet_pgl-video-summarization')
|
||||
result = summarization_pipeline(
|
||||
'data/test/videos/video_category_test_video.mp4')
|
||||
Tasks.video_summarization, model=model_id)
|
||||
result = summarization_pipeline(video_path)
|
||||
|
||||
print(f'video summarization output: {result}.')
|
||||
print(f'video summarization output: \n{result}.')
|
||||
show_video_summarization_result(video_path, result,
|
||||
'./summarization_result.avi')
|
||||
|
||||
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||
def test_run_modelhub_default_model(self):
|
||||
video_path = 'data/test/videos/video_category_test_video.mp4'
|
||||
summarization_pipeline = pipeline(Tasks.video_summarization)
|
||||
result = summarization_pipeline(
|
||||
'data/test/videos/video_category_test_video.mp4')
|
||||
result = summarization_pipeline(video_path)
|
||||
|
||||
print(f'video summarization output: {result}.')
|
||||
print(f'video summarization output:\n {result}.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user