integrating record3d and fix checkpoint delete issue (#722)

* integrating record3d

* fix save checkpoint logic

* added record3d data
This commit is contained in:
Ethan Weber authored and GitHub committed 2022-10-07 00:34:51 -07:00
1 parent fe5f7ea97d
commit 2531242d1d
3 files changed
+28 -12

No files matched your search

@@ -41,7 +41,7 @@ class Record3DDataParserConfig(DataParserConfig):
_target: Type = field(default_factory=lambda: Record3D) _target: Type = field(default_factory=lambda: Record3D)
"""target class to instantiate""" """target class to instantiate"""
data: Path = Path("data/record3d/garden") data: Path = Path("data/record3d/bear")
"""Location of data""" """Location of data"""
val_skip: int = 8 val_skip: int = 8
"""1/val_skip images to use for validation.""" """1/val_skip images to use for validation."""
@@ -49,7 +49,7 @@ class Record3DDataParserConfig(DataParserConfig):
"""Scene scale.""" """Scene scale."""
orientation_method: Literal["pca", "up"] = "up" orientation_method: Literal["pca", "up"] = "up"
"""The method to use for orientation""" """The method to use for orientation"""
max_dataset_size: int = 150 max_dataset_size: int = 300
"""Max number of images to train on. If the dataset has """Max number of images to train on. If the dataset has
more, images will be sampled approximately evenly.""" more, images will be sampled approximately evenly."""
@@ -69,7 +69,7 @@ class Record3D(DataParser):
image_filenames = [] image_filenames = []
for f in image_dir.iterdir(): for f in image_dir.iterdir():
if f.stem.isdigit(): # removes possible duplicate images (for example, 123(3).jpg) if f.stem.isdigit(): # removes possible duplicate images (for example, 123(3).jpg)
image_filenames.append(image_dir / f) image_filenames.append(f)
image_filenames = sorted(image_filenames, key=lambda fn: int(fn.stem)) image_filenames = sorted(image_filenames, key=lambda fn: int(fn.stem))
image_filenames = np.array(image_filenames) image_filenames = np.array(image_filenames)
+3 -3
View File
@@ -285,6 +285,9 @@ class Trainer:
pipeline = self.pipeline.module.state_dict() # type: ignore pipeline = self.pipeline.module.state_dict() # type: ignore
else: else:
pipeline = self.pipeline.state_dict() pipeline = self.pipeline.state_dict()
if len(self.prev_ckpt_paths) == self.config.trainer.num_ckpt_to_save:
self.prev_ckpt_paths[0].unlink(missing_ok=True)
self.prev_ckpt_paths.pop(0)
torch.save( torch.save(
{ {
"step": step, "step": step,
@@ -295,9 +298,6 @@ class Trainer:
ckpt_path, ckpt_path,
) )
self.prev_ckpt_paths.append(ckpt_path) self.prev_ckpt_paths.append(ckpt_path)
if len(self.prev_ckpt_paths) > self.config.trainer.num_ckpt_to_save:
self.prev_ckpt_paths[0].unlink(missing_ok=True)
self.prev_ckpt_paths.pop(0)
@profiler.time_function @profiler.time_function
def train_iteration(self, step: int) -> Tuple[torch.Tensor, Dict[str, torch.Tensor], Dict[str, torch.Tensor]]: def train_iteration(self, step: int) -> Tuple[torch.Tensor, Dict[str, torch.Tensor], Dict[str, torch.Tensor]]:
+22 -6
View File
@@ -56,7 +56,6 @@ def grab_file_id(zip_url: str) -> str:
nerfstudio_file_ids = { nerfstudio_file_ids = {
"bunny": grab_file_id("https://drive.google.com/file/d/1oVytSgd1gQclF0CybJ6JdXDmaqKOx7Wg/view?usp=sharing"),
"bww_entrance": grab_file_id("https://drive.google.com/file/d/1ylkRHtfB3n3IRLf2wplpfxzPTq7nES9I/view?usp=sharing"), "bww_entrance": grab_file_id("https://drive.google.com/file/d/1ylkRHtfB3n3IRLf2wplpfxzPTq7nES9I/view?usp=sharing"),
"bww_tree": grab_file_id("https://drive.google.com/file/d/1N_OQejT0MblK1UP05KORxy25SXjKqZN1/view?usp=sharing"), "bww_tree": grab_file_id("https://drive.google.com/file/d/1N_OQejT0MblK1UP05KORxy25SXjKqZN1/view?usp=sharing"),
"campanile": grab_file_id("https://drive.google.com/file/d/13aOfGJRRH05pOOk9ikYGTwqFc2L1xskU/view?usp=sharing"), "campanile": grab_file_id("https://drive.google.com/file/d/13aOfGJRRH05pOOk9ikYGTwqFc2L1xskU/view?usp=sharing"),
@@ -77,11 +76,11 @@ nerfstudio_file_ids = {
DatasetName = tyro.extras.literal_type_from_choices(nerfstudio_file_ids.keys()) DatasetName = tyro.extras.literal_type_from_choices(nerfstudio_file_ids.keys())
def download_nerfstudio(save_dir: Path, capture_name: str): def download_capture_name(save_dir: Path, dataset_name: str, capture_name: str, capture_name_to_file_id: dict):
"""Download specific captures from the nerfstudio dataset.""" """Download specific captures a given dataset and capture name."""
url = f"https://drive.google.com/uc?id={nerfstudio_file_ids[capture_name]}" url = f"https://drive.google.com/uc?id={capture_name_to_file_id[capture_name]}"
target_path = str(save_dir / f"nerfstudio/{capture_name}") target_path = str(save_dir / f"{dataset_name}/{capture_name}")
os.makedirs(target_path, exist_ok=True) os.makedirs(target_path, exist_ok=True)
download_path = Path(f"{target_path}.zip") download_path = Path(f"{target_path}.zip")
tmp_path = str(save_dir / ".temp") tmp_path = str(save_dir / ".temp")
@@ -99,8 +98,23 @@ def download_nerfstudio(save_dir: Path, capture_name: str):
os.remove(download_path) os.remove(download_path)
def download_nerfstudio(save_dir: Path, capture_name: str):
"""Download specific captures for the nerfstudio dataset."""
download_capture_name(save_dir, "nerfstudio", capture_name, capture_name_to_file_id=nerfstudio_file_ids)
record3d_file_ids = {
"bear": grab_file_id("https://drive.google.com/file/d/1WRZohWMRj0nNlYFIEBwkddDoGPvLTzkR/view?usp=sharing"),
}
def download_record3d(save_dir: Path, capture_name: str):
"""Download specific captures for the record3d dataset."""
download_capture_name(save_dir, "record3d", capture_name, capture_name_to_file_id=record3d_file_ids)
def main( def main(
dataset: Literal["blender", "friends", "nerfstudio"], dataset: Literal["blender", "friends", "nerfstudio", "record3d"],
capture_name: Optional[DatasetName] = None, # type: ignore capture_name: Optional[DatasetName] = None, # type: ignore
save_dir: Path = Path("data/"), save_dir: Path = Path("data/"),
): ):
@@ -137,6 +151,8 @@ def main(
console.print(f"\t {capture_names}") console.print(f"\t {capture_names}")
sys.exit() sys.exit()
download_nerfstudio(save_dir, capture_name) download_nerfstudio(save_dir, capture_name)
if dataset == "record3d":
download_record3d(save_dir, "bear")
def entrypoint(): def entrypoint():