Skip to content

Commit

Permalink
code release
Browse files Browse the repository at this point in the history
  • Loading branch information
hw-liang committed Apr 2, 2024
1 parent 1041ef4 commit ed9493e
Show file tree
Hide file tree
Showing 24 changed files with 15 additions and 113 deletions.
Binary file removed data/a_Parrot.ply
Binary file not shown.
21 changes: 0 additions & 21 deletions mesh.py

This file was deleted.

24 changes: 0 additions & 24 deletions mesh2ply_8w.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,6 @@ def obj_to_ply(obj_filename, ply_filename):
o3d.io.write_point_cloud(ply_filename, pcd)
print(f"Point cloud saved to {ply_filename}")

# Replace 'path_to_obj.obj' with the path to your .obj file and
# 'output_path.ply' with the desired output path for the .ply file.
# obj_filename = './outputs/magic123-coarse-sd/new.png-a_panda_dancing@20231022-112824/save/it10000-export/model.obj'
# ply_filename = 'a.ply'
if __name__ == '__main__':
# obj_to_ply(obj_filename, ply_filename)
fire.Fire(obj_to_ply)
# def load_obj(filename):
# """
# Load the OBJ file and return vertices and faces.
# """
# vertices = []
# faces = []

# with open(filename, 'r') as file:
# for line in file:
# if line.startswith('v '):
# vertices.append(list(map(float, line.strip().split()[1:4])))
# elif line.startswith('f'):
# face = [int(i.split('/')[0]) for i in line.strip().split()[1:]]
# faces.append(face)

# return np.array(vertices), np.array(faces)

# res = load_obj(obj_filename)
# print(res[0].shape)
# print(res[1].shape)
13 changes: 1 addition & 12 deletions render_comp_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ def query_trajectory(generate_coordinates, t0, fps, frame_num):
translation_list = [generate_coordinates(t0 + i * fps) for i in range(frame_num)]
return translation_list

# def query_trajectory(t0, fps, frame_num):
# R = 0.5
# rot_speed = 1 / 3
# get_location = lambda t: np.array((R * np.sin(2 * np.pi * t * rot_speed), 0, R * np.cos(2 * np.pi * t * rot_speed)))
# translation_list = [get_location(t0 + i * fps) for i in range(frame_num)]
# return translation_list

