Enterwar99 commited on
Commit
f7c13c9
·
verified ·
1 Parent(s): aae80c6

Update api_app.py

Browse files
Files changed (1) hide show
  1. api_app.py +4 -4
api_app.py CHANGED
@@ -116,17 +116,17 @@ def predict_with_mc_dropout(current_model_instance, input_tensor_on_device, mc_d
116
  std_dev_probabilities = np.std(predictions_stack, axis=0) # Kształt: (num_classes,)
117
 
118
  predicted_class_index = np.argmax(mean_probabilities)
119
- confidence_in_predicted_class = mean_probabilities[predicted_class_index]
120
 
121
  # Użyj średniej odchyleń standardowych prawdopodobieństw wszystkich klas jako metryki niepewności
122
  uncertainty_metric = np.mean(std_dev_probabilities)
123
 
124
  is_uncertain = uncertainty_metric > uncertainty_threshold_std # Użyj uncertainty_threshold_std
125
- logger.info(f"MC Dropout Results: Predicted Index: {predicted_class_index}, Confidence: {confidence_in_predicted_class:.4f}, Uncertainty (avg_std): {uncertainty_metric:.4f}, Is Uncertain: {is_uncertain}")
126
 
127
- birads_category_if_confident = predicted_class_index + 1
128
  base_result = {
129
- "birads": birads_category_if_confident if not is_uncertain else None,
130
  "confidence": float(confidence_in_predicted_class) if not is_uncertain else None,
131
  "interpretation": interpretations_dict.get(birads_category_if_confident, "Nieznana klasyfikacja") if not is_uncertain \
132
  else f"Model jest niepewny co do tego obrazu (niepewność: {uncertainty_metric:.4f}). Sprawdź jakość i typ obrazu. Może to być obraz spoza domeny medycznej.",
 
116
  std_dev_probabilities = np.std(predictions_stack, axis=0) # Kształt: (num_classes,)
117
 
118
  predicted_class_index = np.argmax(mean_probabilities)
119
+ confidence_in_predicted_class = float(mean_probabilities[predicted_class_index]) # Jawna konwersja do float
120
 
121
  # Użyj średniej odchyleń standardowych prawdopodobieństw wszystkich klas jako metryki niepewności
122
  uncertainty_metric = np.mean(std_dev_probabilities)
123
 
124
  is_uncertain = uncertainty_metric > uncertainty_threshold_std # Użyj uncertainty_threshold_std
125
+ logger.info(f"MC Dropout Results: Predicted Index: {int(predicted_class_index)}, Confidence: {confidence_in_predicted_class:.4f}, Uncertainty (avg_std): {uncertainty_metric:.4f}, Is Uncertain: {is_uncertain}")
126
 
127
+ birads_category_if_confident = int(predicted_class_index) + 1 # Jawna konwersja do int
128
  base_result = {
129
+ "birads": int(birads_category_if_confident) if not is_uncertain else None, # Jawna konwersja do int
130
  "confidence": float(confidence_in_predicted_class) if not is_uncertain else None,
131
  "interpretation": interpretations_dict.get(birads_category_if_confident, "Nieznana klasyfikacja") if not is_uncertain \
132
  else f"Model jest niepewny co do tego obrazu (niepewność: {uncertainty_metric:.4f}). Sprawdź jakość i typ obrazu. Może to być obraz spoza domeny medycznej.",