예제 #1
0
    def _check_summary_result(summary_dir):
        summary_file_path = ''
        for file in os.listdir(summary_dir):
            if re.search("_MS", file):
                summary_file_path = os.path.join(summary_dir, file)
                break

        assert not summary_file_path

        with SummaryReader(summary_file_path) as summary_reader:
            tags = set()

            # Read the event that record by SummaryCollector.begin
            summary_reader.read_event()

            summary_event = summary_reader.read_event()
            for value in summary_event.summary.value:
                tags.add(value.tag)

            # There will not record input data when dataset sink mode is True
            expected_tags = [
                'conv1.weight/auto', 'conv2.weight/auto', 'fc1.weight/auto',
                'fc1.bias/auto', 'fc2.weight/auto', 'histogram', 'image',
                'scalar', 'tensor'
            ]
            assert set(expected_tags) == tags
예제 #2
0
def test_summary():
    with tempfile.TemporaryDirectory() as tmp_dir:
        steps = 2
        with SummaryRecord(tmp_dir) as test_writer:
            train_summary_record(test_writer, steps=steps)

            file_name = os.path.realpath(test_writer.full_file_name)
        with SummaryReader(file_name) as summary_writer:
            for _ in range(steps):
                event = summary_writer.read_event()
                tags = set(value.tag for value in event.summary.value)
                assert tags == {'tensor', 'histogram', 'scalar', 'image'}
예제 #3
0
def test_histogram_summary_empty_tensor():
    """Test histogram summary, input is an empty tensor."""
    with tempfile.TemporaryDirectory() as tmp_dir:
        with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
            test_data = _wrap_test_data(Tensor([]))
            _cache_summary_tensor_data(test_data)
            test_writer.record(step=1)

        file_name = os.path.join(tmp_dir, test_writer.event_file_name)
        with SummaryReader(file_name) as reader:
            event = reader.read_event()
            assert event.summary.value[0].histogram.count == 0
예제 #4
0
def test_histogram_summary_all_nan_inf():
    """Test histogram summary, input tensor has no valid number."""
    with tempfile.TemporaryDirectory() as tmp_dir:
        with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
            test_data = _wrap_test_data(Tensor(np.array([np.nan, np.nan, np.nan, np.inf, -np.inf])))
            _cache_summary_tensor_data(test_data)
            test_writer.record(step=1)

        file_name = os.path.join(tmp_dir, test_writer.event_file_name)
        with SummaryReader(file_name) as reader:
            event = reader.read_event()
            LOG.debug(event)

            histogram = event.summary.value[0].histogram
            assert histogram.nan_count == 3
            assert histogram.pos_inf_count == 1
            assert histogram.neg_inf_count == 1
예제 #5
0
def test_histogram_summary_same_value():
    """Test histogram summary, input is an ones tensor."""
    with tempfile.TemporaryDirectory() as tmp_dir:
        with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
            dim1 = 100
            dim2 = 100

            test_data = _wrap_test_data(Tensor(np.ones([dim1, dim2])))
            _cache_summary_tensor_data(test_data)
            test_writer.record(step=1)

        file_name = os.path.join(tmp_dir, test_writer.event_file_name)
        with SummaryReader(file_name) as reader:
            event = reader.read_event()
            LOG.debug(event)

            assert len(event.summary.value[0].histogram.buckets) == _calc_histogram_bins(dim1 * dim2)
예제 #6
0
def test_summary_step2_summary_record1():
    """Test record 10 step summary."""
    if platform.system() == "Windows":
        # Summary does not support windows currently.
        return

    with tempfile.TemporaryDirectory() as tmp_dir:
        steps = 2
        with SummaryRecord(tmp_dir) as test_writer:
            train_summary_record(test_writer, steps=steps)

            file_name = os.path.realpath(test_writer.full_file_name)
        with SummaryReader(file_name) as summary_writer:
            for _ in range(steps):
                event = summary_writer.read_event()
                tags = set(value.tag for value in event.summary.value)
                assert tags == {'tensor', 'histogram', 'scalar', 'image'}
예제 #7
0
    def _list_summary_tags(summary_dir):
        summary_file_path = ''
        for file in os.listdir(summary_dir):
            if re.search("_MS", file):
                summary_file_path = os.path.join(summary_dir, file)
                break
        assert summary_file_path

        tags = list()
        with SummaryReader(summary_file_path) as summary_reader:

            while True:
                summary_event = summary_reader.read_event()
                if not summary_event:
                    break
                for value in summary_event.summary.value:
                    tags.append(value.tag)
        return tags
예제 #8
0
def test_histogram_summary_high_dims():
    """Test histogram summary, input is a 4-dimension tensor."""
    with tempfile.TemporaryDirectory() as tmp_dir:
        with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
            dim = 10

            rng = np.random.RandomState(0)
            tensor_data = rng.normal(size=[dim, dim, dim, dim])
            test_data = _wrap_test_data(Tensor(tensor_data))
            _cache_summary_tensor_data(test_data)
            test_writer.record(step=1)

        file_name = os.path.join(tmp_dir, test_writer.event_file_name)
        with SummaryReader(file_name) as reader:
            event = reader.read_event()
            LOG.debug(event)

            assert event.summary.value[0].histogram.count == tensor_data.size
예제 #9
0
def test_histogram_multi_summary():
    """Test histogram multiple step."""
    with tempfile.TemporaryDirectory() as tmp_dir:
        with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:

            rng = np.random.RandomState(10)
            size = 50
            num_step = 5

            for i in range(num_step):
                arr = rng.normal(size=size)

                test_data = _wrap_test_data(Tensor(arr))
                _cache_summary_tensor_data(test_data)
                test_writer.record(step=i)

        file_name = os.path.join(tmp_dir, test_writer.event_file_name)
        with SummaryReader(file_name) as reader:
            for _ in range(num_step):
                event = reader.read_event()
                assert event.summary.value[0].histogram.count == size
예제 #10
0
def test_histogram_summary_nan_inf():
    """Test histogram summary, input tensor has nan."""
    with tempfile.TemporaryDirectory() as tmp_dir:
        with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
            dim1 = 100
            dim2 = 100

            arr = np.ones([dim1, dim2])
            arr[0][0] = np.nan
            arr[0][1] = np.inf
            arr[0][2] = -np.inf
            test_data = _wrap_test_data(Tensor(arr))

            _cache_summary_tensor_data(test_data)
            test_writer.record(step=1)

        file_name = os.path.join(tmp_dir, test_writer.event_file_name)
        with SummaryReader(file_name) as reader:
            event = reader.read_event()
            LOG.debug(event)

            assert event.summary.value[0].histogram.nan_count == 1