def new_instance(self, logdir, reload_interval): if not os.path.isabs(logdir) and notebook_dir: logdir = os.path.join(notebook_dir, logdir) if logdir not in self._logdir_dict: purge_orphaned_data = True plugins = get_plugins() reload_interval = reload_interval or 30 application.standard_tensorboard_wsgi( logdir=logdir, reload_interval=reload_interval, purge_orphaned_data=purge_orphaned_data, plugins=plugins) return self._logdir_dict[logdir]
def create_tb_app(plugins, assets_zip_provider=None): """Read the flags, and create a TensorBoard WSGI application. Args: plugins: A list of constructor functions for TBPlugin subclasses. assets_zip_provider: Delegates to TBContext or uses default if None. Raises: ValueError: if a logdir is not specified. Returns: A new TensorBoard WSGI application. :type plugins: list[:class:`base_plugin.TBPlugin`] :type assets_zip_provider: () -> file :rtype: types.FunctionType """ if not FLAGS.db and not FLAGS.logdir: raise ValueError( 'A logdir must be specified when db is not specified. ' 'Run `tensorboard --help` for details and examples.') return application.standard_tensorboard_wsgi( assets_zip_provider=assets_zip_provider, db_uri=FLAGS.db, logdir=os.path.expanduser(FLAGS.logdir), purge_orphaned_data=FLAGS.purge_orphaned_data, reload_interval=FLAGS.reload_interval, plugins=plugins, path_prefix=FLAGS.path_prefix, window_title=FLAGS.window_title)
def create_app(logdir, reload_interval, path_prefix=""): with warnings.catch_warnings(): warnings.simplefilter("ignore", Warning) from tensorboard.backend import application from tensorboard import program try: tb_f = program.TensorBoard except AttributeError: raise TensorboardError("tensorboard>=1.10 required") else: with warnings.catch_warnings(): warnings.simplefilter("ignore", Warning) tb = tb_f() argv = ( "", "--logdir", logdir, "--reload_interval", str(reload_interval), "--path_prefix", path_prefix, ) tb.configure(argv) return application.standard_tensorboard_wsgi(tb.flags, tb.plugin_loaders, tb.assets_zip_provider)
def setUp(self): self.context = None dummy_assets_zip_provider = lambda: None # The application should have added routes for both plugins. self.app = application.standard_tensorboard_wsgi( FakeFlags(logdir=self.get_temp_dir()), [ base_plugin.BasicLoader( functools.partial( FakePlugin, plugin_name='foo', is_active_value=True, routes_mapping={'/foo_route': self._foo_handler}, construction_callback=self._construction_callback)), base_plugin.BasicLoader( functools.partial( FakePlugin, plugin_name='bar', is_active_value=True, routes_mapping={ '/bar_route': self._bar_handler, '/wildcard/*': self._wildcard_handler, '/wildcard/special/*': self._wildcard_special_handler, '/wildcard/special/exact': self._foo_handler, }, construction_callback=self._construction_callback)), ], dummy_assets_zip_provider) self.server = werkzeug_test.Client(self.app, wrappers.BaseResponse)
def testPluginsAdded(self): def foo_handler(): pass def bar_handler(): pass plugins = [ functools.partial(FakePlugin, plugin_name='foo', is_active_value=True, routes_mapping={'/foo_route': foo_handler}), functools.partial(FakePlugin, plugin_name='bar', is_active_value=True, routes_mapping={'/bar_route': bar_handler}), ] # The application should have added routes for both plugins. app = application.standard_tensorboard_wsgi('', True, 60, plugins) # The routes are prefixed with /data/plugin/[plugin name]. self.assertDictContainsSubset( { '/data/plugin/foo/foo_route': foo_handler, '/data/plugin/bar/bar_route': bar_handler, }, app.data_applications)
def __get_tb_app(self, tensorboard_logs): return application.standard_tensorboard_wsgi( logdir=tensorboard_logs, assets_zip_provider=tb_default.get_assets_zip_provider(), purge_orphaned_data=True, reload_interval=5, plugins=tb_default.get_plugins())
def create_tb_app(logdir, reload_interval, purge_orphaned_data): argv = [ "", "--logdir", logdir, "--reload_interval", str(reload_interval), "--purge_orphaned_data", str(purge_orphaned_data), ] tensorboard = program.TensorBoard() tensorboard.configure(argv) if version.parse(TB_VERSION) < version.parse("2.4"): return application.standard_tensorboard_wsgi( tensorboard.flags, tensorboard.plugin_loaders, tensorboard.assets_zip_provider, ) else: (data_provider, deprecated_multiplexer) = tensorboard._make_data_provider() app = application.TensorBoardWSGIApp( tensorboard.flags, tensorboard.plugin_loaders, data_provider, tensorboard.assets_zip_provider, deprecated_multiplexer, )
def setUp(self): self.context = None dummy_assets_zip_provider = lambda: None # The application should have added routes for both plugins. self.app = application.standard_tensorboard_wsgi( FakeFlags(logdir=self.get_temp_dir()), [ FakePluginLoader( plugin_name="foo", is_active_value=True, routes_mapping={"/foo_route": self._foo_handler}, construction_callback=self._construction_callback, ), FakePluginLoader( plugin_name="bar", is_active_value=True, routes_mapping={ "/bar_route": self._bar_handler, "/wildcard/*": self._wildcard_handler, "/wildcard/special/*": self._wildcard_special_handler, "/wildcard/special/exact": self._foo_handler, }, construction_callback=self._construction_callback, ), FakePluginLoader( plugin_name="whoami", routes_mapping={"/eid": self._eid_handler,}, ), ], dummy_assets_zip_provider, ) self.server = werkzeug_test.Client(self.app, wrappers.BaseResponse)
def testPluginsAdded(self): def foo_handler(): pass def bar_handler(): pass plugins = [ functools.partial( FakePlugin, plugin_name='foo', is_active_value=True, routes_mapping={'/foo_route': foo_handler}), functools.partial( FakePlugin, plugin_name='bar', is_active_value=True, routes_mapping={'/bar_route': bar_handler}), ] # The application should have added routes for both plugins. app = application.standard_tensorboard_wsgi('', True, 60, plugins) # The routes are prefixed with /data/plugin/[plugin name]. self.assertDictContainsSubset({ '/data/plugin/foo/foo_route': foo_handler, '/data/plugin/bar/bar_route': bar_handler, }, app.data_applications)
def create_serve_fun(log_dir: 'str', host='0.0.0.0', port=8000): """ create tensorboard serve fun :param log_dir: log dir (as tf.summary.FileWriter) :param host: host ip :param port: host port :return: serve fun """ def _handle_error(_, client_address): exc_info = sys.exc_info() e = exc_info[1] if isinstance(e, IOError) and e.errno == errno.EPIPE: tf.logging.warn('EPIPE caused by %s:%d in HTTP serving' % client_address) else: tf.logging.error('HTTP serving error', exc_info=exc_info) tb = application.standard_tensorboard_wsgi( logdir=log_dir, purge_orphaned_data=True, reload_interval=5, plugins=[ core_plugin.CorePlugin, scalars_plugin.ScalarsPlugin, graphs_plugin.GraphsPlugin, ]) server = serving.make_server(host=host, port=port, app=tb, threaded=True) server.daemon_threads = True server.handle_error = _handle_error return server.serve_forever
def create_app( logdir, reload_interval, path_prefix="", tensorboard_options=None, disabled_plugins=None, ): with warnings.catch_warnings(): warnings.simplefilter("ignore", Warning) from tensorboard import program from tensorboard.backend import application try: TensorBoard = program.TensorBoard except AttributeError: raise TensorboardError("tensorboard>=1.10 required") else: with warnings.catch_warnings(): warnings.simplefilter("ignore", Warning) plugins = _plugins(disabled_plugins) tb = TensorBoard(plugins) argv = _base_tb_args(logdir, reload_interval, path_prefix) + _extra_tb_args(tensorboard_options) log.debug("TensorBoard args: %r", argv) tb.configure(argv) return application.standard_tensorboard_wsgi(tb.flags, tb.plugin_loaders, tb.assets_zip_provider)
def _get_server(self): app = application.standard_tensorboard_wsgi(self.flags, self.plugin_loaders, self.assets_zip_provider) if self._wsgi_middleware is not None: app = self._wsgi_middleware(app) return make_simple_server(app, self.flags.host, self.flags.port, self.flags.path_prefix)
def create_tb_app(logdir, reload_interval, purge_orphaned_data): return manager.add_instance( logdir, application.standard_tensorboard_wsgi( logdir=logdir, reload_interval=reload_interval, purge_orphaned_data=purge_orphaned_data, plugins=default.get_plugins()))
def create_app(plugins, logdir, reload_interval): return application.standard_tensorboard_wsgi( assets_zip_provider=None, db_uri="", logdir=os.path.expanduser(logdir), purge_orphaned_data=False, reload_interval=reload_interval, plugins=plugins)
def setUp(self): self._write_dummy_files() app = application.standard_tensorboard_wsgi( '/tmp/beholder-demo', True, 5, get_plugins() ) self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
def create_tb_app(log): return backendWSGI.standard_tensorboard_wsgi( assets_zip_provider=default.get_assets_zip_provider(), db_uri='', logdir=os.path.expanduser(log), purge_orphaned_data=True, reload_interval=5, plugins=default.get_plugins(), path_prefix='', window_title='', max_reload_threads=1, flags='')
def create_tb_app(logdir, reload_interval, purge_orphaned_data): argv = [ "", "--logdir", logdir, "--reload_interval", str(reload_interval), "--purge_orphaned_data", str(purge_orphaned_data), ] tensorboard = program.TensorBoard() tensorboard.configure(argv) return application.standard_tensorboard_wsgi( tensorboard.flags, tensorboard.plugin_loaders, tensorboard.assets_zip_provider)
def create_app(logdir, reload_interval, path_prefix=""): try: tb_f = program.TensorBoard except AttributeError: raise TensorboardError("tensorboard>=1.10 required") else: tb = tb_f() argv = ( "", "--logdir", logdir, "--reload_interval", str(reload_interval), "--path_prefix", path_prefix, ) tb.configure(argv) return application.standard_tensorboard_wsgi( tb.flags, tb.plugin_loaders, tb.assets_zip_provider)
def tb_wsgi_app(environ, start_response, batch_id): from tensorboard import default from tensorboard import program from tensorboard.backend import application from django import conf # fix. ungzip # request.headers unset 'Accept-Encoding' # ? 'HTTP_ACCEPT_ENCODING' # then set again #program.main(default.get_plugins(), default.get_assets_zip_provider()) plugins = default.get_plugins() #assets_zip_provider = program.get_default_assets_zip_provider() assets_zip_provider = None #server_class = #tb_wsgi = program.create_tb_app(plugins, assets_zip_provider) tensorboard = program.TensorBoard(plugins, assets_zip_provider) argv = [ __file__, '--logdir={}/tf-logs/{}'.format(conf.settings.BASE_DIR, batch_id), '--path_prefix=/view/{}'.format(batch_id) ] tensorboard.configure(argv=argv) app = application.standard_tensorboard_wsgi( tensorboard.flags, tensorboard.plugin_loaders, tensorboard.assets_zip_provider) #tensorboard.flags.logdir = "tf-logs/{}".format(batch_id) #tensorboard.flags.path_prefix = "/view/{}".format(batch_id) #tb_wsgi.data_applications[clean_path](environ, start_response) # wrapped @wrappers.Request.application #for k in tb_wsgi.data_applications.keys(): # print(k) #for a,b in environ.items(): # print(a, "\t", b) # set again request.headers: 'Accept-Encoding' return app(environ, start_response)
def setUp(self): self.context = None # The application should have added routes for both plugins. self.app = application.standard_tensorboard_wsgi( FakeFlags(logdir=self.get_temp_dir()), [ base_plugin.BasicLoader( functools.partial( FakePlugin, plugin_name='foo', is_active_value=True, routes_mapping={'/foo_route': self._foo_handler}, construction_callback=self._construction_callback)), base_plugin.BasicLoader( functools.partial( FakePlugin, plugin_name='bar', is_active_value=True, routes_mapping={'/bar_route': self._bar_handler}, construction_callback=self._construction_callback)), ], default.get_assets_zip_provider())
def setUp(self): self.context = None plugins = [ functools.partial( FakePlugin, plugin_name='foo', is_active_value=True, routes_mapping={'/foo_route': self._foo_handler}, construction_callback=self._construction_callback), functools.partial( FakePlugin, plugin_name='bar', is_active_value=True, routes_mapping={'/bar_route': self._bar_handler}, construction_callback=self._construction_callback), ] # The application should have added routes for both plugins. self.logdir = self.get_temp_dir() self.app = application.standard_tensorboard_wsgi( self.logdir, True, 60, plugins)
def setUp(self): self.context = None plugins = [ functools.partial( FakePlugin, plugin_name='foo', is_active_value=True, routes_mapping={'/foo_route': self._foo_handler}, construction_callback=self._construction_callback), functools.partial( FakePlugin, plugin_name='bar', is_active_value=True, routes_mapping={'/bar_route': self._bar_handler}, construction_callback=self._construction_callback), ] # The application should have added routes for both plugins. self.logdir = self.get_temp_dir() self.app = application.standard_tensorboard_wsgi( self.logdir, True, 60, plugins)
def create_tb_app(plugins): """Read the flags, and create a TensorBoard WSGI application. Args: plugins: A list of constructor functions for TBPlugin subclasses. Raises: ValueError: if a logdir is not specified. Returns: A new TensorBoard WSGI application. """ if not FLAGS.logdir: raise ValueError('A logdir must be specified. Run `tensorboard --help` for ' 'details and examples.') logdir = os.path.expanduser(FLAGS.logdir) return application.standard_tensorboard_wsgi( logdir=logdir, purge_orphaned_data=FLAGS.purge_orphaned_data, reload_interval=FLAGS.reload_interval, plugins=plugins)
def create_tb_app(plugins, assets_zip_provider=None): """Read the flags, and create a TensorBoard WSGI application. Args: plugins: A list of constructor functions for TBPlugin subclasses. assets_zip_provider: Delegates to TBContext or uses default if None. Raises: ValueError: if a logdir is not specified. Returns: A new TensorBoard WSGI application. """ if not FLAGS.db and not FLAGS.logdir: raise ValueError('A logdir must be specified when db is not specified. ' 'Run `tensorboard --help` for details and examples.') return application.standard_tensorboard_wsgi( assets_zip_provider=assets_zip_provider, db_uri=FLAGS.db, logdir=os.path.expanduser(FLAGS.logdir), purge_orphaned_data=FLAGS.purge_orphaned_data, reload_interval=FLAGS.reload_interval, plugins=plugins, path_prefix=FLAGS.path_prefix)
def create_tb_app(logdir, reload_interval, purge_orphaned_data): return application.standard_tensorboard_wsgi( logdir=logdir, reload_interval=reload_interval, purge_orphaned_data=purge_orphaned_data, plugins=_plugins)
def testTagFound(self): tag = application.get_tensorboard_tag() self.assertTrue(tag) app = application.standard_tensorboard_wsgi('', True, 60, []) self.assertEqual(app.tag, tag)
def testIndexFound(self): app = application.standard_tensorboard_wsgi('', True, 60, []) index = app.get_index_html() self.assertTrue(index)
def start(self): self.app = application.standard_tensorboard_wsgi( self.tmpdir.name, True, 10, get_plugins()) return True
def _make_server(self): """Constructs the TensorBoard WSGI app and instantiates the server.""" app = application.standard_tensorboard_wsgi(self.flags, self.plugin_loaders, self.assets_zip_provider) return self.server_class(app, self.flags)
def _make_server(self): """Constructs the TensorBoard WSGI app and instantiates the server.""" app = application.standard_tensorboard_wsgi(self.flags, self.plugin_loaders, self.assets_zip_provider) return self.server_class(app, self.flags)