WIP yaml integration

This commit is contained in:
Chung Min Kim committed 2023-04-02 18:35:21 +00:00
1 parent dec7d25852
commit adcd206466
3 files changed
+23 -7

No files matched your search

+21 -5
View File
@@ -22,6 +22,7 @@ from dataclasses import dataclass, field
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Type, Union, Literal from typing import Any, Dict, List, Optional, Tuple, Type, Union, Literal
import os.path as osp import os.path as osp
import yaml
import torch import torch
from rich.progress import Console from rich.progress import Console
@@ -46,6 +47,9 @@ from lerf.encoders.image_encoder import BaseImageEncoder
@dataclass @dataclass
class LERFDataManagerConfig(VanillaDataManagerConfig): class LERFDataManagerConfig(VanillaDataManagerConfig):
_target: Type = field(default_factory=lambda: LERFDataManager) _target: Type = field(default_factory=lambda: LERFDataManager)
patch_tile_size_range: Tuple[int, int] = (0.05, 0.5)
patch_tile_size_res: int = 7
patch_stride_scaler: float = 0.5
class LERFDataManager(VanillaDataManager): # pylint: disable=abstract-method class LERFDataManager(VanillaDataManager): # pylint: disable=abstract-method
"""Basic stored data manager implementation. """Basic stored data manager implementation.
@@ -79,26 +83,38 @@ class LERFDataManager(VanillaDataManager): # pylint: disable=abstract-method
images = torch.cat(images) images = torch.cat(images)
cache_dir = f"outputs/{self.config.dataparser.data.name}" cache_dir = f"outputs/{self.config.dataparser.data.name}"
# clip_cache_path, dino_cache_path = self._search_cache(cache_dir)
clip_cache_path = osp.join(cache_dir, "clip")
dino_cache_path = osp.join(cache_dir, "dino.npy")
self.clip_interpolator = PatchedDataloader( self.clip_interpolator = PatchedDataloader(
image_list=images, image_list=images,
device=self.device, device=self.device,
cfg={ cfg=
{
"tile_size_range": (0.05, 0.5), "tile_size_range": (0.05, 0.5),
"tile_size_res": 7, "tile_size_res": 7,
"stride_scaler": 0.5, "stride_scaler": 0.5,
"image_shape": tuple(images.shape[2:4]) "image_shape": tuple(images.shape[2:4])
}, },
cache_path=Path(osp.join(cache_dir, "clip")), cache_path=clip_cache_path,
model=self.image_encoder, model=self.image_encoder,
) )
self.dino_dataloader = DinoDataloader( self.dino_dataloader = DinoDataloader(
image_list=images, device=self.device, image_list=images, device=self.device,
cfg={"image_shape": tuple(images.shape[2:4])}, cfg={"image_shape": tuple(images.shape[2:4])},
cache_path=Path(osp.join(cache_dir, "dino.npy")) cache_path=dino_cache_path
) )
def _search_cache(self): # def _search_cache(self, cache_path, prop_dict):
pass # if osp.exists(cache_path):
# # load yaml file
# with open(cache_path, "r") as f:
# cache = yaml.load(f, Loader=yaml.FullLoader)
# for k, v in cache.items():
# if k in self.config:
# self.config[k] = v
# else:
# ...
def next_train(self, step: int) -> Tuple[RayBundle, Dict]: def next_train(self, step: int) -> Tuple[RayBundle, Dict]:
"""Returns the next batch of data from the train dataloader.""" """Returns the next batch of data from the train dataloader."""
@@ -14,7 +14,7 @@ from lerf.encoders.image_encoder import BaseImageEncoder, BaseImageEncoderConfig
@dataclass @dataclass
class OpenCLIPNetworkConfig(BaseImageEncoderConfig): class OpenCLIPNetworkConfig(BaseImageEncoderConfig):
_target: Type = field(default_factory=lambda: OpenCLIPNetwork) _target: Type = field(default_factory=lambda: OpenCLIPNetwork)
name: str = "openclip" name: str = "openclip_vit_b_16"
description: str = "OpenCLIP network, images and text" description: str = "OpenCLIP network, images and text"
"""target class to instantiate""" """target class to instantiate"""
clip_model_type: str = "ViT-B-16" clip_model_type: str = "ViT-B-16"
+1 -1
View File
@@ -176,7 +176,7 @@ class LERFModel(NerfactoModel):
loss_dict["clip_loss"] = self.config.clip_loss_weight * torch.nn.functional.huber_loss( loss_dict["clip_loss"] = self.config.clip_loss_weight * torch.nn.functional.huber_loss(
outputs["clip"], batch["clip"], delta=1.25 outputs["clip"], batch["clip"], delta=1.25
) )
# loss_dict["dino_loss"] = torch.nn.functional.mse_loss(outputs["dino"], batch["dino"]) loss_dict["dino_loss"] = torch.nn.functional.mse_loss(outputs["dino"], batch["dino"])
return loss_dict return loss_dict
def get_param_groups(self) -> Dict[str, List[Parameter]]: def get_param_groups(self) -> Dict[str, List[Parameter]]: