def _get_tensorboard_scalars(logdir: Union[str,
                                           Path], metrics: Optional[List[str]],
                             step: str) -> Dict[str, List]:
    summary_reader = SummaryReader(logdir, types=["scalar"])

    items = defaultdict(list)
    for item in summary_reader:
        if step in item.tag and (metrics is None or any(m in item.tag
                                                        for m in metrics)):
            items[item.tag].append(item)
    return items
示例#2
0
def test_summary_reader_iterate():
    reader = SummaryReader('logs', types=['scalar', 'image'])
    _, data_raw = _get_test_data()
    data_raw2 = 2 * [d for d in data_raw if d is not None]
    items = list(reader)

    assert len(items) == len(data_raw2)

    for item, event_raw in zip(items, data_raw2):
        assert item.step == event_raw['step']
        assert item.tag == event_raw['tag']
        assert item.type == event_raw['type']
        assert np.all(item.value == event_raw['value'])
示例#3
0
def test_summary_reader_iterate():
    reader = SummaryReader("logs", types=["scalar", "image"])
    _, data_raw = _get_test_data()
    data_raw2 = 2 * [d for d in data_raw if d is not None]
    items = list(reader)

    assert len(items) == len(data_raw2)

    for item, event_raw in zip(items, data_raw2):
        assert item.step == event_raw["step"]
        assert item.tag == event_raw["tag"]
        assert item.type == event_raw["type"]
        assert np.all(item.value == event_raw["value"])
示例#4
0
def test_summary_reader_filter_scalars():
    types = ['scalar']
    reader = SummaryReader('logs', types=types)
    _, data_raw = _get_test_data()
    data_raw2 = 2 * [
        d for d in data_raw if d is not None and d['type'] in types
    ]
    items = list(reader)

    assert len(items) == len(data_raw2)

    for item, event_raw in zip(items, data_raw2):
        assert item.step == event_raw['step']
        assert item.tag == event_raw['tag']
        assert item.type == 'scalar'
        assert np.all(item.value == event_raw['value'])
示例#5
0
def test_summary_reader_filter_scalars():
    types = ["scalar"]
    reader = SummaryReader("logs", types=types)
    _, data_raw = _get_test_data()
    data_raw2 = 2 * [
        d for d in data_raw if d is not None and d["type"] in types
    ]
    items = list(reader)

    assert len(items) == len(data_raw2)

    for item, event_raw in zip(items, data_raw2):
        assert item.step == event_raw["step"]
        assert item.tag == event_raw["tag"]
        assert item.type == "scalar"
        assert np.all(item.value == event_raw["value"])
示例#6
0
def test_summary_reader_invalid_type():
    with pytest.raises(ValueError):
        SummaryReader('.', types=['unknown-type'])
示例#7
0
def test_summary_reader_invalid_type():
    with pytest.raises(ValueError):
        SummaryReader(".", types=["unknown-type"])