Instructions to use guicon/techchallenge-pet-computer-vision-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use guicon/techchallenge-pet-computer-vision-model with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://guicon/techchallenge-pet-computer-vision-model") - Notebooks
- Google Colab
- Kaggle
File size: 591 Bytes
9dc814d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import tensorflow as tf
import numpy as np
IMG_SIZE = 160
model = tf.keras.models.load_model("model")
with open("labels.txt") as f:
class_names = [line.strip() for line in f.readlines()]
def predict(image):
img = image.resize((IMG_SIZE, IMG_SIZE))
img_array = np.array(img)
if img_array.shape[-1] == 4:
img_array = img_array[:, :, :3]
img_array = np.expand_dims(img_array, axis=0)
preds = model.predict(img_array, verbose=0)[0]
idx = np.argmax(preds)
return {
"classe": class_names[idx],
"confidence": float(preds[idx])
}
|