def run(self):
        if LooseVersion(tf.__version__) < LooseVersion("1.12"):  # v1.10
            # Remove http messages
            log = logging.getLogger('werkzeug')
            log.setLevel(logging.ERROR)
            # Start tensorboard server
            tb = program.TensorBoard(default.PLUGIN_LOADERS,
                                     default.get_assets_zip_provider())
            tb.configure(argv=['--logdir', self.dir_path])
            url = tb.launch()
            sys.stdout.write('TensorBoard at %s \n' % url)

        elif LooseVersion(
                tf.__version__) >= LooseVersion("1.12") and LooseVersion(
                    tf.__version__) < LooseVersion("2.0"):  # v1.12 - v1.14
            # Remove http messages
            log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
            # Start tensorboard server
            tb = program.TensorBoard(
                default.get_plugins())  #, default.get_assets_zip_provider())
            tb.configure(argv=[None, '--logdir', self.dir_path])
            url = tb.launch()
            sys.stdout.write('TensorBoard at %s \n' % url)
        else:  # v2.X
            # Remove http messages
            log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
            # Start tensorboard server
            tb = program.TensorBoard(
                default.get_plugins())  # , default.get_assets_zip_provider())
            tb.configure(argv=[None, '--logdir', self.dir_path])
            url = tb.launch()
            sys.stdout.write('TensorBoard at %s \n' % url)
Example #2
0
    def __init__(self,
                 plugins=None,
                 assets_zip_provider=None,
                 server_class=None):
        """Creates new instance.

    Args:
      plugin: A list of TensorBoard plugins to load, as TBPlugin classes or
        TBLoader instances or classes. If not specified, defaults to first-party
        plugins.
      assets_zip_provider: Delegates to TBContext or uses default if None.
      server_class: An optional factory for a `TensorBoardServer` to use
        for serving the TensorBoard WSGI app. If provided, its callable
        signature should match that of `TensorBoardServer.__init__`.
    """
        if plugins is None:
            from tensorboard import default
            plugins = default.get_plugins()
        if assets_zip_provider is None:
            assets_zip_provider = get_default_assets_zip_provider()
        if server_class is None:
            server_class = create_port_scanning_werkzeug_server
        self.plugin_loaders = [
            application.make_plugin_loader(p) for p in plugins
        ]
        self.assets_zip_provider = assets_zip_provider
        self.server_class = server_class
        self.flags = None
Example #3
0
def start_tf_board(client: skein.ApplicationClient,
                   experiment: Experiment = None):
    thread = None
    if experiment:
        model_dir = experiment.estimator.config.model_dir
    else:
        model_dir = os.environ.get('TF_BOARD_MODEL_DIR', None)
    task = cluster.get_task()
    os.environ['GCS_READ_CACHE_DISABLED'] = '1'
    os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp'
    os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION'] = '2'
    try:
        program.setup_environment()
        tensorboard = program.TensorBoard(default.get_plugins(),
                                          default.get_assets_zip_provider())
        with _internal.reserve_sock_addr() as (h, p):
            tensorboard_url = f"http://{h}:{p}"
            argv = ['tensorboard', f"--logdir={model_dir}",
                    f"--port={p}"]
            # Append more arguments if needed.
            if 'TF_BOARD_EXTRA_ARGS' in os.environ:
                argv += os.environ['TF_BOARD_EXTRA_ARGS'].split(' ')
            tensorboard.configure(argv)
        tensorboard.launch()
        event.url_event(client, task, f"Tensorboard is listening at {tensorboard_url}")
        thread = [t for t in threading.enumerate() if t.name == 'TensorBoard'][0]
    except Exception as e:
        event.stop_event(client, task, e)

    return thread
Example #4
0
def run_main():
    """Initializes flags and calls main()."""
    program.setup_environment()

    if getattr(tf, '__version__', 'stub') == 'stub':
        # Unless the user has explicitly requested running without TensorFlow by setting the
        # TENSORBOARD_NO_TF environment variable, we check for TensorFlow here so that if it's
        # missing we generate a clear and immediate error rather than partial functionality.
        # TODO(#2027): Remove environment check once we have placeholder UI
        if os.getenv('TENSORBOARD_NO_TF') is None:
            import tensorflow  # pylint: disable=unused-import
        logger.warn(
            "TensorFlow installation not found - running with reduced feature set."
        )

    tensorboard = program.TensorBoard(
        default.get_plugins(), program.get_default_assets_zip_provider())
    try:
        from absl import app
        # Import this to check that app.run() will accept the flags_parser argument.
        from absl.flags import argparse_flags
        app.run(tensorboard.main, flags_parser=tensorboard.configure)
        raise AssertionError("absl.app.run() shouldn't return")
    except ImportError:
        pass
    except base_plugin.FlagsError as e:
        print("Error: %s" % e, file=sys.stderr)
        sys.exit(1)

    tensorboard.configure(sys.argv)
    sys.exit(tensorboard.main())
Example #5
0
def main(unused_argv=None):
    """Standard TensorBoard program CLI.

  See `tensorboard.program.main` for further documentation.
  """
    return program.main(default.get_plugins(),
                        default.get_assets_zip_provider())
def run_main(asset_path):
    loader = runsenabler_loader.RunsEnablerLoader("some_dir")
    plugins = default.get_plugins() + [
        paramplot_plugin.ParamPlotPlugin, loader
    ]
    gr_tensorboard = TensorBoard(plugins, lambda: open(asset_path, 'rb'))
    gr_tensorboard.configure(sys.argv)

    use_filesystem_controller = gr_tensorboard.flags.use_filesystem_controller
    original_logdir = pathlib.Path(gr_tensorboard.flags.logdir)
    loader.actual_logdir = str(original_logdir)
    if use_filesystem_controller:
        # Retrieve the actual log directory and replace it in the context with the new logdir
        parent_dir = original_logdir.parent
        print("logdir provided: " + str(original_logdir))
        new_logdir = parent_dir / "temp_dir"
        print("creating temporary workspace in " + str(new_logdir))

        # Create the temp dir
        new_logdir.mkdir(parents=True)

        # swap the original logdir for the new one
        gr_tensorboard.flags.logdir = str(new_logdir)

    try:
        sys.exit(gr_tensorboard.main())
    finally:
        if use_filesystem_controller:
            shutil.rmtree(str(new_logdir))
 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())
Example #8
0
  def __init__(self,
               plugins=None,
               assets_zip_provider=None,
               server_class=None):
    """Creates new instance.

    Args:
      plugins: A list of TensorBoard plugins to load, as TBLoader instances or
        TBPlugin classes. If not specified, defaults to first-party plugins.
      assets_zip_provider: Delegates to TBContext or uses default if None.
      server_class: An optional factory for a `TensorBoardServer` to use
        for serving the TensorBoard WSGI app. If provided, its callable
        signature should match that of `TensorBoardServer.__init__`.

    :type plugins: list[Union[base_plugin.TBLoader, Type[base_plugin.TBPlugin]]]
    :type assets_zip_provider: () -> file
    :type server_class: class
    """
    if plugins is None:
      from tensorboard import default
      plugins = default.get_plugins()
    if assets_zip_provider is None:
      assets_zip_provider = get_default_assets_zip_provider()
    if server_class is None:
      server_class = create_port_scanning_werkzeug_server
    def make_loader(plugin):
      if isinstance(plugin, base_plugin.TBLoader):
        return plugin
      if issubclass(plugin, base_plugin.TBPlugin):
        return base_plugin.BasicLoader(plugin)
      raise ValueError("Not a TBLoader or TBPlugin subclass: %s" % plugin)
    self.plugin_loaders = [make_loader(p) for p in plugins]
    self.assets_zip_provider = assets_zip_provider
    self.server_class = server_class
    self.flags = None
Example #9
0
def run_main():
    """Initializes flags and calls main()."""
    program.setup_environment()

    if getattr(tf, '__version__', 'stub') == 'stub':
        print(
            "TensorFlow installation not found - running with reduced feature set.",
            file=sys.stderr)

    tensorboard = program.TensorBoard(
        default.get_plugins() + default.get_dynamic_plugins(),
        program.get_default_assets_zip_provider(),
        subcommands=[uploader_main.UploaderSubcommand()])
    try:
        from absl import app
        # Import this to check that app.run() will accept the flags_parser argument.
        from absl.flags import argparse_flags
        app.run(tensorboard.main, flags_parser=tensorboard.configure)
        raise AssertionError("absl.app.run() shouldn't return")
    except ImportError:
        pass
    except base_plugin.FlagsError as e:
        print("Error: %s" % e, file=sys.stderr)
        sys.exit(1)

    tensorboard.configure(sys.argv)
    sys.exit(tensorboard.main())
