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
Download app.py from nxtdev/CDC-Processing: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/nxtdev/CDC-Processing/resolve/949bf24deb614ef542faa43e52838d4f8b972b46/app.py
- Command line
-
hf download hf://nxtdev/CDC-Processing@949bf24deb614ef542faa43e52838d4f8b972b46/app.py
-
curl -L -o app.py https://huggingface.co/nxtdev/CDC-Processing/resolve/949bf24deb614ef542faa43e52838d4f8b972b46/app.py
1.3 kB
| 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") | |