Spaces:
Sleeping
Sleeping
Update src/facerender/animate.py
Browse files- src/facerender/animate.py +29 -53
src/facerender/animate.py
CHANGED
@@ -122,66 +122,42 @@ class AnimateFromCoeff():
|
|
122 |
|
123 |
from torch.cuda.amp import autocast
|
124 |
def generate(self, x, video_save_dir, pic_path, crop_info, enhancer=None, background_enhancer=None, preprocess='crop'):
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
# frame_num = x['frame_num']
|
148 |
-
|
149 |
-
# predictions_video = make_animation(source_image, source_semantics, target_semantics,
|
150 |
-
# self.generator, self.kp_extractor, self.he_estimator, self.mapping,
|
151 |
-
# yaw_c_seq, pitch_c_seq, roll_c_seq, use_exp = True)
|
152 |
-
|
153 |
-
# predictions_video = predictions_video.reshape((-1,)+predictions_video.shape[2:])
|
154 |
-
# predictions_video = predictions_video[:frame_num]
|
155 |
-
|
156 |
-
# video = []
|
157 |
-
# for idx in range(predictions_video.shape[0]):
|
158 |
-
# image = predictions_video[idx]
|
159 |
-
# image = np.transpose(image.data.cpu().numpy(), [1, 2, 0]).astype(np.float32)
|
160 |
-
# video.append(image)
|
161 |
-
# result = img_as_ubyte(video)
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
source_image = x['source_image'].to(self.device).type(torch.FloatTensor)
|
168 |
-
source_semantics = x['source_semantics'].to(self.device).type(torch.FloatTensor)
|
169 |
-
target_semantics = x['target_semantics_list'].to(self.device).type(torch.FloatTensor)
|
170 |
-
yaw_c_seq = x.get('yaw_c_seq', None).to(self.device).type(torch.FloatTensor) if 'yaw_c_seq' in x else None
|
171 |
-
pitch_c_seq = x.get('pitch_c_seq', None).to(self.device).type(torch.FloatTensor) if 'pitch_c_seq' in x else None
|
172 |
-
roll_c_seq = x.get('roll_c_seq', None).to(self.device).type(torch.FloatTensor) if 'roll_c_seq' in x else None
|
173 |
frame_num = x['frame_num']
|
174 |
|
175 |
-
|
176 |
-
predictions_video = make_animation(source_image, source_semantics, target_semantics,
|
177 |
self.generator, self.kp_extractor, self.he_estimator, self.mapping,
|
178 |
yaw_c_seq, pitch_c_seq, roll_c_seq, use_exp = True)
|
179 |
|
180 |
-
predictions_video = predictions_video.reshape((-1,)
|
181 |
predictions_video = predictions_video[:frame_num]
|
182 |
|
183 |
-
|
184 |
-
|
|
|
|
|
|
|
185 |
result = img_as_ubyte(video)
|
186 |
|
187 |
### the generated video is 256x256, so we keep the aspect ratio,
|
|
|
122 |
|
123 |
from torch.cuda.amp import autocast
|
124 |
def generate(self, x, video_save_dir, pic_path, crop_info, enhancer=None, background_enhancer=None, preprocess='crop'):
|
125 |
+
source_image=x['source_image'].type(torch.FloatTensor)
|
126 |
+
source_semantics=x['source_semantics'].type(torch.FloatTensor)
|
127 |
+
target_semantics=x['target_semantics_list'].type(torch.FloatTensor)
|
128 |
+
source_image=source_image.to(self.device)
|
129 |
+
source_semantics=source_semantics.to(self.device)
|
130 |
+
target_semantics=target_semantics.to(self.device)
|
131 |
+
if 'yaw_c_seq' in x:
|
132 |
+
yaw_c_seq = x['yaw_c_seq'].type(torch.FloatTensor)
|
133 |
+
yaw_c_seq = x['yaw_c_seq'].to(self.device)
|
134 |
+
else:
|
135 |
+
yaw_c_seq = None
|
136 |
+
if 'pitch_c_seq' in x:
|
137 |
+
pitch_c_seq = x['pitch_c_seq'].type(torch.FloatTensor)
|
138 |
+
pitch_c_seq = x['pitch_c_seq'].to(self.device)
|
139 |
+
else:
|
140 |
+
pitch_c_seq = None
|
141 |
+
if 'roll_c_seq' in x:
|
142 |
+
roll_c_seq = x['roll_c_seq'].type(torch.FloatTensor)
|
143 |
+
roll_c_seq = x['roll_c_seq'].to(self.device)
|
144 |
+
else:
|
145 |
+
roll_c_seq = None
|
146 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
frame_num = x['frame_num']
|
148 |
|
149 |
+
predictions_video = make_animation(source_image, source_semantics, target_semantics,
|
|
|
150 |
self.generator, self.kp_extractor, self.he_estimator, self.mapping,
|
151 |
yaw_c_seq, pitch_c_seq, roll_c_seq, use_exp = True)
|
152 |
|
153 |
+
predictions_video = predictions_video.reshape((-1,)+predictions_video.shape[2:])
|
154 |
predictions_video = predictions_video[:frame_num]
|
155 |
|
156 |
+
video = []
|
157 |
+
for idx in range(predictions_video.shape[0]):
|
158 |
+
image = predictions_video[idx]
|
159 |
+
image = np.transpose(image.data.cpu().numpy(), [1, 2, 0]).astype(np.float32)
|
160 |
+
video.append(image)
|
161 |
result = img_as_ubyte(video)
|
162 |
|
163 |
### the generated video is 256x256, so we keep the aspect ratio,
|