-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.py
281 lines (242 loc) · 8.23 KB
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import os
import time
import json
import re
import subprocess
import platform
import inquirer
if platform.system() == "Windows":
mainPath = os.path.join(os.getenv("APPDATA"), "TheAnimeScripter")
else:
mainPath = os.path.join(
os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")),
"TheAnimeScripter",
)
if not os.path.exists(mainPath):
os.makedirs(mainPath)
ffmpegLogPath = os.path.join(mainPath, "ffmpeg.log")
tasLogPath = os.path.join(mainPath, "TAS.log")
def runAllBenchmarks(executor, version, inputVideo=None, systemInfo=None):
print(
"Running all benchmarks. Depending on your system, this may take a while. Please be patient and keep the terminal in focus at all time."
)
print(
"The results will be saved in benchmarkResults.json. Feel free to share this file with the Discord Community at https://discord.gg/WJfyDAVYGZ"
)
results = {
"Upscale": runUpscaleBenchmark(inputVideo, executor),
"Interpolate": runInterpolateBenchmark(inputVideo, executor),
}
with open("benchmarkResults.json", "w") as f:
json.dump(
{
"Version": version,
"Testing Methodology": TESTINGVERSION,
"System Info": systemInfo,
"Results": results,
},
f,
indent=4,
)
def getExe():
if os.path.exists("main.exe"):
version = subprocess.check_output(["main.exe", "--version"]).decode().strip()
return ["main.exe"], version
else:
if platform.system() == "Linux":
if os.path.exists("./main"):
version = (
subprocess.check_output(["./main", "--version"]).decode().strip()
)
return ["./main"], version
else:
version = (
subprocess.check_output(["python3.12", "main.py", "--version"])
.decode()
.strip()
)
return ["python3.12", "main.py"], version
else:
version = (
subprocess.check_output(["python", "main.py", "--version"])
.decode()
.strip()
)
return ["python", "main.py"], version
def getClip(executor):
print("Please select 1080p as the desired quality.")
outputPath = "output/test.mp4"
cmd = executor + ["--input", CLIPURL, "--output", outputPath]
subprocess.Popen(cmd, shell=False).wait()
systemInfo = parseSystemInfo()
return os.path.abspath(outputPath), systemInfo
def runUpscaleBenchmark(inputVideo, executor):
global currentTest
results = {}
for method in upscaleMethods:
print(f"[{currentTest}/{TOTALTESTS}] {method} benchmark...")
cmd = executor + [
"--input",
inputVideo,
"--upscale",
"--upscale_method",
method,
"--static",
"--benchmark",
"--outpoint",
"20" if "-tensorrt" in method else "15",
]
print(f"Running command: {' '.join(cmd)}") # Debugging line
subprocess.run(cmd, check=True, cwd=os.path.dirname(os.path.abspath(__file__)))
fps = parseFPS()
results[method] = fps
time.sleep(TIMESLEEP)
currentTest += 1
return results
def runInterpolateBenchmark(inputVideo, executor):
global currentTest
results = {}
for method in interpolateMethods:
print(f"[{currentTest}/{TOTALTESTS}] {method} benchmark...")
currentTest += 1
cmd = executor + [
"--input",
inputVideo,
"--interpolate",
"--interpolate_method",
method,
"--benchmark",
]
print(f"Running command: {' '.join(cmd)}") # Debugging line
subprocess.run(cmd, cwd=os.path.dirname(os.path.abspath(__file__)))
fps = parseFPS()
results[method] = fps
time.sleep(TIMESLEEP)
print(
f"[{currentTest}/{TOTALTESTS}] Running {method} with ensemble benchmark..."
)
currentTest += 1
cmd = executor + [
"--input",
inputVideo,
"--interpolate",
"--interpolate_method",
method,
"--benchmark",
# "--ensemble",
"--outpoint",
"20",
]
if method not in ["rife4.22", "rife4.22-lite"]:
cmd += ["--ensemble"]
print(f"Running command: {' '.join(cmd)}") # Debugging line
subprocess.run(cmd, cwd=os.path.dirname(os.path.abspath(__file__)))
fps = parseFPS()
results[f"{method}-ensemble"] = fps
time.sleep(TIMESLEEP)
return results
def parseFPS():
with open(tasLogPath, "r") as file:
for line in file:
if "Total Execution Time" in line:
match = re.search(
r"Total Execution Time: ([\d.]+) seconds - FPS: ([\d.]+)", line
)
if match:
total_execution_time = float(match.group(1))
fps = float(match.group(2))
print(f"Total Execution Time: {total_execution_time} seconds")
print(f"FPS: {fps}")
return total_execution_time, fps
return None, None
def parseSystemInfo():
systemInfo = {}
with open(tasLogPath, "r") as file:
lines = file.readlines()
start = lines.index("============== System Checker ==============\n") + 1
end = lines.index("============== Arguments Checker ==============\n")
for line in lines[start:end]:
if ": " in line:
key, value = line.strip().split(": ")
systemInfo[key] = value
return systemInfo
if __name__ == "__main__":
TIMESLEEP = 2
CLIPURL = "https://www.youtube.com/watch?v=kpeUMAVJCig"
TESTINGVERSION = "V4.4"
upscaleMethods = [
"shufflecugan",
"compact",
"ultracompact",
"superultracompact",
"span",
"compact-directml",
"ultracompact-directml",
"superultracompact-directml",
"span-directml",
"span-ncnn",
"shufflecugan-ncnn",
"compact-tensorrt",
"ultracompact-tensorrt",
"superultracompact-tensorrt",
"shufflecugan-tensorrt",
"span-tensorrt",
]
interpolateMethods = [
"rife4.6",
"rife4.22",
"rife4.22-lite",
"rife4.6-ncnn",
"rife4.22-lite-ncnn",
"rife4.22-ncnn",
"rife4.6-tensorrt",
"rife4.22-tensorrt",
"rife4.22-lite-tensorrt",
]
currentTest = 0
executor, version = getExe()
inputVideo, systemInfo = getClip(executor)
# Define the questions
questions = [
inquirer.List(
"GPUVENDOR",
message="Please select your GPU vendor",
choices=["NVIDIA", "AMD", "Intel"],
),
]
# Ask the questions
answers = inquirer.prompt(questions)
GPUVENDOR = answers["GPUVENDOR"].upper()
# Filter methods based on GPU vendor
if GPUVENDOR == "NVIDIA":
upscaleMethods = [
method
for method in upscaleMethods
if "ncnn" not in method and "directml" not in method
]
interpolateMethods = [
method
for method in interpolateMethods
if "ncnn" not in method and "directml" not in method
]
elif GPUVENDOR in ["AMD", "INTEL"]:
upscaleMethods = [
method
for method in upscaleMethods
if "ncnn" in method or "directml" in method
]
interpolateMethods = [
method
for method in interpolateMethods
if "ncnn" in method or "directml" in method
]
if platform.system() == "Linux":
upscaleMethods = [
method for method in upscaleMethods if "directml" not in method
]
TOTALTESTS = len(upscaleMethods) + len(interpolateMethods) * 2
print(f"GPU Vendor: {GPUVENDOR}")
print(f"Total models to benchmark: {TOTALTESTS}")
print(f"Using {' '.join(executor)} version {version}")
print("Current working directory:", os.getcwd())
runAllBenchmarks(executor, version, inputVideo, systemInfo)