Spaces:
Running
on
Zero
Running
on
Zero
Update inference_video.py
Browse files- inference_video.py +11 -13
inference_video.py
CHANGED
@@ -3,9 +3,7 @@ import numpy as np
|
|
3 |
import glob
|
4 |
from os.path import isfile, join
|
5 |
import subprocess
|
6 |
-
from IPython.display import clear_output
|
7 |
import os
|
8 |
-
from google.colab import files
|
9 |
import shutil
|
10 |
from io import BytesIO
|
11 |
import io
|
@@ -60,7 +58,7 @@ def inference_image(image, size):
|
|
60 |
model8.load_weights('weights/RealESRGAN_x8.pth', download=False)
|
61 |
result = model2.predict(image.convert('RGB'))
|
62 |
|
63 |
-
print(f"
|
64 |
return result
|
65 |
|
66 |
custom_name = "input.mp4"
|
@@ -68,7 +66,7 @@ custom_name = "input.mp4"
|
|
68 |
def save_video_input(video, custom_name):
|
69 |
try:
|
70 |
# Specify the desired output file path with the custom name and ".mp4" extension
|
71 |
-
output_file_path = f"videos/{custom_name}.mp4"
|
72 |
|
73 |
# Save the video input to the specified file path
|
74 |
with open(output_file_path, 'wb') as output_file:
|
@@ -124,8 +122,8 @@ for filename in os.listdir(directory):
|
|
124 |
try:
|
125 |
|
126 |
# PATH TO STORE VIDEO FRAMES
|
127 |
-
if not os.path.exists('upload'):
|
128 |
-
os.makedirs('upload')
|
129 |
|
130 |
# if not created then raise error
|
131 |
except OSError:
|
@@ -142,7 +140,7 @@ for filename in os.listdir(directory):
|
|
142 |
|
143 |
if ret:
|
144 |
# if video is still left continue creating images
|
145 |
-
name = 'upload/frame' + str(currentframe) + '.jpg'
|
146 |
|
147 |
# writing the extracted images
|
148 |
cv2.imwrite(name, frame)
|
@@ -166,31 +164,31 @@ for filename in os.listdir(directory):
|
|
166 |
#apply super-resolution on all frames of a video
|
167 |
|
168 |
# Specify the directory path
|
169 |
-
all_frames_path = "upload"
|
170 |
|
171 |
# Get a list of all files in the directory
|
172 |
file_names = os.listdir(all_frames_path)
|
173 |
|
174 |
# process the files
|
175 |
for file_name in file_names:
|
176 |
-
inference_image(f"upload/{file_name}")
|
177 |
|
178 |
|
179 |
#convert super res frames to .avi
|
180 |
-
pathIn = 'results/restored_imgs/'
|
181 |
|
182 |
zee = zee+1
|
183 |
fName = "video"+str(zee)
|
184 |
filenameVid = f"{fName}.avi"
|
185 |
|
186 |
-
pathOut = "results_videos/"+filenameVid
|
187 |
|
188 |
convert_frames_to_video(pathIn, pathOut, fps)
|
189 |
|
190 |
|
191 |
#convert .avi to .mp4
|
192 |
-
src = 'results_videos/'
|
193 |
-
dst = 'results_mp4_videos/'
|
194 |
|
195 |
for root, dirs, filenames in os.walk(src, topdown=False):
|
196 |
#print(filenames)
|
|
|
3 |
import glob
|
4 |
from os.path import isfile, join
|
5 |
import subprocess
|
|
|
6 |
import os
|
|
|
7 |
import shutil
|
8 |
from io import BytesIO
|
9 |
import io
|
|
|
58 |
model8.load_weights('weights/RealESRGAN_x8.pth', download=False)
|
59 |
result = model2.predict(image.convert('RGB'))
|
60 |
|
61 |
+
print(f"Frame of the Video size ({device}): {size} ... OK")
|
62 |
return result
|
63 |
|
64 |
custom_name = "input.mp4"
|
|
|
66 |
def save_video_input(video, custom_name):
|
67 |
try:
|
68 |
# Specify the desired output file path with the custom name and ".mp4" extension
|
69 |
+
output_file_path = f"/tmp/videos/{custom_name}.mp4"
|
70 |
|
71 |
# Save the video input to the specified file path
|
72 |
with open(output_file_path, 'wb') as output_file:
|
|
|
122 |
try:
|
123 |
|
124 |
# PATH TO STORE VIDEO FRAMES
|
125 |
+
if not os.path.exists('/tmp/upload/'):
|
126 |
+
os.makedirs('/tmp/upload/')
|
127 |
|
128 |
# if not created then raise error
|
129 |
except OSError:
|
|
|
140 |
|
141 |
if ret:
|
142 |
# if video is still left continue creating images
|
143 |
+
name = '/tmp/upload/frame' + str(currentframe) + '.jpg'
|
144 |
|
145 |
# writing the extracted images
|
146 |
cv2.imwrite(name, frame)
|
|
|
164 |
#apply super-resolution on all frames of a video
|
165 |
|
166 |
# Specify the directory path
|
167 |
+
all_frames_path = "/tmp/upload/"
|
168 |
|
169 |
# Get a list of all files in the directory
|
170 |
file_names = os.listdir(all_frames_path)
|
171 |
|
172 |
# process the files
|
173 |
for file_name in file_names:
|
174 |
+
inference_image(f"/tmp/upload/{file_name}")
|
175 |
|
176 |
|
177 |
#convert super res frames to .avi
|
178 |
+
pathIn = '/tmp/results/restored_imgs/'
|
179 |
|
180 |
zee = zee+1
|
181 |
fName = "video"+str(zee)
|
182 |
filenameVid = f"{fName}.avi"
|
183 |
|
184 |
+
pathOut = "/tmp/results_videos/"+filenameVid
|
185 |
|
186 |
convert_frames_to_video(pathIn, pathOut, fps)
|
187 |
|
188 |
|
189 |
#convert .avi to .mp4
|
190 |
+
src = '/tmp/results_videos/'
|
191 |
+
dst = '/tmp/results_mp4_videos/'
|
192 |
|
193 |
for root, dirs, filenames in os.walk(src, topdown=False):
|
194 |
#print(filenames)
|