Skip to content

Commit 50c7418

Browse files
committed
ok
1 parent ca2cec9 commit 50c7418

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

configs/inference.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ input:
1616
reference_frame_path: "path/to/reference_frame.jpg"
1717

1818
output:
19-
path: "output.mp4" # or "path/to/output.png" for single frame
19+
path: "output.mp4" # or "path/to/output.png" for single frame
20+
directory: "image_reconstruction"

inference.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ def load_image(image_path, transform):
1818
def save_output(tensor, filename):
1919
save_image(tensor, filename, normalize=True)
2020

21-
def process_video(model, video_path, output_path, transform, device, frame_skip=0):
21+
def process_video(model, video_path, output_dir, transform, device, frame_skip=0):
2222
ctx = gpu(0) if torch.cuda.is_available() else cpu(0)
2323
vr = VideoReader(video_path, ctx=ctx)
2424

25-
fps = vr.get_avg_fps()
26-
width, height = vr[0].shape[1], vr[0].shape[0]
27-
28-
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
29-
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
25+
# Create output directory if it doesn't exist
26+
# os.makedirs(output_dir, exist_ok=True)
3027

3128
# Process reference frame
3229
reference_frame = vr[0].asnumpy()
@@ -50,13 +47,15 @@ def process_video(model, video_path, output_path, transform, device, frame_skip=
5047
t_c = model.latent_token_encoder(current_frame)
5148
reconstructed_frame = model.decode_latent_tokens(f_r, t_r, t_c)
5249

53-
reconstructed_frame = reconstructed_frame.squeeze().cpu().numpy().transpose(1, 2, 0)
54-
reconstructed_frame = (reconstructed_frame * 255).astype(np.uint8)
55-
reconstructed_frame = cv2.cvtColor(reconstructed_frame, cv2.COLOR_RGB2BGR)
56-
57-
out.write(reconstructed_frame)
50+
# Convert the reconstructed frame to a PIL Image
51+
reconstructed_frame = reconstructed_frame.squeeze().cpu()
52+
reconstructed_frame = transforms.ToPILImage()(reconstructed_frame)
53+
54+
# Save the reconstructed frame as an image
55+
output_path = os.path.join(output_dir, f"frame_{i:04d}.png")
56+
reconstructed_frame.save(output_path)
5857

59-
out.release()
58+
print(f"Processed {total_frames} frames. Output saved in {output_dir}")
6059

6160
def main():
6261
# Load configuration
@@ -83,7 +82,7 @@ def main():
8382
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
8483
])
8584

86-
process_video(model, config.input.video_path, config.output.path, transform, device, config.input.frame_skip)
85+
process_video(model, config.input.video_path, config.output.directory, transform, device, config.input.frame_skip)
8786

8887

8988
if __name__ == "__main__":

0 commit comments

Comments
 (0)