simplequeue

This commit is contained in:
Justin Kerr committed 2022-11-06 22:42:10 -08:00
1 parent 1ce3dd2f75
commit 0ca611dcb3
2 files changed
+15 -16

No files matched your search

+1 -1
View File
@@ -63,7 +63,7 @@ method_configs["nerfacto"] = Config(
pipeline=VanillaPipelineConfig( pipeline=VanillaPipelineConfig(
datamanager=VanillaDataManagerConfig( datamanager=VanillaDataManagerConfig(
dataparser=NerfstudioDataParserConfig(), dataparser=NerfstudioDataParserConfig(),
train_num_rays_per_batch=4096, train_num_rays_per_batch=8000,
eval_num_rays_per_batch=4096, eval_num_rays_per_batch=4096,
camera_optimizer=CameraOptimizerConfig( camera_optimizer=CameraOptimizerConfig(
mode="SO3xR3", optimizer=AdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-2) mode="SO3xR3", optimizer=AdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-2)
@@ -283,26 +283,21 @@ class Runner(MP_CON.Process):
self.train_dataset, self.train_dataset,
num_images_to_sample_from=self.config.train_num_images_to_sample_from, num_images_to_sample_from=self.config.train_num_images_to_sample_from,
num_times_to_repeat_images=self.config.train_num_times_to_repeat_images, num_times_to_repeat_images=self.config.train_num_times_to_repeat_images,
device='cpu', device=self.device,
num_workers=1, num_workers=2,
pin_memory=True, pin_memory=False,
) )
self.iter_train_image_dataloader = iter(self.train_image_dataloader) self.iter_train_image_dataloader = iter(self.train_image_dataloader)
self.train_pixel_sampler = PixelSampler(self.config.train_num_rays_per_batch) self.train_pixel_sampler = PixelSampler(self.config.train_num_rays_per_batch)
self.train_ray_generator = RayGenerator( self.train_ray_generator = RayGenerator(
self.train_dataset.dataparser_outputs.cameras.to('cpu') self.train_dataset.dataparser_outputs.cameras.to(self.device)
) ).to(self.device)
while True: while True:
image_batch = next(self.iter_train_image_dataloader) image_batch = next(self.iter_train_image_dataloader)
batch = self.train_pixel_sampler.sample(image_batch) batch = self.train_pixel_sampler.sample(image_batch)
ray_indices = batch["indices"] ray_indices = batch["indices"]
ray_bundle = self.train_ray_generator(ray_indices).to(self.device) ray_bundle = self.train_ray_generator(ray_indices)
while True: self.bundle_queue.put((ray_bundle.origins,ray_bundle.directions,ray_bundle.pixel_area,ray_bundle.camera_indices,batch))
try:
self.bundle_queue.put((ray_bundle,batch),block=False)
break
except queue.Full:
time.sleep(.02)
class VanillaDataManager(DataManager): # pylint: disable=abstract-method class VanillaDataManager(DataManager): # pylint: disable=abstract-method
@@ -340,8 +335,8 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
self.train_dataset = self.create_train_dataset() self.train_dataset = self.create_train_dataset()
self.eval_dataset = self.create_eval_dataset() self.eval_dataset = self.create_eval_dataset()
self.bundle_queue = MP_CON.Queue(4)#including Manager() is important for speed self.bundle_queue = MP_CON.SimpleQueue()
runners = [Runner(self.bundle_queue, self.train_dataset, self.device,self.config) for i in range(3)] runners = [Runner(self.bundle_queue, self.train_dataset, self.device,self.config) for i in range(2)]
DataManager.__init__(self) DataManager.__init__(self)
def create_train_dataset(self) -> InputDataset: def create_train_dataset(self) -> InputDataset:
@@ -395,7 +390,11 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
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."""
self.train_count += 1 self.train_count += 1
ray_bundle,batch = self.bundle_queue.get(block=True) os,ds,ps,cs,batch = self.bundle_queue.get()
ray_bundle = RayBundle(
origins=os, directions=ds, pixel_area=ps, camera_indices=cs
)
# ray_bundle=ray_bundle.to(self.device)
ray_indices = ray_bundle.camera_indices ray_indices = ray_bundle.camera_indices
# Multiply in the camera optimization deltas to the rays # Multiply in the camera optimization deltas to the rays