Beispiel #1
0
 def test_tags(self):
     """Tests proper tags for each event/tensor."""
     tensor_data = test_utils.get_random_mesh(100,
                                              add_faces=True,
                                              add_colors=True)
     config_dict = {"foo": 1}
     name = "foo"
     events = self.mesh_events(
         name,
         tensor_data.vertices,
         faces=tensor_data.faces,
         colors=tensor_data.colors,
         config_dict=config_dict,
         step=333,
     )
     expected_names_set = frozenset(
         name_tpl % name
         for name_tpl in ["%s_VERTEX", "%s_FACE", "%s_COLOR"])
     actual_names_set = frozenset(
         [event.summary.value[0].tag for event in events])
     self.assertEqual(expected_names_set, actual_names_set)
     expected_bitmask = metadata.get_components_bitmask([
         plugin_data_pb2.MeshPluginData.VERTEX,
         plugin_data_pb2.MeshPluginData.FACE,
         plugin_data_pb2.MeshPluginData.COLOR,
     ])
     for event in events:
         self.assertEqual(expected_bitmask,
                          self.get_metadata(event).components)
Beispiel #2
0
 def test_get_tensor_summary(self):
     """Tests proper creation of tensor summary with mesh plugin
     metadata."""
     name = "my_mesh"
     display_name = "my_display_name"
     description = "my mesh is the best of meshes"
     tensor_data = test_utils.get_random_mesh(100)
     components = 14
     with tf.compat.v1.Graph().as_default():
         tensor_summary = summary._get_tensor_summary(
             name,
             display_name,
             description,
             tensor_data.vertices,
             plugin_data_pb2.MeshPluginData.VERTEX,
             components,
             "",
             None,
         )
         with self.test_session():
             proto = self.pb_via_op(tensor_summary)
             self.assertEqual("%s_VERTEX" % name, proto.value[0].tag)
             self.assertEqual(
                 metadata.PLUGIN_NAME,
                 proto.value[0].metadata.plugin_data.plugin_name,
             )
             self.assertEqual(components,
                              self.get_components(proto.value[0]))
Beispiel #3
0
 def test_op(self):
     """Tests merged summary with different types of data."""
     name = "my_mesh"
     tensor_data = test_utils.get_random_mesh(
         100, add_faces=True, add_colors=True
     )
     config_dict = {"foo": 1}
     with tf.compat.v1.Graph().as_default():
         tensor_summary = summary.op(
             name,
             tensor_data.vertices,
             faces=tensor_data.faces,
             colors=tensor_data.colors,
             config_dict=config_dict,
         )
         with self.test_session() as sess:
             proto = self.pb_via_op(tensor_summary)
             self.verify_proto(proto, name)
             plugin_metadata = metadata.parse_plugin_metadata(
                 proto.value[0].metadata.plugin_data.content
             )
             self.assertEqual(
                 json.dumps(config_dict, sort_keys=True),
                 plugin_metadata.json_config,
             )
 def test_step(self):
     """Tests that different components of mesh summary share the same step."""
     tensor_data = test_utils.get_random_mesh(100,
                                              add_faces=True,
                                              add_colors=True)
     config_dict = {"foo": 1}
     events = self.mesh_events('a',
                               tensor_data.vertices,
                               faces=tensor_data.faces,
                               colors=tensor_data.colors,
                               config_dict=config_dict,
                               step=333)
     self.assertEqual(333, events[0].step)
     self.assertEqual(333, events[1].step)
     self.assertEqual(333, events[2].step)
 def test_pb(self):
     """Tests ProtoBuf interface."""
     name = "my_mesh"
     tensor_data = test_utils.get_random_mesh(100,
                                              add_faces=True,
                                              add_colors=True)
     config_dict = {"foo": 1}
     proto = summary.mesh_pb(name,
                             tensor_data.vertices,
                             faces=tensor_data.faces,
                             colors=tensor_data.colors,
                             config_dict=config_dict)
     plugin_metadata = metadata.parse_plugin_metadata(
         proto.value[0].metadata.plugin_data.content)
     self.assertEqual(json.dumps(config_dict, sort_keys=True),
                      plugin_metadata.json_config)
