jays009 commited on
Commit
fcc2886
·
verified ·
1 Parent(s): 8a47119

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -11,8 +11,8 @@ from io import BytesIO
11
  import numpy as np
12
  from scipy.spatial.distance import mahalanobis
13
 
14
- # Setup logging
15
- logging.basicConfig(level=logging.INFO)
16
  logger = logging.getLogger(__name__)
17
 
18
  # Define the number of classes
@@ -92,7 +92,7 @@ def is_in_distribution(features):
92
  distance = compute_mahalanobis_distance(features, mean, cov)
93
  distances.append(distance)
94
  min_distance = min(distances)
95
- logger.info(f"Minimum Mahalanobis distance: {min_distance:.4f}")
96
  return min_distance < MAHALANOBIS_THRESHOLD
97
 
98
  # Prediction function for an uploaded image
@@ -105,7 +105,6 @@ def predict_from_image_url(image_url):
105
 
106
  # Apply transformations
107
  image_tensor = transform(image).unsqueeze(0) # Shape: [1, 3, 224, 224]
108
- logger.info(f"Input image tensor shape: {image_tensor.shape}")
109
 
110
  # Extract features from the penultimate layer
111
  with torch.no_grad():
@@ -129,10 +128,7 @@ def predict_from_image_url(image_url):
129
  # Stage 2: Main Model Prediction
130
  with torch.no_grad():
131
  outputs = main_model(image_tensor) # Shape: [1, 3]
132
- logger.info(f"Model output shape: {outputs.shape}")
133
- logger.info(f"Raw logits: {outputs[0].numpy()}")
134
  probabilities = torch.softmax(outputs, dim=1)[0] # Convert to probabilities
135
- logger.info(f"Softmax probabilities: {probabilities.numpy()}")
136
  predicted_class = torch.argmax(outputs, dim=1).item()
137
 
138
  # Define class information
 
11
  import numpy as np
12
  from scipy.spatial.distance import mahalanobis
13
 
14
+ # Setup logging (reduced to WARNING level)
15
+ logging.basicConfig(level=logging.WARNING)
16
  logger = logging.getLogger(__name__)
17
 
18
  # Define the number of classes
 
92
  distance = compute_mahalanobis_distance(features, mean, cov)
93
  distances.append(distance)
94
  min_distance = min(distances)
95
+ logger.info(f"Minimum Mahalanobis distance: {min_distance:.4f}") # Keep this log for calibration
96
  return min_distance < MAHALANOBIS_THRESHOLD
97
 
98
  # Prediction function for an uploaded image
 
105
 
106
  # Apply transformations
107
  image_tensor = transform(image).unsqueeze(0) # Shape: [1, 3, 224, 224]
 
108
 
109
  # Extract features from the penultimate layer
110
  with torch.no_grad():
 
128
  # Stage 2: Main Model Prediction
129
  with torch.no_grad():
130
  outputs = main_model(image_tensor) # Shape: [1, 3]
 
 
131
  probabilities = torch.softmax(outputs, dim=1)[0] # Convert to probabilities
 
132
  predicted_class = torch.argmax(outputs, dim=1).item()
133
 
134
  # Define class information