Skip to content

Commit

Permalink
easyvolcap: dirty: update scripts and n_frames_total
Browse files Browse the repository at this point in the history
  • Loading branch information
dendenxu committed Jan 20, 2024
1 parent 5a4d8ac commit c87a781
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
3 changes: 3 additions & 0 deletions configs/exps/l3mhet/l3mhet_hospital.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
configs:
- configs/base.yaml # default arguments for the whole codebase
- configs/models/l3mhet.yaml # network model configuration
- configs/specs/blurry.yaml # empty temporal embedder
- configs/specs/optcam.yaml
- configs/specs/transient.yaml

dataloader_cfg:
dataset_cfg: &dataset_cfg
Expand Down
2 changes: 1 addition & 1 deletion easyvolcap/dataloaders/datasets/noop_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self,
self.closest_using_t = closest_using_t
self.n_views = (view_sample[1] - view_sample[0]) // view_sample[2] if view_sample[1] is not None else 1
self.n_latents = (frame_sample[1] - frame_sample[0]) // frame_sample[2] if frame_sample[1] is not None else 1
self.n_frame_total = self.n_latents
self.n_frames_total = self.n_latents
self.n_view_total = self.n_views

self.Rv = torch.as_tensor([
Expand Down
12 changes: 6 additions & 6 deletions easyvolcap/dataloaders/datasets/volumetric_video_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def __init__(self,
self.view_sample = view_sample
if self.view_sample[1] is not None: self.n_view_total = self.view_sample[1]
else: self.n_view_total = len(os.listdir(join(self.data_root, self.images_dir))) # total number of cameras before filtering
if self.frame_sample[1] is not None: self.n_frame_total = self.frame_sample[1]
else: self.n_frame_total = min([len(glob(join(self.data_root, self.images_dir, cam, '*'))) for cam in os.listdir(join(self.data_root, self.images_dir))]) # total number of images before filtering
if self.frame_sample[1] is not None: self.n_frames_total = self.frame_sample[1]
else: self.n_frames_total = min([len(glob(join(self.data_root, self.images_dir, cam, '*'))) for cam in os.listdir(join(self.data_root, self.images_dir))]) # total number of images before filtering
self.use_loaded_time = use_loaded_time

# Rendering and space carving bounds
Expand Down Expand Up @@ -355,15 +355,15 @@ def random_crop_size(self, value: torch.Tensor):
def load_paths(self):
# Load image related stuff for reading from disk later
# If number of images in folder does not match, here we'll get an error
ims = [[join(self.data_root, self.images_dir, cam, self.ims_pattern.format(frame=i)) for i in range(self.n_frame_total)] for cam in self.camera_names]
ims = [[join(self.data_root, self.images_dir, cam, self.ims_pattern.format(frame=i)) for i in range(self.n_frames_total)] for cam in self.camera_names]
if not exists(ims[0][0]):
ims = [[i.replace('.' + self.ims_pattern.split('.')[-1], '.JPG') for i in im] for im in ims]
if not exists(ims[0][0]):
ims = [[i.replace('.JPG', '.png') for i in im] for im in ims]
if not exists(ims[0][0]):
ims = [[i.replace('.png', '.PNG') for i in im] for im in ims]
if not exists(ims[0][0]):
ims = [sorted(glob(join(self.data_root, self.images_dir, cam, '*')))[:self.n_frame_total] for cam in self.camera_names]
ims = [sorted(glob(join(self.data_root, self.images_dir, cam, '*')))[:self.n_frames_total] for cam in self.camera_names]
ims = [np.asarray(ims[i])[:min([len(i) for i in ims])] for i in range(len(ims))] # deal with the fact that some weird dataset has different number of images
self.ims = np.asarray(ims) # V, N
self.ims_dir = join(*split(dirname(self.ims[0, 0]))[:-1]) # logging only
Expand Down Expand Up @@ -656,7 +656,7 @@ def load_cameras(self):
if exists(join(self.data_root, self.intri_file)) and exists(join(self.data_root, self.extri_file)):
self.cameras = read_camera(join(self.data_root, self.intri_file), join(self.data_root, self.extri_file))
self.camera_names = np.asarray(sorted(list(self.cameras.keys()))) # NOTE: sorting camera names
self.cameras = dotdict({k: [self.cameras[k] for i in range(self.n_frame_total)] for k in self.camera_names})
self.cameras = dotdict({k: [self.cameras[k] for i in range(self.n_frames_total)] for k in self.camera_names})
# TODO: Handle avg processing

# Monocular dataset loading, each camera has a separate folder
Expand Down Expand Up @@ -932,7 +932,7 @@ def frame_min(self): return self.frame_sample[0] if len(self.frame_sample) == 3

@property
def frame_max(self):
middle = (self.frame_sample[1] if self.frame_sample[1] else self.n_frame_total) - 1 # None -> all frames are loaded
middle = (self.frame_sample[1] if self.frame_sample[1] else self.n_frames_total) - 1 # None -> all frames are loaded
return middle if len(self.frame_sample) == 3 else max(self.frame_sample)

@property
Expand Down
14 changes: 12 additions & 2 deletions scripts/nerf/nerf_to_easyvolcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ def main():
c2w_opengl = np.array(transforms.frames[local_count].transform_matrix).astype(np.float32)
c2w_opencv = c2w_opengl @ np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
w2c_opencv = np.linalg.inv(c2w_opencv)
if 'fl_x' in transforms.frames[local_count]:
fx, fy, cx, cy = transforms.frames[local_count].fl_x, transforms.frames[local_count].fl_y, \
transforms.frames[local_count].cx, transforms.frames[local_count].cy
H, W = transforms.frames[local_count].h, transforms.frames[local_count].w
else:
fx, fy, cx, cy = 0.5 * W / np.tan(0.5 * transforms.camera_angle_x), \
0.5 * W / np.tan(0.5 * transforms.camera_angle_x), 0.5 * W, 0.5 * H

evc_cams[f'{local_count:06d}'] = {
'R': w2c_opencv[:3, :3],
'T': w2c_opencv[:3, 3:],
'K': np.array([[0.5 * W / np.tan(0.5 * transforms.camera_angle_x), 0, 0.5 * W],
[0, 0.5 * W / np.tan(0.5 * transforms.camera_angle_x), 0.5 * H],
'K': np.array([[fx, 0, cx],
[0, fy, cy],
[0, 0, 1]]),
'D': np.zeros((1, 5)),
'H': H,
'W': W,
}

# write the cameras
Expand Down
8 changes: 4 additions & 4 deletions scripts/preprocess/tools/align_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@


def load_align_cameras(data_root: str, intri_file: str, extri_file: str, camera_dir: str = 'cameras',
n_frame_total: int = 1, near: float = 0.2, far: float = 100.0,
n_frames_total: int = 1, near: float = 0.2, far: float = 100.0,
avg_using_all: bool = False, avg_max_count: int = 100):

# Multiview dataset loading, need to expand, will have redundant information
if exists(join(data_root, intri_file)) and exists(join(data_root, extri_file)):
cameras = read_camera(join(data_root, intri_file), join(data_root, extri_file))
camera_names = np.asarray(sorted(list(cameras.keys()))) # NOTE: sorting camera names
cameras = dotdict({k: [cameras[k] for i in range(n_frame_total)] for k in camera_names})
cameras = dotdict({k: [cameras[k] for i in range(n_frames_total)] for k in camera_names})
# Monocular dataset loading, each camera has a separate folder
elif exists(join(data_root, camera_dir)):
camera_names = np.asarray(sorted(os.listdir(join(data_root, camera_dir)))) # NOTE: sorting here is very important!
Expand Down Expand Up @@ -86,7 +86,7 @@ def main():
parser.add_argument('--extri_file', type=str, default='extri.yml')
parser.add_argument('--camera_dir', type=str, default='cameras')

parser.add_argument('--n_frame_total', type=int, default=1)
parser.add_argument('--n_frames_total', type=int, default=1)
parser.add_argument('--near', type=float, default=0.25)
parser.add_argument('--far', type=float, default=2.00)
parser.add_argument('--avg_using_all', action='store_true')
Expand All @@ -99,7 +99,7 @@ def main():
# Load and align cameras
Ks, Hs, Ws, Rs, Ts, ts, ns, fs, Ds = load_align_cameras(
args.data_root, args.intri_file, args.extri_file, args.camera_dir,
args.n_frame_total, args.near, args.far, args.avg_using_all, args.avg_max_count
args.n_frames_total, args.near, args.far, args.avg_using_all, args.avg_max_count
)

# Convert loaded and aligned cameras to `EasyMocap` format
Expand Down

0 comments on commit c87a781

Please sign in to comment.