Upload inference.py
Browse files229 unmodified lines230231232233234235236237238239240241242243244245246247248249250229 unmodified lines
except Exception as e: raise RuntimeError(f"Failed to extract class names: {e}") from e
def get_tensor(self, crop: Image.Image): """Preprocess a crop into a numpy array for batch inference.""" img = np.array(crop) img = cv2.resize(img, (self.img_size, self.img_size)) return img
def classify_batch(self, batch): """Run inference on a batch of preprocessed numpy arrays.""" probs = self.model.predict(batch, verbose=0) results = [] for p in probs: classifications = [ [self.class_ids_sorted[i], float(p[i])] for i in range(len(self.class_ids_sorted)) ] results.append(classifications) return resultsinference.py+18