mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-28 03:50:11 +08:00
Refactored dataloader
This commit is contained in:
1 parent
a87b7c3b53
commit
dec7d25852
8 files changed
+845
-2
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
import typing
|
||||
from abc import ABC, ABCMeta, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
class FeatureDataloader(ABC):
|
||||
def __init__(
|
||||
self,
|
||||
cfg: dict,
|
||||
device: torch.device,
|
||||
image_list: torch.Tensor, # (N, 3, H, W)
|
||||
cache_path: Path,
|
||||
):
|
||||
self.cfg = cfg
|
||||
self.device = device
|
||||
self.cache_path = cache_path
|
||||
self.data = None # only expect data to be cached, nothing else
|
||||
self.try_load(image_list) # don't save image_list, avoid duplicates
|
||||
|
||||
@abstractmethod
|
||||
def __call__(self, img_points):
|
||||
# img_points: (B, 3) # (img_ind, x, y)
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def create(self, image_list: torch.Tensor):
|
||||
pass
|
||||
|
||||
def load(self):
|
||||
self.data = torch.from_numpy(np.load(self.cache_path))
|
||||
|
||||
def save(self):
|
||||
np.save(self.cache_path, self.data)
|
||||
|
||||
def try_load(self, img_list: torch.Tensor):
|
||||
try:
|
||||
self.load()
|
||||
except FileNotFoundError:
|
||||
self.create(img_list)
|
||||
self.save()
|
||||
Reference in new issue
Block a user