def testExceptions(self): logdir = '/fake/foo' multiplexer = event_multiplexer.EventMultiplexer() # Fails if there is an unnamed plugin with self.assertRaises(ValueError): # This plugin lacks a name. plugins = [ FakePlugin(plugin_name=None, is_active_value=True, routes_mapping={}) ] application.TensorBoardWSGIApp(logdir, plugins, multiplexer, 0) # Fails if there are two plugins with same name with self.assertRaises(ValueError): plugins = [ FakePlugin(plugin_name='foo', is_active_value=True, routes_mapping={}), FakePlugin(plugin_name='foo', is_active_value=True, routes_mapping={}), ] application.TensorBoardWSGIApp(logdir, plugins, multiplexer, 0)
def _test(self, name, should_be_okay): temp_dir = tempfile.mkdtemp(prefix=self.get_temp_dir()) self.addCleanup(shutil.rmtree, temp_dir) multiplexer = event_multiplexer.EventMultiplexer( size_guidance=application.DEFAULT_SIZE_GUIDANCE, purge_orphaned_data=True) plugins = [ FakePlugin(plugin_name='foo', is_active_value=True, routes_mapping={}), FakePlugin(plugin_name=name, is_active_value=True, routes_mapping={}), FakePlugin(plugin_name='bar', is_active_value=False, routes_mapping={}) ] if should_be_okay: application.TensorBoardWSGIApp(temp_dir, plugins, multiplexer, reload_interval=0) else: with self.assertRaisesRegexp(ValueError, r'invalid name'): application.TensorBoardWSGIApp(temp_dir, plugins, multiplexer, reload_interval=0)
def create_app(self): """Creates a WSGI-compliant app than can handle TensorBoard requests. Returns: (function) A complete WSGI application that handles TensorBoard requests. """ logdir = os.path.expanduser(FLAGS.logdir) if not logdir: msg = ('A logdir must be specified. Run `tensorboard --help` for ' 'details and examples.') logging.error(msg) print(msg) return -1 multiplexer = event_multiplexer.EventMultiplexer( size_guidance=application.DEFAULT_SIZE_GUIDANCE, purge_orphaned_data=FLAGS.purge_orphaned_data) plugins = { debugger_plugin.PLUGIN_PREFIX_ROUTE: debugger_plugin.DebuggerPlugin(multiplexer), projector_plugin.PLUGIN_PREFIX_ROUTE: projector_plugin.ProjectorPlugin(), } return application.TensorBoardWSGIApp( logdir, plugins, multiplexer, reload_interval=FLAGS.reload_interval)
def setUp(self): self.temp_dir = self._GenerateTestData() multiplexer = event_multiplexer.EventMultiplexer( size_guidance=application.DEFAULT_SIZE_GUIDANCE, purge_orphaned_data=True) plugins = [ FakePlugin(plugin_name='foo', is_active_value=True), FakePlugin(plugin_name='bar', is_active_value=False) ] app = application.TensorBoardWSGIApp(self.temp_dir, plugins, multiplexer, reload_interval=0) try: self._server = serving.BaseWSGIServer('localhost', 0, app) # 0 to pick an unused port. except IOError: # BaseWSGIServer has a preference for IPv4. If that didn't work, try again # with an explicit IPv6 address. self._server = serving.BaseWSGIServer('::1', 0, app) self._server_thread = threading.Thread( target=self._server.serve_forever) self._server_thread.daemon = True self._server_thread.start() self._connection = http_client.HTTPConnection( 'localhost', self._server.server_address[1])
def setUp(self): # Populate the log directory with debugger event for run '.'. self.log_dir = self.get_temp_dir() file_prefix = compat.as_bytes( os.path.join(self.log_dir, 'events.debugger')) writer = pywrap_tensorflow.EventsWriter(file_prefix) writer.WriteEvent( self._CreateEventWithDebugNumericSummary(op_name='layers/Matmul', output_slot=0, wall_time=42, step=2, list_of_values=[1, 2, 3])) writer.WriteEvent( self._CreateEventWithDebugNumericSummary(op_name='layers/Matmul', output_slot=1, wall_time=43, step=7, list_of_values=[4, 5, 6])) writer.WriteEvent( self._CreateEventWithDebugNumericSummary(op_name='logits/Add', output_slot=0, wall_time=1337, step=7, list_of_values=[7, 8, 9])) writer.WriteEvent( self._CreateEventWithDebugNumericSummary( op_name='logits/Add', output_slot=0, wall_time=1338, step=8, list_of_values=[10, 11, 12])) writer.Close() # Populate the log directory with debugger event for run 'run_foo'. run_foo_directory = os.path.join(self.log_dir, 'run_foo') os.mkdir(run_foo_directory) file_prefix = compat.as_bytes( os.path.join(run_foo_directory, 'events.debugger')) writer = pywrap_tensorflow.EventsWriter(file_prefix) writer.WriteEvent( self._CreateEventWithDebugNumericSummary( op_name='layers/Variable', output_slot=0, wall_time=4242, step=42, list_of_values=[13, 14, 15])) writer.Close() # Start a server that will receive requests and respond with health pills. self.multiplexer = event_multiplexer.EventMultiplexer({ '.': self.log_dir, 'run_foo': run_foo_directory, }) self.plugin = debugger_plugin.DebuggerPlugin() wsgi_app = application.TensorBoardWSGIApp(self.log_dir, [self.plugin], self.multiplexer, reload_interval=0) self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
def _SetupWSGIApp(self): multiplexer = event_multiplexer.EventMultiplexer( size_guidance=application.DEFAULT_SIZE_GUIDANCE, purge_orphaned_data=True) self.plugin = projector_plugin.ProjectorPlugin() wsgi_app = application.TensorBoardWSGIApp( self.log_dir, [self.plugin], multiplexer, reload_interval=0) self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
def setUp(self): self.log_dir = tempfile.mkdtemp() # We use numpy.random to generate images. We seed to avoid non-determinism # in this test. numpy.random.seed(42) # Create image summaries for run foo. ops.reset_default_graph() sess = session.Session() placeholder = array_ops.placeholder(dtypes.uint8) summary.image(name="baz", tensor=placeholder) merged_summary_op = summary.merge_all() foo_directory = os.path.join(self.log_dir, "foo") writer = summary.FileWriter(foo_directory) writer.add_graph(sess.graph) for step in xrange(2): writer.add_summary(sess.run(merged_summary_op, feed_dict={ placeholder: (numpy.random.rand(1, 16, 42, 3) * 255).astype(numpy.uint8) }), global_step=step) writer.close() # Create image summaries for run bar. ops.reset_default_graph() sess = session.Session() placeholder = array_ops.placeholder(dtypes.uint8) summary.image(name="quux", tensor=placeholder) merged_summary_op = summary.merge_all() bar_directory = os.path.join(self.log_dir, "bar") writer = summary.FileWriter(bar_directory) writer.add_graph(sess.graph) for step in xrange(2): writer.add_summary(sess.run(merged_summary_op, feed_dict={ placeholder: (numpy.random.rand(1, 6, 8, 3) * 255).astype(numpy.uint8) }), global_step=step) writer.close() # Start a server with the plugin. multiplexer = event_multiplexer.EventMultiplexer({ "foo": foo_directory, "bar": bar_directory, }) plugin = images_plugin.ImagesPlugin() wsgi_app = application.TensorBoardWSGIApp(self.log_dir, [plugin], multiplexer, reload_interval=0) self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse) self.routes = plugin.get_plugin_apps(multiplexer, self.log_dir)
def setUp(self): self.log_dir = tempfile.mkdtemp() # We use numpy.random to generate audio. We seed to avoid non-determinism # in this test. numpy.random.seed(42) # Create audio summaries for run foo. tf.reset_default_graph() sess = tf.Session() placeholder = tf.placeholder(tf.float32) tf.summary.audio(name="baz", tensor=placeholder, sample_rate=44100) merged_summary_op = tf.summary.merge_all() foo_directory = os.path.join(self.log_dir, "foo") writer = tf.summary.FileWriter(foo_directory) writer.add_graph(sess.graph) for step in xrange(2): # The floats (sample data) range from -1 to 1. writer.add_summary(sess.run( merged_summary_op, feed_dict={placeholder: numpy.random.rand(42, 22050) * 2 - 1}), global_step=step) writer.close() # Create audio summaries for run bar. tf.reset_default_graph() sess = tf.Session() placeholder = tf.placeholder(tf.float32) tf.summary.audio(name="quux", tensor=placeholder, sample_rate=44100) merged_summary_op = tf.summary.merge_all() bar_directory = os.path.join(self.log_dir, "bar") writer = tf.summary.FileWriter(bar_directory) writer.add_graph(sess.graph) for step in xrange(2): # The floats (sample data) range from -1 to 1. writer.add_summary(sess.run( merged_summary_op, feed_dict={placeholder: numpy.random.rand(42, 11025) * 2 - 1}), global_step=step) writer.close() # Start a server with the plugin. multiplexer = event_multiplexer.EventMultiplexer({ "foo": foo_directory, "bar": bar_directory, }) plugin = audio_plugin.AudioPlugin() wsgi_app = application.TensorBoardWSGIApp(self.log_dir, [plugin], multiplexer, reload_interval=0) self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse) self.routes = plugin.get_plugin_apps(multiplexer, self.log_dir)
def setUp(self): self.temp_dir = self._GenerateTestData() plugins = {'projector': projector_plugin.ProjectorPlugin()} app = application.TensorBoardWSGIApp(self.temp_dir, plugins, reload_interval=0) self._server = serving.BaseWSGIServer('localhost', 0, app) # 0 to pick an unused port. self._server_thread = threading.Thread( target=self._server.serve_forever) self._server_thread.daemon = True self._server_thread.start() self._connection = http_client.HTTPConnection( 'localhost', self._server.server_address[1])
def testExceptions(self): class UnnamedPlugin(base_plugin.TBPlugin): def get_plugin_apps(self): pass class MockPlugin(UnnamedPlugin): plugin_name = 'mock' class OtherMockPlugin(UnnamedPlugin): plugin_name = 'mock' logdir = '/fake/foo' multiplexer = event_multiplexer.EventMultiplexer() # Fails if there is an unnamed plugin with self.assertRaises(ValueError): plugins = [UnnamedPlugin()] application.TensorBoardWSGIApp(logdir, plugins, multiplexer, 0) # Fails if there are two plugins with same name with self.assertRaises(ValueError): plugins = [MockPlugin(), OtherMockPlugin()] application.TensorBoardWSGIApp(logdir, plugins, multiplexer, 0)
def setUp(self): self.temp_dir = self._GenerateTestData() multiplexer = event_multiplexer.EventMultiplexer( size_guidance=application.DEFAULT_SIZE_GUIDANCE, purge_orphaned_data=True) plugins = {'projector': projector_plugin.ProjectorPlugin()} app = application.TensorBoardWSGIApp( self.temp_dir, plugins, multiplexer, reload_interval=0) self._server = serving.BaseWSGIServer('localhost', 0, app) # 0 to pick an unused port. self._server_thread = threading.Thread(target=self._server.serve_forever) self._server_thread.daemon = True self._server_thread.start() self._connection = http_client.HTTPConnection( 'localhost', self._server.server_address[1])
def main(unused_argv=None): debug = FLAGS.insecure_debug_mode logdir = os.path.expanduser(FLAGS.logdir) if debug: logging.set_verbosity(logging.DEBUG) logging.warning('TensorBoard is in debug mode. This is NOT SECURE.') if FLAGS.inspect: logging.info( 'Not bringing up TensorBoard, but inspecting event files.') event_file = os.path.expanduser(FLAGS.event_file) efi.inspect(logdir, event_file, FLAGS.tag) return 0 if not logdir: msg = ('A logdir must be specified. Run `tensorboard --help` for ' 'details and examples.') logging.error(msg) print(msg) return -1 logging.info('Starting TensorBoard in directory %s', os.getcwd()) plugins = {'projector': projector_plugin.ProjectorPlugin()} tb_app = application.TensorBoardWSGIApp( logdir, plugins, purge_orphaned_data=FLAGS.purge_orphaned_data, reload_interval=FLAGS.reload_interval) try: tag = resource_loader.load_resource('tensorboard/TAG').strip() logging.info('TensorBoard is tag: %s', tag) except IOError: logging.info('Unable to read TensorBoard tag') tag = '' status_bar.SetupStatusBarInsideGoogle('TensorBoard %s' % tag, FLAGS.port) print('Starting TensorBoard %s on port %d' % (tag, FLAGS.port)) if FLAGS.host == "0.0.0.0": try: host = socket.gethostbyname(socket.gethostname()) print('(You can navigate to http://%s:%d)' % (host, FLAGS.port)) except socket.gaierror: pass else: print('(You can navigate to http://%s:%d)' % (FLAGS.host, FLAGS.port)) try: serving.run_simple(FLAGS.host, FLAGS.port, tb_app, threaded=True, use_reloader=debug, use_evalex=debug, use_debugger=debug) except socket.error: if FLAGS.port == 0: msg = 'Unable to find any open ports.' logging.error(msg) print(msg) return -2 else: msg = 'Tried to connect to port %d, but address is in use.' % FLAGS.port logging.error(msg) print(msg) return -3