Home | History | Annotate | Download | only in projector
      1 # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 # ==============================================================================
     15 """API tests for the projector plugin in TensorBoard."""
     16 
     17 from __future__ import absolute_import
     18 from __future__ import division
     19 from __future__ import print_function
     20 
     21 import os
     22 import shutil
     23 
     24 from google.protobuf import text_format
     25 
     26 from tensorflow.contrib.tensorboard.plugins import projector
     27 from tensorflow.contrib.tensorboard.plugins.projector import projector_config_pb2
     28 from tensorflow.python.platform import gfile
     29 from tensorflow.python.platform import test
     30 from tensorflow.python.summary.writer import writer as writer_lib
     31 
     32 
     33 class ProjectorApiTest(test.TestCase):
     34 
     35   def testVisualizeEmbeddings(self):
     36     # Create a dummy configuration.
     37     config = projector_config_pb2.ProjectorConfig()
     38     config.model_checkpoint_path = 'test'
     39     emb1 = config.embeddings.add()
     40     emb1.tensor_name = 'tensor1'
     41     emb1.metadata_path = 'metadata1'
     42 
     43     # Call the API method to save the configuration to a temporary dir.
     44     temp_dir = self.get_temp_dir()
     45     self.addCleanup(shutil.rmtree, temp_dir)
     46     writer = writer_lib.FileWriter(temp_dir)
     47     projector.visualize_embeddings(writer, config)
     48 
     49     # Read the configurations from disk and make sure it matches the original.
     50     with gfile.GFile(os.path.join(temp_dir, 'projector_config.pbtxt')) as f:
     51       config2 = projector_config_pb2.ProjectorConfig()
     52       text_format.Parse(f.read(), config2)
     53       self.assertEqual(config, config2)
     54 
     55 
     56 if __name__ == '__main__':
     57   test.main()
     58