コード例 #1
0
ファイル: visualize_test.py プロジェクト: sulw/tensorflow
    def testVisualize(self):
        model = test_utils.build_mock_flatbuffer_model()
        tmp_dir = self.get_temp_dir()
        model_filename = os.path.join(tmp_dir, 'model.tflite')
        with open(model_filename, 'wb') as model_file:
            model_file.write(model)
        html_filename = os.path.join(tmp_dir, 'visualization.html')

        visualize.CreateHtmlFile(model_filename, html_filename)

        with open(html_filename, 'r') as html_file:
            html_text = html_file.read()

        # It's hard to test debug output without doing a full HTML parse,
        # but at least sanity check that expected identifiers are present.
        self.assertRegex(
            html_text,
            re.compile(r'%s' % model_filename, re.MULTILINE | re.DOTALL))
        self.assertRegex(html_text,
                         re.compile(r'input_tensor', re.MULTILINE | re.DOTALL))
        self.assertRegex(
            html_text, re.compile(r'constant_tensor',
                                  re.MULTILINE | re.DOTALL))
        self.assertRegex(html_text, re.compile(r'ADD',
                                               re.MULTILINE | re.DOTALL))
コード例 #2
0
 def testFlatbufferToDict(self):
   model = test_utils.build_mock_flatbuffer_model()
   model_dict = visualize.CreateDictFromFlatbuffer(model)
   self.assertEqual(test_utils.TFLITE_SCHEMA_VERSION, model_dict['version'])
   self.assertEqual(1, len(model_dict['subgraphs']))
   self.assertEqual(1, len(model_dict['operator_codes']))
   self.assertEqual(3, len(model_dict['buffers']))
   self.assertEqual(3, len(model_dict['subgraphs'][0]['tensors']))
   self.assertEqual(0, model_dict['subgraphs'][0]['tensors'][0]['buffer'])