MCPcopy Create free account
hub / github.com/GitsSaikat/PyGen / predict

Method predict

data/AutoVison/context_code.py:82–103  ·  view source on GitHub ↗

Predict class for new image

(self, img)

Source from the content-addressed store, hash-verified

80 }
81
82 def predict(self, img):
83 """Predict class for new image"""
84 if self.model is None:
85 raise ValueError("Model not trained. Please train the model first.")
86
87 processed_img = self.preprocess_image(img)
88 features = self.extract_features(processed_img)
89
90 # Concatenate features similar to training
91 feature_vector = np.concatenate([
92 features['hog'].flatten(),
93 features['color'].flatten(),
94 features['sift'].flatten() if features['sift'] is not None else np.zeros(128)
95 ])
96
97 prediction = self.model.predict([feature_vector])[0]
98 confidence = np.max(self.model.predict_proba([feature_vector]))
99
100 return {
101 'prediction': prediction,
102 'confidence': confidence
103 }
104
105 def save_model(self, path):
106 """Save trained model"""

Callers 3

mainFunction · 0.95
trainMethod · 0.45
evaluate_modelMethod · 0.45

Calls 2

preprocess_imageMethod · 0.95
extract_featuresMethod · 0.95

Tested by

no test coverage detected