def FetchPredictionsFromFile(filepath): """Fetch PredictionOutputs proto from file. Args: filepath: local file to load the PredictionOutputs proto Returns: PredictionOutputs """ pred_outputs = prediction_output_pb2.PredictionOutputs() with open(filepath, 'rb') as f: pred_outputs.ParseFromString(f.read()) return pred_outputs
def setUp(self): super(PredictionDataServiceTest, self).setUp() tf_ex = tf.train.Example() feature = tf_ex.features.feature feature['eeg_channel/num_samples'].int64_list.value.append(20) feature['eeg_channel/sampling_frequency_hz'].float_list.value.append( 1.0) for i in range(20): feature['test_feature'].float_list.value.append(i * 2) for i in range(20): feature[('eeg_channel/EEG ' 'test_sub-REF/samples')].float_list.value.append(i + 1) for i in range(20): feature[('eeg_channel/EEG ' 'test_min-REF/samples')].float_list.value.append(1) time = timestamp_pb2.Timestamp() time.seconds = 10 time.nanos = 800000000 feature['start_time'].bytes_list.value.append(time.SerializeToString()) feature['segment/patient_id'].bytes_list.value.append(b'test patient') waveform_data_source = data_source.TfExampleEegDataSource( tf_ex, 'test key') pred_outputs = prediction_output_pb2.PredictionOutputs() pred_output = pred_outputs.prediction_output.add() pred_output.chunk_info.chunk_id = 'test chunk' pred_output.chunk_info.chunk_start_time.seconds = 10 pred_output.chunk_info.chunk_start_time.nanos = 800000000 pred_output.chunk_info.chunk_size_sec = 2 label = pred_output.label.add() label.name = 'test label' pred_output_2 = pred_outputs.prediction_output.add() pred_output_2.chunk_info.chunk_id = 'test chunk 2' pred_output_2.chunk_info.chunk_start_time.seconds = 12 pred_output_2.chunk_info.chunk_start_time.nanos = 800000000 pred_output_2.chunk_info.chunk_size_sec = 2 label = pred_output_2.label.add() label.name = 'test label' self._pred = prediction_data_service.PredictionDataService( pred_outputs, waveform_data_source, 100)
TEST_TF_EX = tf.train.Example() feature = TEST_TF_EX.features.feature feature['eeg_channel/num_samples'].int64_list.value.append(4) feature['eeg_channel/sampling_frequency_hz'].float_list.value.append(1.0) feature['test_feature'].float_list.value.extend([i * 2 for i in range(20)]) feature['eeg_channel/EEG test_min-REF/samples'].float_list.value.extend( [1, 2, 3, 4]) feature['eeg_channel/EEG test_sub-REF/samples'].float_list.value.extend( [1, 1, 1, 1]) feature['raw_label_events'].bytes_list.value.append( TEST_ANNOTATION.SerializeToString()) feature['start_time'].bytes_list.value.append(TEST_TIME.SerializeToString()) feature['segment/patient_id'].bytes_list.value.append('test id') TEST_PRED = prediction_output_pb2.PredictionOutputs() pred_output = TEST_PRED.prediction_output.add() pred_output.chunk_info.chunk_id = 'test chunk' pred_output.chunk_info.chunk_start_time.seconds = 10 pred_output.chunk_info.chunk_start_time.nanos = 800000000 pred_output.chunk_info.chunk_size_sec = 2 label = pred_output.label.add() label.name = 'test label' label.predicted_value.score = 3 label.actual_value.score = 1 label.attribution_map.attribution.extend(list(range(1, 9))) label.attribution_map.width = 4 label.attribution_map.height = 2 label.attribution_map.feature_names.extend([ 'eeg_channel/EEG test_sub-REF/samples#eeg_channel/EEG test_min-REF/samples', 'eeg_channel/EEG test_min-REF/samples#eeg_channel/EEG test_sub-REF/samples',