4444 import mock # pylint: disable=g-import-not-at-top,unused-import
4545
4646
47- @tensorboard_test_util .run_v1_only ('requires tf.Session' )
4847class MeshPluginTest (tf .test .TestCase ):
4948 """Tests for mesh plugin server."""
5049
@@ -57,73 +56,71 @@ def setUp(self):
5756 self .log_dir = self .get_temp_dir ()
5857
5958 # Create mesh summary.
60- tf .compat .v1 .reset_default_graph ()
61- sess = tf .compat .v1 .Session ()
62- point_cloud = test_utils .get_random_mesh (1000 )
63- point_cloud_vertices = tf .compat .v1 .placeholder (tf .float32 ,
64- point_cloud .vertices .shape )
65-
66- mesh_no_color = test_utils .get_random_mesh (2000 , add_faces = True )
67- mesh_no_color_extended = test_utils .get_random_mesh (2500 , add_faces = True )
68- mesh_no_color_vertices = tf .compat .v1 .placeholder (
69- tf .float32 , [1 , None , 3 ])
70- mesh_no_color_faces = tf .compat .v1 .placeholder (tf .int32 ,
71- [1 , None , 3 ])
72-
73- mesh_color = test_utils .get_random_mesh (
74- 3000 , add_faces = True , add_colors = True )
75- mesh_color_vertices = tf .compat .v1 .placeholder (tf .float32 ,
76- mesh_color .vertices .shape )
77- mesh_color_faces = tf .compat .v1 .placeholder (tf .int32 ,
78- mesh_color .faces .shape )
79- mesh_color_colors = tf .compat .v1 .placeholder (tf .uint8 ,
80- mesh_color .colors .shape )
81- self .data = [
82- point_cloud , mesh_no_color , mesh_no_color_extended , mesh_color ]
83-
84- # In case when name is present and display_name is not, we will reuse name
85- # as display_name. Summaries below intended to test both cases.
86- self .names = ["point_cloud" , "mesh_no_color" , "mesh_color" ]
87- summary .op (
88- self .names [0 ],
89- point_cloud_vertices ,
90- description = "just point cloud" )
91- summary .op (
92- self .names [1 ],
93- mesh_no_color_vertices ,
94- faces = mesh_no_color_faces ,
95- display_name = "name_to_display_in_ui" ,
96- description = "beautiful mesh in grayscale" )
97- summary .op (
98- self .names [2 ],
99- mesh_color_vertices ,
100- faces = mesh_color_faces ,
101- colors = mesh_color_colors ,
102- description = "mesh with random colors" )
103-
104- merged_summary_op = tf .compat .v1 .summary .merge_all ()
105- self .runs = ["bar" ]
106- self .steps = 20
107- bar_directory = os .path .join (self .log_dir , self .runs [0 ])
108- with tensorboard_test_util .FileWriterCache .get (bar_directory ) as writer :
109- writer .add_graph (sess .graph )
110- for step in range (self .steps ):
111- # Alternate between two random meshes with different number of
112- # vertices.
113- no_color = mesh_no_color if step % 2 == 0 else mesh_no_color_extended
114- with patch .object (time , 'time' , return_value = step ):
115- writer .add_summary (
116- sess .run (
117- merged_summary_op ,
118- feed_dict = {
119- point_cloud_vertices : point_cloud .vertices ,
120- mesh_no_color_vertices : no_color .vertices ,
121- mesh_no_color_faces : no_color .faces ,
122- mesh_color_vertices : mesh_color .vertices ,
123- mesh_color_faces : mesh_color .faces ,
124- mesh_color_colors : mesh_color .colors ,
125- }),
126- global_step = step )
59+ with tf .compat .v1 .Graph ().as_default ():
60+ tf_placeholder = tf .compat .v1 .placeholder
61+ sess = tf .compat .v1 .Session ()
62+ point_cloud = test_utils .get_random_mesh (1000 )
63+ point_cloud_vertices = tf_placeholder (
64+ tf .float32 , point_cloud .vertices .shape
65+ )
66+
67+ mesh_no_color = test_utils .get_random_mesh (2000 , add_faces = True )
68+ mesh_no_color_extended = test_utils .get_random_mesh (2500 , add_faces = True )
69+ mesh_no_color_vertices = tf_placeholder (tf .float32 , [1 , None , 3 ])
70+ mesh_no_color_faces = tf_placeholder (tf .int32 , [1 , None , 3 ])
71+
72+ mesh_color = test_utils .get_random_mesh (
73+ 3000 , add_faces = True , add_colors = True )
74+ mesh_color_vertices = tf_placeholder (tf .float32 , mesh_color .vertices .shape )
75+ mesh_color_faces = tf_placeholder (tf .int32 , mesh_color .faces .shape )
76+ mesh_color_colors = tf_placeholder (tf .uint8 , mesh_color .colors .shape )
77+
78+ self .data = [
79+ point_cloud , mesh_no_color , mesh_no_color_extended , mesh_color ]
80+
81+ # In case when name is present and display_name is not, we will reuse name
82+ # as display_name. Summaries below intended to test both cases.
83+ self .names = ["point_cloud" , "mesh_no_color" , "mesh_color" ]
84+ summary .op (
85+ self .names [0 ],
86+ point_cloud_vertices ,
87+ description = "just point cloud" )
88+ summary .op (
89+ self .names [1 ],
90+ mesh_no_color_vertices ,
91+ faces = mesh_no_color_faces ,
92+ display_name = "name_to_display_in_ui" ,
93+ description = "beautiful mesh in grayscale" )
94+ summary .op (
95+ self .names [2 ],
96+ mesh_color_vertices ,
97+ faces = mesh_color_faces ,
98+ colors = mesh_color_colors ,
99+ description = "mesh with random colors" )
100+
101+ merged_summary_op = tf .compat .v1 .summary .merge_all ()
102+ self .runs = ["bar" ]
103+ self .steps = 20
104+ bar_directory = os .path .join (self .log_dir , self .runs [0 ])
105+ with tensorboard_test_util .FileWriterCache .get (bar_directory ) as writer :
106+ writer .add_graph (sess .graph )
107+ for step in range (self .steps ):
108+ # Alternate between two random meshes with different number of
109+ # vertices.
110+ no_color = mesh_no_color if step % 2 == 0 else mesh_no_color_extended
111+ with patch .object (time , 'time' , return_value = step ):
112+ writer .add_summary (
113+ sess .run (
114+ merged_summary_op ,
115+ feed_dict = {
116+ point_cloud_vertices : point_cloud .vertices ,
117+ mesh_no_color_vertices : no_color .vertices ,
118+ mesh_no_color_faces : no_color .faces ,
119+ mesh_color_vertices : mesh_color .vertices ,
120+ mesh_color_faces : mesh_color .faces ,
121+ mesh_color_colors : mesh_color .colors ,
122+ }),
123+ global_step = step )
127124
128125 # Start a server that will receive requests.
129126 self .multiplexer = event_multiplexer .EventMultiplexer ({
0 commit comments