BlueSR commited on
Commit
ae70b23
·
verified ·
1 Parent(s): ce2ce33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -6
app.py CHANGED
@@ -85,16 +85,11 @@ def extract_features_single(cnn_model, image_tensor):
85
  """Extract features from a single image using CNN for Random Forest"""
86
  cnn_model.eval()
87
  with torch.no_grad():
88
- # Get features from the layer before final classification
89
  features = cnn_model.features(image_tensor)
90
  features = cnn_model.avgpool(features)
91
  features = torch.flatten(features, 1)
92
 
93
- # Pass through the first part of classifier (before final layer)
94
- if hasattr(cnn_model.classifier, '__iter__'):
95
- for i, layer in enumerate(cnn_model.classifier[:-1]): # Exclude final classification layer
96
- features = layer(features)
97
-
98
  return features.cpu().numpy()
99
 
100
  # Preprocess image for CNN
 
85
  """Extract features from a single image using CNN for Random Forest"""
86
  cnn_model.eval()
87
  with torch.no_grad():
88
+ # Extract raw 1280-dim features (matching how the RF model was trained)
89
  features = cnn_model.features(image_tensor)
90
  features = cnn_model.avgpool(features)
91
  features = torch.flatten(features, 1)
92
 
 
 
 
 
 
93
  return features.cpu().numpy()
94
 
95
  # Preprocess image for CNN