Untitled
unknown
plain_text
7 months ago
1.2 kB
2
Indexable
Never
import numpy as np import tensorflow as tf def calculate_metrics(predictions, labels, threshold=0.5): # Threshold predictions predictions_binary = (predictions > threshold).astype(np.int32) # Calculate correct and incorrect predictions correct_predictions = np.sum(predictions_binary == labels) incorrect_predictions = np.sum(predictions_binary != labels) # Calculate misses (false negatives) misses = np.sum((predictions_binary == 0) & (labels == 1)) # Calculate IoU per segment intersection = np.logical_and(predictions_binary, labels) union = np.logical_or(predictions_binary, labels) iou = np.sum(intersection) / np.sum(union) return correct_predictions, incorrect_predictions, misses, iou # Example usage: # Assuming `model_output` is your model's output, and `true_labels` are your true labels model_output = ... # Your model's output true_labels = ... # Your ground truth labels correct, incorrect, misses, iou = calculate_metrics(model_output, true_labels) print(f"Correct Predictions: {correct}") print(f"Incorrect Predictions: {incorrect}") print(f"Misses: {misses}") print(f"IoU: {iou}")
Leave a Comment