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
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from keras.models import load_model
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
|
| 6 |
+
# Load the model
|
| 7 |
+
model = load_model("model_img_pro.keras") # Update with your actual model path
|
| 8 |
+
|
| 9 |
+
# Function to preprocess the image
|
| 10 |
+
def preprocess_image(image_path, target_size):
|
| 11 |
+
# Load and resize the image
|
| 12 |
+
image = Image.open(image_path).convert('RGB')
|
| 13 |
+
image = image.resize(target_size)
|
| 14 |
+
|
| 15 |
+
# Convert image to array and normalize
|
| 16 |
+
image_array = np.array(image) / 255.0
|
| 17 |
+
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
|
| 18 |
+
|
| 19 |
+
return image_array
|
| 20 |
+
|
| 21 |
+
# Define target size based on your model
|
| 22 |
+
target_size = (224, 224) # Example size; update based on your model's expected input
|
| 23 |
+
|
| 24 |
+
# Path to the image you want to classify
|
| 25 |
+
image_path = "path_to_your_image.jpg" # Update with your image path
|
| 26 |
+
|
| 27 |
+
# Preprocess the image
|
| 28 |
+
processed_image = preprocess_image(image_path, target_size)
|
| 29 |
+
|
| 30 |
+
# Make predictions
|
| 31 |
+
predictions = model.predict(processed_image)
|
| 32 |
+
|
| 33 |
+
# Print the predictions
|
| 34 |
+
print(predictions)
|
| 35 |
+
|
| 36 |
+
# Optionally, decode the predictions if needed
|
| 37 |
+
# For binary classification (cat vs dog), you might have a single output neuron
|
| 38 |
+
# Example: if predictions[0][0] > 0.5, it's a dog; otherwise, it's a cat
|
| 39 |
+
if predictions[0][0] > 0.5:
|
| 40 |
+
print("Dog")
|
| 41 |
+
else:
|
| 42 |
+
print("Cat")
|