9
9
import warnings
10
10
from collections import OrderedDict
11
11
from dataclasses import dataclass , field
12
- from typing import Any , Dict , List , Optional , Sequence , Tuple , Union
12
+ from typing import Any , Dict , List , Optional , Sequence , Tuple , TYPE_CHECKING , Union
13
13
14
14
import numpy as np
15
15
import torch
27
27
from pytorch3d .renderer .cameras import CamerasBase , PerspectiveCameras
28
28
from pytorch3d .vis .plotly_vis import plot_scene
29
29
from tabulate import tabulate
30
- from visdom import Visdom
30
+
31
+ if TYPE_CHECKING :
32
+ from visdom import Visdom
31
33
32
34
33
35
EVAL_N_SRC_VIEWS = [1 , 3 , 5 , 7 , 9 ]
@@ -43,14 +45,16 @@ class _Visualizer:
43
45
44
46
visdom_env : str = "eval_debug"
45
47
46
- _viz : Visdom = field (init = False )
48
+ _viz : Optional [ " Visdom" ] = field (init = False )
47
49
48
50
def __post_init__ (self ):
49
51
self ._viz = vis_utils .get_visdom_connection ()
50
52
51
53
def show_rgb (
52
54
self , loss_value : float , metric_name : str , loss_mask_now : torch .Tensor
53
55
):
56
+ if self ._viz is None :
57
+ return
54
58
self ._viz .images (
55
59
torch .cat (
56
60
(
@@ -68,7 +72,10 @@ def show_rgb(
68
72
def show_depth (
69
73
self , depth_loss : float , name_postfix : str , loss_mask_now : torch .Tensor
70
74
):
71
- self ._viz .images (
75
+ if self ._viz is None :
76
+ return
77
+ viz = self ._viz
78
+ viz .images (
72
79
torch .cat (
73
80
(
74
81
make_depth_image (self .depth_render , loss_mask_now ),
@@ -80,13 +87,13 @@ def show_depth(
80
87
win = "depth_abs" + name_postfix ,
81
88
opts = {"title" : f"depth_abs_{ name_postfix } _{ depth_loss :1.2f} " },
82
89
)
83
- self . _viz .images (
90
+ viz .images (
84
91
loss_mask_now ,
85
92
env = self .visdom_env ,
86
93
win = "depth_abs" + name_postfix + "_mask" ,
87
94
opts = {"title" : f"depth_abs_{ name_postfix } _{ depth_loss :1.2f} _mask" },
88
95
)
89
- self . _viz .images (
96
+ viz .images (
90
97
self .depth_mask ,
91
98
env = self .visdom_env ,
92
99
win = "depth_abs" + name_postfix + "_maskd" ,
@@ -126,7 +133,7 @@ def show_depth(
126
133
pointcloud_max_points = 10000 ,
127
134
pointcloud_marker_size = 1 ,
128
135
)
129
- self . _viz .plotlyplot (
136
+ viz .plotlyplot (
130
137
plotlyplot ,
131
138
env = self .visdom_env ,
132
139
win = f"pcl{ name_postfix } " ,
0 commit comments