|
|
|
@ -52,12 +52,11 @@ def _wrap_test_data(input_data: Tensor):
|
|
|
|
|
def test_histogram_summary():
|
|
|
|
|
"""Test histogram summary."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
|
|
|
|
|
|
|
|
|
|
test_data = _wrap_test_data(Tensor([[1, 2, 3], [4, 5, 6]]))
|
|
|
|
|
_cache_summary_tensor_data(test_data)
|
|
|
|
|
test_writer.record(step=1)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
@ -68,7 +67,7 @@ def test_histogram_summary():
|
|
|
|
|
def test_histogram_multi_summary():
|
|
|
|
|
"""Test histogram multiple step."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
|
|
|
|
|
|
|
|
|
|
rng = np.random.RandomState(10)
|
|
|
|
|
size = 50
|
|
|
|
@ -81,8 +80,6 @@ def test_histogram_multi_summary():
|
|
|
|
|
_cache_summary_tensor_data(test_data)
|
|
|
|
|
test_writer.record(step=i)
|
|
|
|
|
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
|
for _ in range(num_step):
|
|
|
|
@ -93,12 +90,11 @@ def test_histogram_multi_summary():
|
|
|
|
|
def test_histogram_summary_scalar_tensor():
|
|
|
|
|
"""Test histogram summary, input is a scalar tensor."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
|
|
|
|
|
|
|
|
|
|
test_data = _wrap_test_data(Tensor(1))
|
|
|
|
|
_cache_summary_tensor_data(test_data)
|
|
|
|
|
test_writer.record(step=1)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
@ -109,12 +105,11 @@ def test_histogram_summary_scalar_tensor():
|
|
|
|
|
def test_histogram_summary_empty_tensor():
|
|
|
|
|
"""Test histogram summary, input is an empty tensor."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
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)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
@ -125,7 +120,7 @@ def test_histogram_summary_empty_tensor():
|
|
|
|
|
def test_histogram_summary_same_value():
|
|
|
|
|
"""Test histogram summary, input is an ones tensor."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
|
|
|
|
|
|
|
|
|
|
dim1 = 100
|
|
|
|
|
dim2 = 100
|
|
|
|
@ -133,7 +128,6 @@ def test_histogram_summary_same_value():
|
|
|
|
|
test_data = _wrap_test_data(Tensor(np.ones([dim1, dim2])))
|
|
|
|
|
_cache_summary_tensor_data(test_data)
|
|
|
|
|
test_writer.record(step=1)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
@ -146,7 +140,7 @@ def test_histogram_summary_same_value():
|
|
|
|
|
def test_histogram_summary_high_dims():
|
|
|
|
|
"""Test histogram summary, input is a 4-dimension tensor."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
|
|
|
|
|
dim = 10
|
|
|
|
|
|
|
|
|
|
rng = np.random.RandomState(0)
|
|
|
|
@ -154,7 +148,6 @@ def test_histogram_summary_high_dims():
|
|
|
|
|
test_data = _wrap_test_data(Tensor(tensor_data))
|
|
|
|
|
_cache_summary_tensor_data(test_data)
|
|
|
|
|
test_writer.record(step=1)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
@ -167,7 +160,7 @@ def test_histogram_summary_high_dims():
|
|
|
|
|
def test_histogram_summary_nan_inf():
|
|
|
|
|
"""Test histogram summary, input tensor has nan."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
with SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") as test_writer:
|
|
|
|
|
|
|
|
|
|
dim1 = 100
|
|
|
|
|
dim2 = 100
|
|
|
|
@ -180,7 +173,6 @@ def test_histogram_summary_nan_inf():
|
|
|
|
|
|
|
|
|
|
_cache_summary_tensor_data(test_data)
|
|
|
|
|
test_writer.record(step=1)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
@ -193,12 +185,11 @@ def test_histogram_summary_nan_inf():
|
|
|
|
|
def test_histogram_summary_all_nan_inf():
|
|
|
|
|
"""Test histogram summary, input tensor has no valid number."""
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM")
|
|
|
|
|
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)
|
|
|
|
|
test_writer.close()
|
|
|
|
|
|
|
|
|
|
file_name = os.path.join(tmp_dir, test_writer.event_file_name)
|
|
|
|
|
reader = SummaryReader(file_name)
|
|
|
|
|