Ejemplo n.º 1
0
def load_data_for_model(doc: Document, plots: TrainTestPlots, logdir: Path) -> None:
    last_epoch = 0
    while doc.session_context:
        try:
            path = logdir / 'metrics' / f'epoch_{last_epoch}'
            new_metrics = load_metrics(str(path))
            last_epoch += 1
            doc.add_next_tick_callback(partial(update_aggregated_metrics, plots, new_metrics))
        except OSError:
            time.sleep(1)
    logger.info("Connection closed")
Ejemplo n.º 2
0
def load_profiling_data(doc: Document, plots: ProfilingPlots, logdir: Path, model_name: str) -> None:
    last_epoch = 0
    while doc.session_context:
        try:
            path = logdir / 'metrics' / f'epoch_{last_epoch}'
            new_metrics = load_metrics(str(path))
            last_epoch += 1
            doc.add_next_tick_callback(partial(update_profiling_metrics, plots, new_metrics))
            METRICS[model_name] = new_metrics
        except OSError:
            time.sleep(1)
    logger.info("Connection closed")
Ejemplo n.º 3
0
def modify_doc(doc: Document):
    plot = figure(x_axis_type='datetime')

    # _source = ColumnDataSource(data=data_holder.get_data())

    def callback():
        d = data_holder.get_data()
        # d = {'a': [(1,123), (2,130), (3, 133)], 'b':[(4,123),(5,130),(6,133)]}

        for k_vtlist, color in zip(d.items(), Spectral4):
            k, vt_list = k_vtlist
            v, t = zip(*vt_list)
            plot.circle(t, v, legend=k, color=color)

    doc.add_next_tick_callback(callback)

    doc.add_root(plot)
Ejemplo n.º 4
0
    def plot(self, metrics: typing.List[typing.Dict[str, np.ndarray]],
             plot: Figure, doc: Document):
        # Override the plot method to perform plotting

        def get_metrics() -> typing.Iterable[typing.Tuple[str, np.ndarray]]:
            """Method to get the metrics in the required format

            Yields:
                typing.Tuple[str, np.ndarray] -- the metric for a specific axis
            """
            for i, agent_metrics in enumerate(metrics):
                for axis, metric in zip(("x", "y"), self._metrics):
                    yield f"{axis}{i}", metric.select(agent_metrics)

        # Add a callback that will update the plot with the new data on the next tick
        doc.add_next_tick_callback(
            partial(self._source.stream, dict(get_metrics())))