Example #10
0
  def __init__(self,
               plugins=None,
               assets_zip_provider=None,
               server_class=None):
    """Creates new instance.

    Args:
      plugins: A list of TensorBoard plugins to load, as TBLoader instances or
        TBPlugin classes. If not specified, defaults to first-party plugins.
      assets_zip_provider: Delegates to TBContext or uses default if None.
      server_class: An optional subclass of TensorBoardServer to use for serving
        the TensorBoard WSGI app.

    :type plugins: list[Union[base_plugin.TBLoader, Type[base_plugin.TBPlugin]]]
    :type assets_zip_provider: () -> file
    :type server_class: class
    """
    if plugins is None:
      from tensorboard import default
      plugins = default.get_plugins()
    if assets_zip_provider is None:
      from tensorboard import default
      assets_zip_provider = default.get_assets_zip_provider()
    if server_class is None:
      server_class = WerkzeugServer
    def make_loader(plugin):
      if isinstance(plugin, base_plugin.TBLoader):
        return plugin
      if issubclass(plugin, base_plugin.TBPlugin):
        return base_plugin.BasicLoader(plugin)
      raise ValueError("Not a TBLoader or TBPlugin subclass: %s" % plugin)
    self.plugin_loaders = [make_loader(p) for p in plugins]
    self.assets_zip_provider = assets_zip_provider
    self.server_class = server_class
    self.flags = None
Example #11
0
def main(unused_argv=None):
  """Standard TensorBoard program CLI.

  See `tensorboard.program.main` for further documentation.
  """
  return program.main(default.get_plugins(),
                      default.get_assets_zip_provider())
Example #12
0
 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()))
Example #13
0
 def run(self):
     # Remove http messages
     log = logging.getLogger('tensorflow').setLevel(logging.FATAL)
     # Start tensorboard server
     tb = program.TensorBoard(default.get_plugins(), default.get_assets_zip_provider())
     tb.configure(argv=[None, '--logdir', self.dir_path])
     url = tb.launch()
     sys.stdout.write('TensorBoard at %s \n' % url)
Example #14
0
 def run(self):
     # Remove http messages
     log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
     # Start tensorboard server
     tb = program.TensorBoard(default.get_plugins())
     tb.configure(argv=[None, '--logdir', self.dir_path])
     url = tb.launch()
     sys.stdout.write('TensorBoard at %s \n' % url)
Example #15
0
 def run(self):
     tb = program.TensorBoard(
         default.get_plugins() + default.get_dynamic_plugins(), 
         program.get_default_assets_zip_provider())
     tb.configure(logdir = str(self.output / "tb"), port = self.port)
     log = logging.getLogger('tensorflow')
     log.setLevel(logging.CRITICAL)
     tb.main()
Example #16
0
    def __init__(
        self,
        plugins=None,
        assets_zip_provider=None,
        server_class=None,
        subcommands=None,
    ):
        """Creates new instance.

        Args:
          plugins: A list of TensorBoard plugins to load, as TBPlugin classes or
            TBLoader instances or classes. If not specified, defaults to first-party
            plugins.
          assets_zip_provider: A function that provides a zip file containing
            assets to the application. If `None`, the default TensorBoard web
            assets will be used. (If building from source, your binary must
            explicitly depend on `//tensorboard:assets_lib` if you pass `None`.)
          server_class: An optional factory for a `TensorBoardServer` to use
            for serving the TensorBoard WSGI app. If provided, its callable
            signature should match that of `TensorBoardServer.__init__`.

        :type plugins:
          list[
            base_plugin.TBLoader | Type[base_plugin.TBLoader] |
            Type[base_plugin.TBPlugin]
          ]
        """
        if plugins is None:
            from tensorboard import default

            plugins = default.get_plugins()
        if assets_zip_provider is None:
            try:
                from tensorboard import assets
            except ImportError as e:
                # `tensorboard.assets` is not a strict Bazel dep; clients are
                # required to either depend on `//tensorboard:assets_lib` or
                # pass a valid assets provider.
                raise ImportError(
                    "No `assets_zip_provider` given, but `tensorboard.assets` "
                    "could not be imported to resolve defaults") from e
            assets_zip_provider = assets.get_default_assets_zip_provider()
        if server_class is None:
            server_class = create_port_scanning_werkzeug_server
        if subcommands is None:
            subcommands = []
        self.plugin_loaders = [
            application.make_plugin_loader(p) for p in plugins
        ]
        self.assets_zip_provider = assets_zip_provider
        self.server_class = server_class
        self.subcommands = {}
        for subcommand in subcommands:
            name = subcommand.name()
            if name in self.subcommands or name == _SERVE_SUBCOMMAND_NAME:
                raise ValueError("Duplicate subcommand name: %r" % name)
            self.subcommands[name] = subcommand
        self.flags = None
Example #17
0
    def run(self):
        # Remove http messages
        log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
        logging.getLogger('tensorflow').setLevel(logging.ERROR)

        tb = program.TensorBoard(plugins=default.get_plugins())
        tb.configure(argv=[None, '--logdir', self.logdir])
        url = tb.launch()
        print('TensorBoard at %s \n' % url)
Example #18
0
 def run(self):
     # Remove http messages
     logging.getLogger("werkzeug").setLevel(logging.CRITICAL)
     logging.getLogger("tensorflow").setLevel(logging.CRITICAL)
     # Start tensorboard server
     tb = program.TensorBoard(default.get_plugins(), default.get_assets_zip_provider())
     tb.configure(argv=[None, "--logdir", self.dir_path, "--port", str(self.port)])
     url = tb.launch()
     print("TensorBoard at %s/#scalars&_smoothingWeight=0" % url)
Example #19
0
def run_tensorboard(log_path):
    log = logging.getLogger('tensorflow').setLevel(logging.ERROR)

    port_num = abs(hash(log_path))
    tb = program.TensorBoard(default.get_plugins(), get_assets_zip_provider())
    tb.configure(argv=None, '--logdir', str(log_path), '--port', str(port_num), '--samples_per_plugin', 'text=100'])

    url = tb.launch()
    return url
Example #20
0
def _plugins(disabled=None):
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", Warning)
        from tensorboard import default

    base_plugins = default.get_plugins() + default.get_dynamic_plugins()
    plugins = _filter_disabled_plugins(disabled, base_plugins)
    log.debug("TensorBoard plugins: %s", plugins)
    return plugins
Example #21
0
def run_main(asset_path):
    plugins = default.get_plugins() + [
        paramplot_plugin.ParamPlotPlugin,
        runsenabler_loader.RunsEnablerLoader()
    ]
    gr_tensorboard = TensorBoard(plugins, lambda: open(asset_path, 'rb'))
    gr_tensorboard.configure(sys.argv)

    sys.exit(gr_tensorboard.main())
Example #22
0
 def run(self):
     from tensorboard import default
     from tensorboard import program
     # remove http messages
     log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
     # Start tensorboard server
     tb = program.TensorBoard(default.get_plugins())
     tb.configure(argv=[
         None, '--logdir', self.dir_path, '--port', '6006', '--bind_all'
     ])
     url = tb.launch()
     print('Launched TensorBoard at {}'.format(url))
Example #23
0
def run_main():
    """Initializes flags and calls main()."""
    program.setup_environment()
    tensorboard = program.TensorBoard(default.get_plugins(),
                                      default.get_assets_zip_provider())
    try:
        from absl import app
        app.run(tensorboard.main, flags_parser=tensorboard.configure)
        raise AssertionError("absl.app.run() shouldn't return")
    except ImportError:
        pass
    tensorboard.configure(sys.argv)
    sys.exit(tensorboard.main())
Example #24
0
 def run(self, emb_name, port):
     # Remove http messages
     # log = logging.getLogger('sonvx').setLevel(logging.INFO)
     logging.basicConfig(level=logging.INFO)
     logging.propagate = False
     # Start tensorboard server
     tb = program.TensorBoard(default.get_plugins(),
                              default.get_assets_zip_provider())
     tb.configure(
         argv=[None, '--logdir', self.dir_path, '--port',
               str(port)])
     url = tb.launch()
     sys.stdout.write('TensorBoard of %s at %s \n' % (emb_name, url))
Example #25
0
def run_main():
    """Initializes flags and calls main()."""
    main_lib.global_init()

    tensorboard = program.TensorBoard(
        plugins=default.get_plugins(),
        subcommands=[uploader_subcommand.UploaderSubcommand()],
    )
    try:
        app.run(tensorboard.main, flags_parser=tensorboard.configure)
    except base_plugin.FlagsError as e:
        print("Error: %s" % e, file=sys.stderr)
        sys.exit(1)
Example #26
0
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='')
Example #27
0
    def run(self):
        # Remove http message
        log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
        # Start tensorboard server
        tb = customTensorBoard(
            default.get_plugins() + default.get_dynamic_plugins(),
            program.get_default_assets_zip_provider())

        tb.configure(
            argv=[None, '--logdir', self.dir_path, '--port',
                  str(self.port)])
        url = tb.launch()
        self.tb = tb
        return url
Example #28
0
        def run(self):
            # Remove http messages
            log = logging.getLogger('werkzeug').setLevel(logging.ERROR)

            logging.getLogger("tensorflow").setLevel(logging.WARNING)
            # Start tensorboard server
            tb = program.TensorBoard(default.get_plugins(),
                                     default.get_assets_zip_provider())
            tb.configure(argv=[
                None, '--logdir', self.dir_path, '--port',
                str(self.port)
            ])
            url = tb.launch()
            print('TensorBoard at %s \n' % url)
Example #29
0
 def run(self):
     # Remove http messages
     logging.getLogger('tensorflow').setLevel(logging.ERROR)
     logging.getLogger('werkzeug').setLevel(logging.ERROR)
     # Start tensorboard server
     tb = program.TensorBoard(default.get_plugins())
     # tb = program.TensorBoard(default.get_plugins(), default.get_assets_zip_provider())
     port = os.getenv('PORT')
     if not port:
         logging.warning("Don't set tensorboard port, use 6006!")
         port = '6006'
     tb.configure(argv=[None, '--logdir', self.dir_path, '--port', port])
     url = tb.launch()
     sys.stdout.write('TensorBoard at %s \n' % url)
Example #30
0
def run_main():
  """Initializes flags and calls main()."""
  program.setup_environment()
  tensorboard = program.TensorBoard(default.get_plugins(),
                                    default.get_assets_zip_provider())
  try:
    from absl import app
    # Import this to check that app.run() will accept the flags_parser argument.
    from absl.flags import argparse_flags
    app.run(tensorboard.main, flags_parser=tensorboard.configure)
    raise AssertionError("absl.app.run() shouldn't return")
  except ImportError:
    pass
  tensorboard.configure(sys.argv)
  sys.exit(tensorboard.main())
Example #31
0
def run_main():
    """Initializes flags and calls main()."""
    main_lib.global_init()

    path = os.path.join(os.path.dirname(__file__), "dev_webfiles.zip")
    tensorboard = program.TensorBoard(
        plugins=default.get_plugins(),
        assets_zip_provider=lambda: open(path, "rb"),
        subcommands=[uploader_subcommand.UploaderSubcommand()],
    )

    try:
        app.run(tensorboard.main, flags_parser=tensorboard.configure)
    except base_plugin.FlagsError as e:
        print("Error: %s" % e, file=sys.stderr)
        sys.exit(1)
def main(logdir):
    tb = program.TensorBoard(
        default.get_plugins(),
        program.get_default_assets_zip_provider(),
    )
    tb.configure(bind_all=False, logdir=logdir)
    url = tb.launch()
    sys.stdout.write("TensorBoard started at %s\n" % (url))
    sys.stdout.flush()
    while True:
        try:
            time.sleep(60)
        except KeyboardInterrupt:
            break
    sys.stdout.write("TensorBoard is shutting down")
    sys.stdout.flush()
Example #33
0
 def run(self):
     '''Launch the tensorboard.
     Note that this method would not block the main thread, we
     suggest to use launch() instead of this when you do not need
     to work with subthread.
     '''
     program.setup_environment()
     # Remove http messages
     log = logging.getLogger('werkzeug').setLevel(logging.ERROR)
     # Start tensorboard server
     _tb = program.TensorBoard(
         default.get_plugins(),
         program.get_default_assets_zip_provider())
     _tb.configure(argv=self.__collect_argvs())
     url = _tb.launch()
     print('TensorBoard at {0}, working on path: {1}.'.format(url, self.log_dir))