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) reader = SummaryReader(file_name) event = reader.read_event() LOG.debug(event) assert event.summary.value[0].histogram.nan_count == 1
def summary_cb_for_save_op(summary_list): """ The summary callback function for MindSpore. Will be executed by summary op. Args: summary_list (list): Format is like [{"name": tag_name, "data": tensor},...] and value is Scalar/Tensor. Returns: bool, true: means save summary success. """ ret = _cache_summary_tensor_data(summary_list) return ret
def test_histogram_multi_summary(): """Test histogram multiple step.""" with tempfile.TemporaryDirectory() as tmp_dir: test_writer = SummaryRecord(tmp_dir, file_suffix="_MS_HISTOGRAM") 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) test_writer.close() file_name = os.path.join(tmp_dir, test_writer.event_file_name) reader = SummaryReader(file_name) for _ in range(num_step): event = reader.read_event() assert event.summary.value[0].histogram.count == size
def test_image_summary_data(): """ test_image_summary_data """ dataset = get_dataset() test_data_list = [] i = 1 for next_element in dataset: tag = "image_" + str(i) + "[:Image]" dct = {} dct["name"] = tag dct["data"] = Tensor(next_element[0]) test_data_list.append(dct) i += 1 log.debug("begin test_image_summary_sample") # step 0: create the thread with SummaryRecord(SUMMARY_DIR, file_suffix="_MS_IMAGE") as test_writer: # step 1: create the test data for summary # step 2: create the Event _cache_summary_tensor_data(test_data_list) test_writer.record(1) log.debug("finished test_image_summary_sample")