Attempt at making viewer robust to random errors (#429)

* catch more specific errors

* reduce complication; simple handle of oom error

* lints
This commit is contained in:
evonneng authored and GitHub committed 2022-09-14 11:19:19 -07:00
1 parent 65ab15b5ce
commit 5469f2e6b8
5 files changed
+125 -8

No files matched your search

+22 -5
View File
@@ -20,6 +20,7 @@ import logging
import os
import sys
import threading
import time
from pathlib import Path
from typing import Any, Dict, Optional
@@ -106,8 +107,9 @@ class RenderThread(threading.Thread):
outputs = None
try:
with SetTrace(self.state.check_interrupt):
outputs = self.graph.get_outputs_for_camera_ray_bundle(self.camera_ray_bundle)
except IOChangeException as e:
with torch.no_grad():
outputs = self.graph.get_outputs_for_camera_ray_bundle(self.camera_ray_bundle)
except Exception as e: # pylint: disable=broad-except
self.exc = e
if outputs:
@@ -119,7 +121,6 @@ class RenderThread(threading.Thread):
def join(self, timeout=None):
threading.Thread.join(self)
torch.cuda.empty_cache()
if self.exc:
raise self.exc
@@ -544,7 +545,14 @@ class VisualizerState:
self.prev_colormap_type = colormap_type
# Calculate camera pose and intrinsics
image_height = self._calculate_image_height(camera_object, is_training)
try:
image_height = self._calculate_image_height(camera_object, is_training)
except ZeroDivisionError as e:
self.vis["renderingState/log_errors"].write("Error: Screen too small; no rays intersecting scene.")
time.sleep(0.03) # sleep to allow buffer to reset
print(f"Error: {e}")
return
if image_height is None:
return
@@ -585,8 +593,17 @@ class VisualizerState:
try:
render_thread.join()
check_thread.join()
except Exception: # pylint: disable=broad-except
except IOChangeException:
pass
except RuntimeError as e:
del camera_ray_bundle
torch.cuda.empty_cache()
time.sleep(0.5) # sleep to allow buffer to reset
self.vis["renderingState/log_errors"].write(
"Error: GPU out of memory. Reduce resolution to prevent viewer from crashing."
)
print(f"Error: {e}")
graph.train()
outputs = render_thread.vis_outputs
if outputs is not None: