Instructions to use Addax-Data-Science/TAS-BB-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Addax-Data-Science/TAS-BB-v1 with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://Addax-Data-Science/TAS-BB-v1") - Notebooks
- Google Colab
- Kaggle
Upload inference.py
Browse files- inference.py +18 -0
inference.py
CHANGED
|
@@ -314,3 +314,21 @@ class ModelInference:
|
|
| 314 |
class_names[class_id_str] = class_name
|
| 315 |
|
| 316 |
return class_names
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
class_names[class_id_str] = class_name
|
| 315 |
|
| 316 |
return class_names
|
| 317 |
+
|
| 318 |
+
def get_tensor(self, crop: Image.Image):
|
| 319 |
+
"""Preprocess a crop into a numpy array for batch inference."""
|
| 320 |
+
img = np.array(crop)
|
| 321 |
+
img = cv2.resize(img, (self.img_size, self.img_size))
|
| 322 |
+
return img
|
| 323 |
+
|
| 324 |
+
def classify_batch(self, batch):
|
| 325 |
+
"""Run inference on a batch of preprocessed numpy arrays."""
|
| 326 |
+
probs = self.model.predict(batch, verbose=0)
|
| 327 |
+
results = []
|
| 328 |
+
for p in probs:
|
| 329 |
+
classifications = [
|
| 330 |
+
[self.class_ids[i], float(p[i])]
|
| 331 |
+
for i in range(len(self.class_ids))
|
| 332 |
+
]
|
| 333 |
+
results.append(classifications)
|
| 334 |
+
return results
|