Spaces:
Runtime error
Runtime error
Commit
·
5837e1d
1
Parent(s):
eaba2a3
Update vtoonify_model.py
Browse files- vtoonify_model.py +7 -4
vtoonify_model.py
CHANGED
|
@@ -58,6 +58,8 @@ class Model():
|
|
| 58 |
self.vtoonify, self.exstyle = self._load_default_model()
|
| 59 |
self.color_transfer = False
|
| 60 |
self.style_name = 'cartoon1'
|
|
|
|
|
|
|
| 61 |
|
| 62 |
@staticmethod
|
| 63 |
def _create_dlib_landmark_model():
|
|
@@ -168,9 +170,9 @@ class Model():
|
|
| 168 |
if video_cap.get(7) == 0:
|
| 169 |
video_cap.release()
|
| 170 |
return 'default.mp4', instyle, 'Error: fail to load the video.'
|
| 171 |
-
num = min(
|
| 172 |
if self.device == 'cpu':
|
| 173 |
-
num = min(
|
| 174 |
success, frame = video_cap.read()
|
| 175 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 176 |
frame, instyle, message, w, h, top, bottom, left, right, scale = self.detect_and_align(frame, top, bottom, left, right, True)
|
|
@@ -178,6 +180,7 @@ class Model():
|
|
| 178 |
return 'default.mp4', instyle, message
|
| 179 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 180 |
videoWriter = cv2.VideoWriter('input.mp4', fourcc, video_cap.get(5), (int(right-left), int(bottom-top)))
|
|
|
|
| 181 |
kernel_1d = np.array([[0.125],[0.375],[0.375],[0.125]])
|
| 182 |
for i in range(num-1):
|
| 183 |
success, frame = video_cap.read()
|
|
@@ -226,9 +229,9 @@ class Model():
|
|
| 226 |
return 'default.mp4', 'Opps, something wrong with the input. Please go to Step 2 and Rescale Video again.'
|
| 227 |
if exstyle is None:
|
| 228 |
return 'default.mp4', 'Opps, something wrong with the style type. Please go to Step 1 and load model again.'
|
| 229 |
-
num = min(
|
| 230 |
if self.device == 'cpu':
|
| 231 |
-
num = min(
|
| 232 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 233 |
videoWriter = cv2.VideoWriter('output.mp4', fourcc,
|
| 234 |
video_cap.get(5), (int(video_cap.get(3)*4),
|
|
|
|
| 58 |
self.vtoonify, self.exstyle = self._load_default_model()
|
| 59 |
self.color_transfer = False
|
| 60 |
self.style_name = 'cartoon1'
|
| 61 |
+
self.video_limit_cpu = 100
|
| 62 |
+
self.video_limit_gpu = 300
|
| 63 |
|
| 64 |
@staticmethod
|
| 65 |
def _create_dlib_landmark_model():
|
|
|
|
| 170 |
if video_cap.get(7) == 0:
|
| 171 |
video_cap.release()
|
| 172 |
return 'default.mp4', instyle, 'Error: fail to load the video.'
|
| 173 |
+
num = min(self.video_limit_gpu, int(video_cap.get(7)))
|
| 174 |
if self.device == 'cpu':
|
| 175 |
+
num = min(self.video_limit_cpu, num)
|
| 176 |
success, frame = video_cap.read()
|
| 177 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 178 |
frame, instyle, message, w, h, top, bottom, left, right, scale = self.detect_and_align(frame, top, bottom, left, right, True)
|
|
|
|
| 180 |
return 'default.mp4', instyle, message
|
| 181 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 182 |
videoWriter = cv2.VideoWriter('input.mp4', fourcc, video_cap.get(5), (int(right-left), int(bottom-top)))
|
| 183 |
+
videoWriter.write(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
|
| 184 |
kernel_1d = np.array([[0.125],[0.375],[0.375],[0.125]])
|
| 185 |
for i in range(num-1):
|
| 186 |
success, frame = video_cap.read()
|
|
|
|
| 229 |
return 'default.mp4', 'Opps, something wrong with the input. Please go to Step 2 and Rescale Video again.'
|
| 230 |
if exstyle is None:
|
| 231 |
return 'default.mp4', 'Opps, something wrong with the style type. Please go to Step 1 and load model again.'
|
| 232 |
+
num = min(self.video_limit_gpu, int(video_cap.get(7)))
|
| 233 |
if self.device == 'cpu':
|
| 234 |
+
num = min(self.video_limit_cpu, num)
|
| 235 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 236 |
videoWriter = cv2.VideoWriter('output.mp4', fourcc,
|
| 237 |
video_cap.get(5), (int(video_cap.get(3)*4),
|