def testRawDataOp(self): with tf.summary.FileWriter( self.logdir) as writer, tf.Session() as sess: # We pass raw counts and precision/recall values. writer.add_summary( sess.run( summary.raw_data_op( tag='foo', true_positive_counts=tf.constant([75, 64, 21, 5, 0]), false_positive_counts=tf.constant([150, 105, 18, 0, 0]), true_negative_counts=tf.constant( [0, 45, 132, 150, 150]), false_negative_counts=tf.constant([0, 11, 54, 70, 75]), precision=tf.constant( [0.3333333, 0.3786982, 0.5384616, 1.0, 0.0]), recall=tf.constant( [1.0, 0.8533334, 0.28, 0.0666667, 0.0]), num_thresholds=5, display_name='some_raw_values', description='We passed raw values into a summary op.')) ) multiplexer = self.createMultiplexer() accumulator = multiplexer.GetAccumulator('.') tag_content_dict = accumulator.PluginTagToContent('pr_curves') self.assertItemsEqual(['foo/pr_curves'], list(tag_content_dict.keys())) # Test the metadata. summary_metadata = multiplexer.SummaryMetadata('.', 'foo/pr_curves') self.assertEqual('some_raw_values', summary_metadata.display_name) self.assertEqual('We passed raw values into a summary op.', summary_metadata.summary_description) # Test the stored plugin data. plugin_data = metadata.parse_plugin_metadata( tag_content_dict['foo/pr_curves']) self.assertEqual(5, plugin_data.num_thresholds) # Test the summary contents. tensor_events = accumulator.Tensors('foo/pr_curves') self.assertEqual(1, len(tensor_events)) self.validateTensorEvent( 0, [ [75.0, 64.0, 21.0, 5.0, 0.0], # True positives. [150.0, 105.0, 18.0, 0.0, 0.0], # False positives. [0.0, 45.0, 132.0, 150.0, 150.0], # True negatives. [0.0, 11.0, 54.0, 70.0, 75.0], # False negatives. [0.3333333, 0.3786982, 0.5384616, 1.0, 0.0], # Precision. [1.0, 0.8533334, 0.28, 0.0666667, 0.0], # Recall. ], tensor_events[0])
def test_raw_data(self): # We pass these raw counts and precision/recall values. name = "foo" true_positive_counts = [75, 64, 21, 5, 0] false_positive_counts = [150, 105, 18, 0, 0] true_negative_counts = [0, 45, 132, 150, 150] false_negative_counts = [0, 11, 54, 70, 75] precision = [0.3333333, 0.3786982, 0.5384616, 1.0, 0.0] recall = [1.0, 0.8533334, 0.28, 0.0666667, 0.0] num_thresholds = 5 display_name = "some_raw_values" description = "We passed raw values into a summary op." op = summary.raw_data_op( name=name, true_positive_counts=tf.constant(true_positive_counts), false_positive_counts=tf.constant(false_positive_counts), true_negative_counts=tf.constant(true_negative_counts), false_negative_counts=tf.constant(false_negative_counts), precision=tf.constant(precision), recall=tf.constant(recall), num_thresholds=num_thresholds, display_name=display_name, description=description, ) pb_via_op = self.normalize_summary_pb(self.pb_via_op(op)) # Call the corresponding method that is decoupled from TensorFlow. pb = self.normalize_summary_pb( summary.raw_data_pb( name=name, true_positive_counts=true_positive_counts, false_positive_counts=false_positive_counts, true_negative_counts=true_negative_counts, false_negative_counts=false_negative_counts, precision=precision, recall=recall, num_thresholds=num_thresholds, display_name=display_name, description=description, )) # The 2 methods above should write summaries with the same data. self.assertProtoEquals(pb, pb_via_op) # Test the metadata. summary_metadata = pb.value[0].metadata self.assertEqual("some_raw_values", summary_metadata.display_name) self.assertEqual( "We passed raw values into a summary op.", summary_metadata.summary_description, ) self.assertEqual(metadata.PLUGIN_NAME, summary_metadata.plugin_data.plugin_name) plugin_data = metadata.parse_plugin_metadata( summary_metadata.plugin_data.content) self.assertEqual(5, plugin_data.num_thresholds) # Test the summary contents. values = tensor_util.make_ndarray(pb.value[0].tensor) self.verify_float_arrays_are_equal( [ [75.0, 64.0, 21.0, 5.0, 0.0], # True positives. [150.0, 105.0, 18.0, 0.0, 0.0], # False positives. [0.0, 45.0, 132.0, 150.0, 150.0], # True negatives. [0.0, 11.0, 54.0, 70.0, 75.0], # False negatives. [0.3333333, 0.3786982, 0.5384616, 1.0, 0.0], # Precision. [1.0, 0.8533334, 0.28, 0.0666667, 0.0], # Recall. ], values, )