mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 15:59:16 +08:00
moved logic for interrupting rendering to visutils (#102)
This commit is contained in:
1 parent
e837f8dbef
commit
be45d5c9bb
2 files changed
+10
-7
No files matched your search
@@ -18,7 +18,6 @@ The Graph module contains all trainable parameters.
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
@@ -34,7 +33,6 @@ from pyrad.graphs.modules.ray_generator import RayGenerator
|
|||||||
from pyrad.utils import profiler
|
from pyrad.utils import profiler
|
||||||
from pyrad.utils.config import GraphConfig
|
from pyrad.utils.config import GraphConfig
|
||||||
from pyrad.utils.misc import get_masked_dict, instantiate_from_dict_config, is_not_none
|
from pyrad.utils.misc import get_masked_dict, instantiate_from_dict_config, is_not_none
|
||||||
from pyrad.viewer.server.viewer_utils import CameraChangeException
|
|
||||||
|
|
||||||
|
|
||||||
@profiler.time_function
|
@profiler.time_function
|
||||||
@@ -178,7 +176,6 @@ class Graph(AbstractGraph):
|
|||||||
@torch.no_grad()
|
@torch.no_grad()
|
||||||
def get_outputs_for_camera_ray_bundle(self, camera_ray_bundle: RayBundle):
|
def get_outputs_for_camera_ray_bundle(self, camera_ray_bundle: RayBundle):
|
||||||
"""Takes in camera parameters and computes the output of the graph."""
|
"""Takes in camera parameters and computes the output of the graph."""
|
||||||
try:
|
|
||||||
assert is_not_none(camera_ray_bundle.num_rays_per_chunk)
|
assert is_not_none(camera_ray_bundle.num_rays_per_chunk)
|
||||||
image_height, image_width = camera_ray_bundle.origins.shape[:2]
|
image_height, image_width = camera_ray_bundle.origins.shape[:2]
|
||||||
num_rays = len(camera_ray_bundle)
|
num_rays = len(camera_ray_bundle)
|
||||||
@@ -197,8 +194,6 @@ class Graph(AbstractGraph):
|
|||||||
time.sleep(0.001) # visualizer allow thread to switch off
|
time.sleep(0.001) # visualizer allow thread to switch off
|
||||||
self.vis_outputs = outputs
|
self.vis_outputs = outputs
|
||||||
return outputs
|
return outputs
|
||||||
except CameraChangeException:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_outputs_for_camera(self, camera: Camera):
|
def get_outputs_for_camera(self, camera: Camera):
|
||||||
"""Get the graph outputs for a Camera."""
|
"""Get the graph outputs for a Camera."""
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class VisualizerState:
|
|||||||
self._render_image_in_viewer(graph)
|
self._render_image_in_viewer(graph)
|
||||||
|
|
||||||
def _check_interrupt(self, frame, event, arg):
|
def _check_interrupt(self, frame, event, arg):
|
||||||
|
"""raises interrupt when flag has been set and not already on lowest resolution"""
|
||||||
if event == "line":
|
if event == "line":
|
||||||
if self.check_interrupt_vis and self.res_upscale_factor > 1:
|
if self.check_interrupt_vis and self.res_upscale_factor > 1:
|
||||||
self.res_upscale_factor = 1
|
self.res_upscale_factor = 1
|
||||||
@@ -96,7 +97,6 @@ class VisualizerState:
|
|||||||
if self.vis and step != 0:
|
if self.vis and step != 0:
|
||||||
if self.res_upscale_factor == 1:
|
if self.res_upscale_factor == 1:
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
steps_per_render_image = min(default_steps * self.res_upscale_factor, 100)
|
steps_per_render_image = min(default_steps * self.res_upscale_factor, 100)
|
||||||
return step % steps_per_render_image == 0
|
return step % steps_per_render_image == 0
|
||||||
return False
|
return False
|
||||||
@@ -138,11 +138,19 @@ class VisualizerState:
|
|||||||
self.check_interrupt_vis = True
|
self.check_interrupt_vis = True
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
|
def _interruptable_get_outputs_for_camera_ray_bundle(self, graph, camera_ray_bundle: RayBundle):
|
||||||
|
"""wrapper around graph function, terminating when interrupting"""
|
||||||
|
try:
|
||||||
|
outputs = graph.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
|
||||||
|
return outputs
|
||||||
|
except CameraChangeException:
|
||||||
|
return None
|
||||||
|
|
||||||
@torch.no_grad()
|
@torch.no_grad()
|
||||||
def _async_get_visualizer_outputs(self, graph, camera_ray_bundle: RayBundle):
|
def _async_get_visualizer_outputs(self, graph, camera_ray_bundle: RayBundle):
|
||||||
"""async getter function for visualizer without returning"""
|
"""async getter function for visualizer without returning"""
|
||||||
with SetTrace(self._check_interrupt):
|
with SetTrace(self._check_interrupt):
|
||||||
graph.get_outputs_for_camera_ray_bundle(camera_ray_bundle)
|
self._interruptable_get_outputs_for_camera_ray_bundle(graph, camera_ray_bundle)
|
||||||
self.check_done_render = True
|
self.check_done_render = True
|
||||||
self.check_interrupt_vis = False
|
self.check_interrupt_vis = False
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user