Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed errors and added updates #83

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,109 changes: 4,771 additions & 338 deletions 4DGaussians.ipynb

Large diffs are not rendered by default.

Binary file added Output Videos/T_rex.mp4
Binary file not shown.
Binary file added Output Videos/bouncing_balls.mp4
Binary file not shown.
Binary file added Output Videos/hell_warrior.mp4
Binary file not shown.
Binary file added Output Videos/hook.mp4
Binary file not shown.
Binary file added Output Videos/jumping_jacks.mp4
Binary file not shown.
Binary file added Output Videos/lego.mp4
Binary file not shown.
Binary file added Output Videos/mutant.mp4
Binary file not shown.
Binary file added Output Videos/standup.mp4
Binary file not shown.
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
torch==1.13.1
torchvision==0.14.1
torchaudio==0.13.1
mmcv==1.6.0
matplotlib
argparse
Expand Down
27 changes: 22 additions & 5 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from time import time
import copy

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
to8b = lambda x : (255*np.clip(x.cpu().numpy(),0,1)).astype(np.uint8)

try:
Expand Down Expand Up @@ -69,7 +70,8 @@ def scene_reconstruction(dataset, opt, hyper, pipe, testing_iterations, saving_i

progress_bar = tqdm(range(first_iter, final_iter), desc="Training progress")
first_iter += 1
# lpips_model = lpips.LPIPS(net="alex").cuda()
lpips_model = lpips.LPIPS(net="alex", version="0.1").eval().to(device)
lpips_model2 = lpips.LPIPS(net="vgg", version="0.1").eval().to(device)
video_cams = scene.getVideoCameras()
test_cams = scene.getTestCameras()
train_cams = scene.getTrainCameras()
Expand Down Expand Up @@ -215,7 +217,7 @@ def scene_reconstruction(dataset, opt, hyper, pipe, testing_iterations, saving_i
# if opt.lambda_lpips !=0:
# lpipsloss = lpips_loss(image_tensor,gt_image_tensor,lpips_model)
# loss += opt.lambda_lpips * lpipsloss

loss.backward()
if torch.isnan(loss).any():
print("loss is nan,end training, reexecv program now.")
Expand All @@ -240,7 +242,7 @@ def scene_reconstruction(dataset, opt, hyper, pipe, testing_iterations, saving_i

# Log and save
timer.pause()
training_report(tb_writer, iteration, Ll1, loss, l1_loss, iter_start.elapsed_time(iter_end), testing_iterations, scene, render, [pipe, background], stage, scene.dataset_type)
training_report(tb_writer, iteration, Ll1, loss, l1_loss, iter_start.elapsed_time(iter_end), testing_iterations, lpips_model, lpips_model2, scene, render, [pipe, background], stage, scene.dataset_type)
if (iteration in saving_iterations):
print("\n[ITER {}] Saving Gaussians".format(iteration))
scene.save(iteration, stage)
Expand Down Expand Up @@ -332,7 +334,7 @@ def prepare_output_and_logger(expname):
print("Tensorboard not available: not logging progress")
return tb_writer

def training_report(tb_writer, iteration, Ll1, loss, l1_loss, elapsed, testing_iterations, scene : Scene, renderFunc, renderArgs, stage, dataset_type):
def training_report(tb_writer, iteration, Ll1, loss, l1_loss, elapsed, testing_iterations, lpips_model, lpips_model2, scene : Scene, renderFunc, renderArgs, stage, dataset_type):
if tb_writer:
tb_writer.add_scalar(f'{stage}/train_loss_patches/l1_loss', Ll1.item(), iteration)
tb_writer.add_scalar(f'{stage}/train_loss_patchestotal_loss', loss.item(), iteration)
Expand All @@ -350,6 +352,10 @@ def training_report(tb_writer, iteration, Ll1, loss, l1_loss, elapsed, testing_i
if config['cameras'] and len(config['cameras']) > 0:
l1_test = 0.0
psnr_test = 0.0
ssim_test = 0.0
n = 0
lpips_test_a = 0.0
lpips_test_v = 0.0
for idx, viewpoint in enumerate(config['cameras']):
image = torch.clamp(renderFunc(viewpoint, scene.gaussians,stage=stage, cam_type=dataset_type, *renderArgs)["render"], 0.0, 1.0)
if dataset_type == "PanopticSports":
Expand All @@ -365,15 +371,26 @@ def training_report(tb_writer, iteration, Ll1, loss, l1_loss, elapsed, testing_i
pass
l1_test += l1_loss(image, gt_image).mean().double()
# mask=viewpoint.mask

lpips_test_a += lpips_model(gt_image, image, normalize=True).item()

lpips_test_v += lpips_model2(gt_image, image, normalize=True).item()

ssim_test += ssim(image,gt_image)
n += 1

psnr_test += psnr(image, gt_image, mask=None).mean().double()

psnr_test /= len(config['cameras'])
l1_test /= len(config['cameras'])
print("\n[ITER {}] Evaluating {}: L1 {} PSNR {}".format(iteration, config['name'], l1_test, psnr_test))
print("\n[ITER {}] Evaluating {}: L1 {} PSNR {} SSIM {} LPIPSA {} LPIPSV {}".format(iteration, config['name'], l1_test, psnr_test, ssim_test/n, lpips_test_a/n, lpips_test_v/n))
# print("sh feature",scene.gaussians.get_features.shape)
if tb_writer:
tb_writer.add_scalar(stage + "/"+config['name'] + '/loss_viewpoint - l1_loss', l1_test, iteration)
tb_writer.add_scalar(stage+"/"+config['name'] + '/loss_viewpoint - psnr', psnr_test, iteration)
tb_writer.add_scalar(stage+"/"+config['name'] + '/loss_viewpoint - ssim', ssim_test, iteration)
tb_writer.add_scalar(stage + "/"+config['name'] + '/loss_viewpoint - lpipsa', lpips_test_a, iteration)
tb_writer.add_scalar(stage+"/"+config['name'] + '/loss_viewpoint - lpipsv', lpips_test_v, iteration)

if tb_writer:
tb_writer.add_histogram(f"{stage}/scene/opacity_histogram", scene.gaussians.get_opacity, iteration)
Expand Down