Instructions to use nxtdev/CDC-Processing with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use nxtdev/CDC-Processing 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://nxtdev/CDC-Processing") - Notebooks
- Google Colab
- Kaggle
File size: 1,298 Bytes
949bf24 | 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import numpy as np
from keras.models import load_model
from PIL import Image
import tensorflow as tf
# Load the model
model = load_model("model_img_pro.keras") # Update with your actual model path
# Function to preprocess the image
def preprocess_image(image_path, target_size):
# Load and resize the image
image = Image.open(image_path).convert('RGB')
image = image.resize(target_size)
# Convert image to array and normalize
image_array = np.array(image) / 255.0
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
return image_array
# Define target size based on your model
target_size = (224, 224) # Example size; update based on your model's expected input
# Path to the image you want to classify
image_path = "path_to_your_image.jpg" # Update with your image path
# Preprocess the image
processed_image = preprocess_image(image_path, target_size)
# Make predictions
predictions = model.predict(processed_image)
# Print the predictions
print(predictions)
# Optionally, decode the predictions if needed
# For binary classification (cat vs dog), you might have a single output neuron
# Example: if predictions[0][0] > 0.5, it's a dog; otherwise, it's a cat
if predictions[0][0] > 0.5:
print("Dog")
else:
print("Cat")
|