Spaces:
Runtime error
Runtime error
Commit
·
c01d896
1
Parent(s):
3da1128
Update vtoonify_model.py
Browse files- vtoonify_model.py +10 -3
vtoonify_model.py
CHANGED
|
@@ -152,7 +152,9 @@ class Model():
|
|
| 152 |
message = 'Error: no face detected!'
|
| 153 |
instyle = torch.zeros(1,18,512).to(self.device)
|
| 154 |
video_cap = cv2.VideoCapture(video)
|
| 155 |
-
num = min(
|
|
|
|
|
|
|
| 156 |
success, frame = video_cap.read()
|
| 157 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 158 |
frame, instyle, message, w, h, top, bottom, left, right, scale = self.detect_and_align(frame, top, bottom, left, right, True)
|
|
@@ -199,7 +201,9 @@ class Model():
|
|
| 199 |
if exstyle is None:
|
| 200 |
exstyle = self.exstyle
|
| 201 |
video_cap = cv2.VideoCapture(aligned_video)
|
| 202 |
-
num = min(
|
|
|
|
|
|
|
| 203 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 204 |
videoWriter = cv2.VideoWriter('output.mp4', fourcc,
|
| 205 |
video_cap.get(5), (int(video_cap.get(3)*4),
|
|
@@ -207,7 +211,10 @@ class Model():
|
|
| 207 |
|
| 208 |
batch_frames = []
|
| 209 |
if video_cap.get(3) != 0:
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
| 211 |
else:
|
| 212 |
batch_size = 1
|
| 213 |
print('Using batch size of %d on %d frames'%(batch_size, num))
|
|
|
|
| 152 |
message = 'Error: no face detected!'
|
| 153 |
instyle = torch.zeros(1,18,512).to(self.device)
|
| 154 |
video_cap = cv2.VideoCapture(video)
|
| 155 |
+
num = min(300, int(video_cap.get(7)))
|
| 156 |
+
if self.device == 'cpu':
|
| 157 |
+
num = min(100, num)
|
| 158 |
success, frame = video_cap.read()
|
| 159 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 160 |
frame, instyle, message, w, h, top, bottom, left, right, scale = self.detect_and_align(frame, top, bottom, left, right, True)
|
|
|
|
| 201 |
if exstyle is None:
|
| 202 |
exstyle = self.exstyle
|
| 203 |
video_cap = cv2.VideoCapture(aligned_video)
|
| 204 |
+
num = min(300, int(video_cap.get(7)))
|
| 205 |
+
if self.device == 'cpu':
|
| 206 |
+
num = min(100, num)
|
| 207 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 208 |
videoWriter = cv2.VideoWriter('output.mp4', fourcc,
|
| 209 |
video_cap.get(5), (int(video_cap.get(3)*4),
|
|
|
|
| 211 |
|
| 212 |
batch_frames = []
|
| 213 |
if video_cap.get(3) != 0:
|
| 214 |
+
if self.device == 'cpu':
|
| 215 |
+
batch_size = max(1, int(4 * 256* 256/ video_cap.get(3) / video_cap.get(4)))
|
| 216 |
+
else:
|
| 217 |
+
batch_size = min(max(1, int(4 * 400 * 360/ video_cap.get(3) / video_cap.get(4))), 4)
|
| 218 |
else:
|
| 219 |
batch_size = 1
|
| 220 |
print('Using batch size of %d on %d frames'%(batch_size, num))
|