nanushio
commited on
Commit
•
b3881ed
1
Parent(s):
acc4b2f
- [MINOR] [SOURCE] [UPDATE] 1. update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import decord
|
|
9 |
from decord import VideoReader
|
10 |
import numpy as np
|
11 |
import yaml
|
|
|
12 |
|
13 |
from cover.datasets import UnifiedFrameSampler, spatial_temporal_view_decomposition
|
14 |
from cover.models import COVER
|
@@ -25,6 +26,12 @@ mean_clip, std_clip = (
|
|
25 |
|
26 |
sample_interval = 30
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def get_sampler_params(video_path):
|
29 |
vr = VideoReader(video_path)
|
30 |
total_frames = len(vr)
|
@@ -44,13 +51,44 @@ def fuse_results(results: list):
|
|
44 |
"overall" : x,
|
45 |
}
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def inference_one_video(input_video):
|
48 |
"""
|
49 |
BASIC SETTINGS
|
50 |
"""
|
51 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
52 |
with open("./cover.yml", "r") as f:
|
53 |
-
|
54 |
|
55 |
dopt = opt["data"]["val-ytugc"]["args"]
|
56 |
temporal_samplers = {}
|
@@ -112,14 +150,30 @@ def inference_one_video(input_video):
|
|
112 |
|
113 |
results = [r.mean().item() for r in evaluator(views)]
|
114 |
pred_score = fuse_results(results)
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
# Define the input and output types for Gradio using the new API
|
118 |
video_input = gr.Video(label="Input Video")
|
119 |
-
|
120 |
|
121 |
# Create the Gradio interface
|
122 |
-
gradio_app = gr.Interface(fn=inference_one_video, inputs=video_input, outputs=
|
123 |
|
124 |
if __name__ == "__main__":
|
125 |
gradio_app.launch()
|
|
|
9 |
from decord import VideoReader
|
10 |
import numpy as np
|
11 |
import yaml
|
12 |
+
import matplotlib.pyplot as plt
|
13 |
|
14 |
from cover.datasets import UnifiedFrameSampler, spatial_temporal_view_decomposition
|
15 |
from cover.models import COVER
|
|
|
26 |
|
27 |
sample_interval = 30
|
28 |
|
29 |
+
comparison_array = {
|
30 |
+
"semantic": [3.0, 3.5, 2.5, 4.0, 2.0], # 示例数组
|
31 |
+
"technical": [2.0, 3.0, 3.5, 4.0, 1.5],
|
32 |
+
"aesthetic": [2.5, 3.0, 2.0, 4.5, 3.5]
|
33 |
+
}
|
34 |
+
|
35 |
def get_sampler_params(video_path):
|
36 |
vr = VideoReader(video_path)
|
37 |
total_frames = len(vr)
|
|
|
51 |
"overall" : x,
|
52 |
}
|
53 |
|
54 |
+
def normalize_score(score, min_score=0, max_score=5):
|
55 |
+
return (score - min_score) / (max_score - min_score) * 5
|
56 |
+
|
57 |
+
def compare_score(score, score_list):
|
58 |
+
better_than = sum(1 for s in score_list if score > s)
|
59 |
+
percentage = better_than / len(score_list) * 100
|
60 |
+
return f"Better than {percentage:.0f}% videos in YT-UGC" if percentage > 50 else f"Worse than {100-percentage:.0f}% videos in YT-UGC"
|
61 |
+
|
62 |
+
def create_bar_chart(scores, comparisons):
|
63 |
+
labels = ['Semantic', 'Technical', 'Aesthetic', 'Overall']
|
64 |
+
colors = ['#d62728', '#1f77b4', '#ff7f0e', '#bcbd22']
|
65 |
+
|
66 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
67 |
+
|
68 |
+
for i, (label, score, comparison, color) in enumerate(zip(labels, scores, comparisons, colors)):
|
69 |
+
ax.barh(i, score, color=color, edgecolor='black')
|
70 |
+
ax.text(score, i, f'{score:.1f}', va='center', ha='left')
|
71 |
+
ax.text(5.1, i, comparison, va='center', ha='left')
|
72 |
+
|
73 |
+
ax.set_yticks(range(len(labels)))
|
74 |
+
ax.set_yticklabels(labels)
|
75 |
+
ax.set_xlim(0, 5)
|
76 |
+
ax.set_xlabel('Score')
|
77 |
+
|
78 |
+
plt.tight_layout()
|
79 |
+
image_path = "./bar_chart.png"
|
80 |
+
plt.savefig(image_path)
|
81 |
+
plt.close()
|
82 |
+
|
83 |
+
return image_path
|
84 |
+
|
85 |
def inference_one_video(input_video):
|
86 |
"""
|
87 |
BASIC SETTINGS
|
88 |
"""
|
89 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
90 |
with open("./cover.yml", "r") as f:
|
91 |
+
opt = yaml.safe_load(f)
|
92 |
|
93 |
dopt = opt["data"]["val-ytugc"]["args"]
|
94 |
temporal_samplers = {}
|
|
|
150 |
|
151 |
results = [r.mean().item() for r in evaluator(views)]
|
152 |
pred_score = fuse_results(results)
|
153 |
+
|
154 |
+
normalized_scores = [
|
155 |
+
normalize_score(pred_score["semantic"]),
|
156 |
+
normalize_score(pred_score["technical"]),
|
157 |
+
normalize_score(pred_score["aesthetic"]),
|
158 |
+
normalize_score(pred_score["overall"])
|
159 |
+
]
|
160 |
+
|
161 |
+
comparisons = [
|
162 |
+
compare_score(pred_score["semantic"], comparison_array["semantic"]),
|
163 |
+
compare_score(pred_score["technical"], comparison_array["technical"]),
|
164 |
+
compare_score(pred_score["aesthetic"], comparison_array["aesthetic"]),
|
165 |
+
compare_score(pred_score["overall"], comparison_array["semantic"] + comparison_array["technical"] + comparison_array["aesthetic"]) # 假设 overall 分数的比较使用所有维度分数的组合
|
166 |
+
]
|
167 |
+
|
168 |
+
image_path = create_bar_chart(normalized_scores, comparisons)
|
169 |
+
return image_path
|
170 |
|
171 |
# Define the input and output types for Gradio using the new API
|
172 |
video_input = gr.Video(label="Input Video")
|
173 |
+
output_image = gr.Image(label="Scores")
|
174 |
|
175 |
# Create the Gradio interface
|
176 |
+
gradio_app = gr.Interface(fn=inference_one_video, inputs=video_input, outputs=output_image)
|
177 |
|
178 |
if __name__ == "__main__":
|
179 |
gradio_app.launch()
|