to8b = lambda x : (255*np.clip(x.cpu().numpy(),0,1)).astype(np.uint8)
def render_set_fixcam(model_path, name, iteration, views, gaussians, pipeline, background,multiview_video, fname='video_rgb.mp4', func=None, scales=None, pre_scale=False, cam_idx=25):
render_path = os.path.join(model_path, name, "ours_{}".format(iteration), "renders")
Expand All @@ -107,11 +100,7 @@ def render_set_fixcam(model_path, name, iteration, views, gaussians, pipeline, b
gt_list = []
render_list = []
print(len(views))

# for idx, view in enumerate(tqdm(views, desc="Rendering progress")):
# for idx in tqdm(range (100)):
# fnum = 100
# fnum = 12

####
fnum = 48
for idx in tqdm(range (fnum)):
Expand Down
2 changes: 1 addition & 1 deletion scene/comp_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, args : ModelParams, gaussians : GaussianModel, load_iteration
# 4 is not used
# self.gaussians.load_3studio_ply(args.cloud_path, spatial_lr_scale=1, time_line=self.maxtime, step=1, position_scale=1/2.5, load_color=True) ## 4dfy
for idx, _ in enumerate(self.gaussians):
_.load_3studio_ply(args.cloud_path[idx], spatial_lr_scale=1, time_line=self.maxtime, pts_num=int(2.5e4), position_scale=1/2.5, load_color=True) ## 4dfy
_.load_3studio_ply(args.cloud_path[idx], spatial_lr_scale=1, time_line=self.maxtime, pts_num=int(2e4), position_scale=1/2.5, load_color=True) ## 4dfy
# self.gaussians.load_3studio_ply(cloud_path, spatial_lr_scale=1, time_line=self.maxtime, step=1, position_scale=1/2.5, load_color=True) ## 4dfy
# self.gaussians.load_3studio_ply(cloud_path, spatial_lr_scale=1, time_line=self.maxtime, step=1, position_scale=1, load_color=True) ## imagedream

Expand Down
3 changes: 0 additions & 3 deletions simple-knn/simple_knn.egg-info/PKG-INFO

This file was deleted.

8 changes: 0 additions & 8 deletions simple-knn/simple_knn.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion simple-knn/simple_knn.egg-info/dependency_links.txt

This file was deleted.

1 change: 0 additions & 1 deletion simple-knn/simple_knn.egg-info/top_level.txt

This file was deleted.

36 changes: 8 additions & 28 deletions train_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import os
import torch

from random import randint
from utils.loss_utils import l1_loss, ssim, l2_loss, lpips_loss
from gaussian_renderer.comp_renderer import render as render_comp
from gaussian_renderer import render as render_single
import sys
from scene.comp_scene import Scene
from scene.gaussian_model_nogrid import GaussianModel_nogrid as GaussianModel
from utils.general_utils import safe_state
import uuid
from tqdm import tqdm
from utils.image_utils import psnr
from argparse import ArgumentParser, Namespace
Expand All @@ -33,10 +31,6 @@
except ImportError:
TENSORBOARD_FOUND = False

# from guidance.zero123_utils import Zero123
# from guidance.zeroscope_utils_hifa import ZeroScope
# from guidance.zeroscope_utils import ZeroScope
# from guidance.mvdream_utils import MVDream
from guidance.sd_utils import StableDiffusion

from PIL import Image
Expand Down Expand Up @@ -103,20 +97,6 @@ def get_rotation(prev_pos, next_pos):
# canonical = np.array([0, 0, 1])
return find_rotation_matrix(canonical, new_vec)

# Constants
g = 9.81 # acceleration due to gravity, m/s^2

# Initial horizontal velocity calculation
vx = 2 # m/s, to cover 4 meters in 2 seconds

# To calculate the initial vertical velocity, we use the equation of motion at the peak (1 second into the jump)
# At the peak, vertical velocity (v) = 0, acceleration (a) = -g, time (t) = 1 sec
# We rearrange the equation v = u + at to find u: u = v - at
vy_initial = 0 - (-g) * 1 # Initial vertical velocity

# return np.array((x, z, y))
# return np.array((x, y, z))

def query_trajectory(generate_coordinates, t0, fps, frame_num):
# get_location = lambda t: np.array((R * np.sin(2 * np.pi * t * rot_speed), 0, R * np.cos(2 * np.pi * t * rot_speed)))
translation_list = [generate_coordinates(t0 + i * fps) for i in range(frame_num)]
Expand Down Expand Up @@ -205,13 +185,13 @@ def scene_reconstruction(dataset, opt, hyper, pipe, testing_iterations, saving_i
frame_num = viewpoint_stack.pose0_num

loader = iter(viewpoint_stack_loader)
if True:
try:
data = next(loader)
except StopIteration:
print("reset dataloader")
batch_size = 1
loader = iter(viewpoint_stack_loader)

try:
data = next(loader)
except StopIteration:
print("reset dataloader")
batch_size = 1
loader = iter(viewpoint_stack_loader)
if (iteration - 1) == debug_from:
pipe.debug = True
images = []
Expand Down Expand Up @@ -251,7 +231,7 @@ def scene_reconstruction(dataset, opt, hyper, pipe, testing_iterations, saving_i
radii = torch.cat(radii_list,0).max(dim=0).values
visibility_filter = torch.cat(visibility_filter_list).any(dim=0)
image_tensor = torch.cat(images,0)
# print('output', image_tensor.shape) # B, C, H, W

if len(out_pts):
out_pts = torch.stack(out_pts, 0)

Expand Down
4 changes: 2 additions & 2 deletions traj_funcs/butterfly_flower.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

def generate_coordinates(timestep): # [0, 1]
x = -2 + timestep*1.7
y = 0.6 - timestep*0.4
x = -2 + timestep * 1.5
y = 0.5 - timestep * 0.5
return np.array([x, y, 0]) # x y z
6 changes: 3 additions & 3 deletions traj_funcs/fish_rock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

def generate_coordinates(t): # [0, 1]
z = 0.8 * np.sin(t*np.pi/2)
def generate_coordinates(t):
z = 1.0 * np.sin(t*np.pi/2)
x = -1.5 * np.cos(t*np.pi/2)
return np.array([x, 0, z]) # x y z
return np.array([x, 0, z])
Binary file removed utils/__pycache__/camera_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/general_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/graphics_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/image_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/loss_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/params_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/scene_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/sh_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/system_utils.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/timer.cpython-37.pyc
Binary file not shown.
Binary file removed utils/__pycache__/utils.cpython-37.pyc
Binary file not shown.
9 changes: 0 additions & 9 deletions utils/camera_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

def loadCam(args, id, cam_info, resolution_scale):


# resized_image_rgb = PILtoTorch(cam_info.image, resolution)

# gt_image = resized_image_rgb[:3, ...]
# loaded_mask = None

# if resized_image_rgb.shape[1] == 4:
# loaded_mask = resized_image_rgb[3:4, ...]

return Camera(colmap_id=cam_info.uid, R=cam_info.R, T=cam_info.T,
FoVx=cam_info.FovX, FoVy=cam_info.FovY,
image=cam_info.image, gt_alpha_mask=None,
Expand Down

0 comments on commit ed9493e

Please sign in to comment.