Beispiel #6
0
 def test_pb(self):
     """Tests merged summary protobuf with different types of data."""
     name = "my_mesh"
     tensor_data = test_utils.get_random_mesh(100,
                                              add_faces=True,
                                              add_colors=True)
     config_dict = {"foo": 1}
     proto = summary.pb(name,
                        tensor_data.vertices,
                        faces=tensor_data.faces,
                        colors=tensor_data.colors,
                        config_dict=config_dict)
     self.verify_proto(proto, name)
     plugin_metadata = metadata.parse_plugin_metadata(
         proto.value[0].metadata.plugin_data.content)
     self.assertEqual(json.dumps(config_dict, sort_keys=True),
                      plugin_metadata.json_config)
    def setUp(self):
        # We use numpy.random to generate meshes. We seed to avoid non-determinism
        # in this test.
        np.random.seed(17)

        # Log dir to save temp events into.
        self.log_dir = self.get_temp_dir()

        # Create mesh summary.
        with tf.compat.v1.Graph().as_default():
            tf_placeholder = tf.compat.v1.placeholder
            sess = tf.compat.v1.Session()
            point_cloud = test_utils.get_random_mesh(1000)
            point_cloud_vertices = tf_placeholder(tf.float32,
                                                  point_cloud.vertices.shape)

            mesh_no_color = test_utils.get_random_mesh(2000, add_faces=True)
            mesh_no_color_extended = test_utils.get_random_mesh(2500,
                                                                add_faces=True)
            mesh_no_color_vertices = tf_placeholder(tf.float32, [1, None, 3])
            mesh_no_color_faces = tf_placeholder(tf.int32, [1, None, 3])

            mesh_color = test_utils.get_random_mesh(3000,
                                                    add_faces=True,
                                                    add_colors=True)
            mesh_color_vertices = tf_placeholder(tf.float32,
                                                 mesh_color.vertices.shape)
            mesh_color_faces = tf_placeholder(tf.int32, mesh_color.faces.shape)
            mesh_color_colors = tf_placeholder(tf.uint8,
                                               mesh_color.colors.shape)

            self.data = [
                point_cloud, mesh_no_color, mesh_no_color_extended, mesh_color
            ]

            # In case when name is present and display_name is not, we will reuse name
            # as display_name. Summaries below intended to test both cases.
            self.names = ["point_cloud", "mesh_no_color", "mesh_color"]
            summary.op(self.names[0],
                       point_cloud_vertices,
                       description="just point cloud")
            summary.op(self.names[1],
                       mesh_no_color_vertices,
                       faces=mesh_no_color_faces,
                       display_name="name_to_display_in_ui",
                       description="beautiful mesh in grayscale")
            summary.op(self.names[2],
                       mesh_color_vertices,
                       faces=mesh_color_faces,
                       colors=mesh_color_colors,
                       description="mesh with random colors")

            merged_summary_op = tf.compat.v1.summary.merge_all()
            self.runs = ["bar"]
            self.steps = 20
            bar_directory = os.path.join(self.log_dir, self.runs[0])
            with tensorboard_test_util.FileWriterCache.get(
                    bar_directory) as writer:
                writer.add_graph(sess.graph)
                for step in range(self.steps):
                    # Alternate between two random meshes with different number of
                    # vertices.
                    no_color = mesh_no_color if step % 2 == 0 else mesh_no_color_extended
                    with patch.object(time, 'time', return_value=step):
                        writer.add_summary(sess.run(merged_summary_op,
                                                    feed_dict={
                                                        point_cloud_vertices:
                                                        point_cloud.vertices,
                                                        mesh_no_color_vertices:
                                                        no_color.vertices,
                                                        mesh_no_color_faces:
                                                        no_color.faces,
                                                        mesh_color_vertices:
                                                        mesh_color.vertices,
                                                        mesh_color_faces:
                                                        mesh_color.faces,
                                                        mesh_color_colors:
                                                        mesh_color.colors,
                                                    }),
                                           global_step=step)

        # Start a server that will receive requests.
        self.multiplexer = event_multiplexer.EventMultiplexer({
            "bar":
            bar_directory,
        })
        self.context = base_plugin.TBContext(logdir=self.log_dir,
                                             multiplexer=self.multiplexer)
        self.plugin = mesh_plugin.MeshPlugin(self.context)
        # Wait until after plugin construction to reload the multiplexer because the
        # plugin caches data from the multiplexer upon construction and this affects
        # logic tested later down.
        # TODO(https://github.com/tensorflow/tensorboard/issues/2579): Eliminate the
        # caching of data at construction time and move this Reload() up to just
        # after the multiplexer is created.
        self.multiplexer.Reload()
        wsgi_app = application.TensorBoardWSGI([self.plugin])
        self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
        self.routes = self.plugin.get_plugin_apps()
  def setUp(self):
    # We use numpy.random to generate meshes. We seed to avoid non-determinism
    # in this test.
    np.random.seed(17)

    # Log dir to save temp events into.
    self.log_dir = self.get_temp_dir()

    # Create mesh summary.
    tf.compat.v1.reset_default_graph()
    sess = tf.compat.v1.Session()
    point_cloud = test_utils.get_random_mesh(1000)
    point_cloud_vertices = tf.compat.v1.placeholder(tf.float32,
                                                    point_cloud.vertices.shape)

    mesh_no_color = test_utils.get_random_mesh(2000, add_faces=True)
    mesh_no_color_vertices = tf.compat.v1.placeholder(
        tf.float32, mesh_no_color.vertices.shape)
    mesh_no_color_faces = tf.compat.v1.placeholder(tf.int32,
                                                   mesh_no_color.faces.shape)

    mesh_color = test_utils.get_random_mesh(
        3000, add_faces=True, add_colors=True)
    mesh_color_vertices = tf.compat.v1.placeholder(tf.float32,
                                                   mesh_color.vertices.shape)
    mesh_color_faces = tf.compat.v1.placeholder(tf.int32,
                                                mesh_color.faces.shape)
    mesh_color_colors = tf.compat.v1.placeholder(tf.uint8,
                                                 mesh_color.colors.shape)
    self.data = [point_cloud, mesh_no_color, mesh_color]

    # In case when name is present and display_name is not, we will reuse name
    # as display_name. Summaries below intended to test both cases.
    self.names = ["point_cloud", "mesh_no_color", "mesh_color"]
    summary.op(
        self.names[0],
        point_cloud_vertices,
        description="just point cloud")
    summary.op(
        self.names[1],
        mesh_no_color_vertices,
        faces=mesh_no_color_faces,
        display_name="name_to_display_in_ui",
        description="beautiful mesh in grayscale")
    summary.op(
        self.names[2],
        mesh_color_vertices,
        faces=mesh_color_faces,
        colors=mesh_color_colors,
        description="mesh with random colors")

    merged_summary_op = tf.compat.v1.summary.merge_all()
    self.runs = ["bar"]
    self.steps = 20
    bar_directory = os.path.join(self.log_dir, self.runs[0])
    with tensorboard_test_util.FileWriterCache.get(bar_directory) as writer:
      writer.add_graph(sess.graph)
      for step in range(self.steps):
        writer.add_summary(
            sess.run(
                merged_summary_op,
                feed_dict={
                    point_cloud_vertices: point_cloud.vertices,
                    mesh_no_color_vertices: mesh_no_color.vertices,
                    mesh_no_color_faces: mesh_no_color.faces,
                    mesh_color_vertices: mesh_color.vertices,
                    mesh_color_faces: mesh_color.faces,
                    mesh_color_colors: mesh_color.colors,
                }),
            global_step=step)

    # Start a server that will receive requests.
    self.multiplexer = event_multiplexer.EventMultiplexer({
        "bar": bar_directory,
    })
    self.context = base_plugin.TBContext(
        logdir=self.log_dir, multiplexer=self.multiplexer)
    self.plugin = mesh_plugin.MeshPlugin(self.context)
    wsgi_app = application.TensorBoardWSGIApp(
        self.log_dir, [self.plugin],
        self.multiplexer,
        reload_interval=0,
        path_prefix="")
    self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
    self.multiplexer.Reload()
    self.routes = self.plugin.get_plugin_apps()