mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 15:59:16 +08:00
fixed bug; added optimizations to interrupt (#191)
* fixed bug; added optimizations to interrupt * removed timed sleep * lint
This commit is contained in:
1 parent
35e12c98cc
commit
41347d908b
2 files changed
+11
-21
No files matched your search
@@ -17,7 +17,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
|
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
@@ -202,10 +201,8 @@ class Graph(AbstractGraph):
|
|||||||
outputs = self.forward_after_ray_generator(ray_bundle)
|
outputs = self.forward_after_ray_generator(ray_bundle)
|
||||||
for output_name, output in outputs.items():
|
for output_name, output in outputs.items():
|
||||||
outputs_lists[output_name].append(output)
|
outputs_lists[output_name].append(output)
|
||||||
time.sleep(0.001) # visualizer allow thread to switch off
|
|
||||||
for output_name, outputs_list in outputs_lists.items():
|
for output_name, outputs_list in outputs_lists.items():
|
||||||
outputs[output_name] = torch.cat(outputs_list).view(image_height, image_width, -1)
|
outputs[output_name] = torch.cat(outputs_list).view(image_height, image_width, -1)
|
||||||
time.sleep(0.001) # visualizer allow thread to switch off
|
|
||||||
self.vis_outputs = outputs
|
self.vis_outputs = outputs
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ class CheckThread(threading.Thread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.state.check_done_render = False
|
self.state.check_done_render = False
|
||||||
is_interrupt = False
|
|
||||||
while not self.state.check_done_render:
|
while not self.state.check_done_render:
|
||||||
# check camera
|
# check camera
|
||||||
data = self.state.vis["/Cameras/Main Camera"].get_object()
|
data = self.state.vis["/Cameras/Main Camera"].get_object()
|
||||||
@@ -107,8 +106,8 @@ class CheckThread(threading.Thread):
|
|||||||
if self.state.prev_camera_matrix is None or not np.allclose(
|
if self.state.prev_camera_matrix is None or not np.allclose(
|
||||||
camera_object["matrix"], self.state.prev_camera_matrix
|
camera_object["matrix"], self.state.prev_camera_matrix
|
||||||
):
|
):
|
||||||
is_interrupt = True
|
self.state.check_interrupt_vis = True
|
||||||
self.state.prev_camera_matrix = camera_object["matrix"]
|
return
|
||||||
|
|
||||||
# check output type
|
# check output type
|
||||||
data = self.state.vis["/Output Type"].get_object()
|
data = self.state.vis["/Output Type"].get_object()
|
||||||
@@ -117,26 +116,24 @@ class CheckThread(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
output_type = data["output_type"]
|
output_type = data["output_type"]
|
||||||
if self.state.prev_output_type != output_type:
|
if self.state.prev_output_type != output_type:
|
||||||
is_interrupt = True
|
self.state.check_interrupt_vis = True
|
||||||
|
return
|
||||||
|
|
||||||
# check max render
|
# check max render
|
||||||
data = self.state.vis["/Max Resolution"].get_object()
|
data = self.state.vis["/Max Resolution"].get_object()
|
||||||
if data is not None:
|
if data is not None:
|
||||||
max_resolution = int(data["max_resolution"])
|
max_resolution = int(data["max_resolution"])
|
||||||
if self.state.max_resolution != max_resolution:
|
if self.state.max_resolution != max_resolution:
|
||||||
is_interrupt = True
|
self.state.check_interrupt_vis = True
|
||||||
self.state.max_resolution = max_resolution
|
return
|
||||||
|
|
||||||
# check min render
|
# check min render
|
||||||
data = self.state.vis["/Min Resolution"].get_object()
|
data = self.state.vis["/Min Resolution"].get_object()
|
||||||
if data is not None:
|
if data is not None:
|
||||||
min_resolution = int(data["min_resolution"])
|
min_resolution = int(data["min_resolution"])
|
||||||
if self.state.min_resolution != min_resolution:
|
if self.state.min_resolution != min_resolution:
|
||||||
is_interrupt = True
|
self.state.check_interrupt_vis = True
|
||||||
self.state.min_resolution = min_resolution
|
return
|
||||||
|
|
||||||
self.state.check_interrupt_vis = is_interrupt
|
|
||||||
time.sleep(0.001)
|
|
||||||
|
|
||||||
|
|
||||||
@decorate_all([check_visualizer_enabled])
|
@decorate_all([check_visualizer_enabled])
|
||||||
@@ -163,7 +160,7 @@ class VisualizerState:
|
|||||||
self.check_interrupt_vis = False
|
self.check_interrupt_vis = False
|
||||||
self.check_done_render = True
|
self.check_done_render = True
|
||||||
self.last_render_time = time.time()
|
self.last_render_time = time.time()
|
||||||
self.min_wait_time = 5.0
|
self.min_wait_time = 0.5 # 1.0 is on high side and will cause lag
|
||||||
|
|
||||||
self.outputs_set = False
|
self.outputs_set = False
|
||||||
|
|
||||||
@@ -198,12 +195,12 @@ class VisualizerState:
|
|||||||
raise IOChangeException
|
raise IOChangeException
|
||||||
return self.check_interrupt
|
return self.check_interrupt
|
||||||
|
|
||||||
def _is_render_step(self, step: int, default_steps: int = 5) -> bool:
|
def _is_render_step(self, step: int, default_steps: int = 2, max_steps: int = 10) -> bool:
|
||||||
"""dynamically calculate when to render grapic based on resolution of image"""
|
"""dynamically calculate when to render grapic based on resolution of image"""
|
||||||
if step != 0:
|
if step != 0:
|
||||||
if self.res_upscale_factor == 1:
|
if self.res_upscale_factor == 1:
|
||||||
return True
|
return True
|
||||||
steps_per_render_image = min(default_steps * self.res_upscale_factor, 100)
|
steps_per_render_image = min(default_steps * self.res_upscale_factor, max_steps)
|
||||||
steps_condition = step % steps_per_render_image == 0
|
steps_condition = step % steps_per_render_image == 0
|
||||||
if steps_condition:
|
if steps_condition:
|
||||||
if self.res_upscale_factor > 3:
|
if self.res_upscale_factor > 3:
|
||||||
@@ -305,10 +302,6 @@ class VisualizerState:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
render_thread.join()
|
render_thread.join()
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
check_thread.join()
|
check_thread.join()
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in new issue
Block a user