Instructions to use lizardwine/DigitClassifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use lizardwine/DigitClassifier with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://lizardwine/DigitClassifier") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -15,6 +15,8 @@ license: apache-2.0
|
|
| 15 |
|
| 16 |
🎯 **Purpose:** To classify handwritten digits from images with high accuracy
|
| 17 |
|
|
|
|
|
|
|
| 18 |
---
|
| 19 |
|
| 20 |
## 📚 Description
|
|
@@ -78,6 +80,80 @@ This model is designed to recognize handwritten digits from 0 to 9. It processes
|
|
| 78 |
1. **Preprocess the Image:** Resize and normalize the image to 28x28 pixels with values between 0 and 1.
|
| 79 |
2. **Feed the Image:** Input the preprocessed image into the model.
|
| 80 |
3. **Interpret the Output:** Analyze the 10-dimensional output vector to find the digit with the highest probability.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
---
|
| 83 |
|
|
|
|
| 15 |
|
| 16 |
🎯 **Purpose:** To classify handwritten digits from images with high accuracy
|
| 17 |
|
| 18 |
+
☁️ **Download:** [Click here](https://huggingface.co/lizardwine/DigitClassifier/resolve/main/DigitClassifier.keras?download=true) to download
|
| 19 |
+
|
| 20 |
---
|
| 21 |
|
| 22 |
## 📚 Description
|
|
|
|
| 80 |
1. **Preprocess the Image:** Resize and normalize the image to 28x28 pixels with values between 0 and 1.
|
| 81 |
2. **Feed the Image:** Input the preprocessed image into the model.
|
| 82 |
3. **Interpret the Output:** Analyze the 10-dimensional output vector to find the digit with the highest probability.
|
| 83 |
+
### Loading the Model
|
| 84 |
+
|
| 85 |
+
To use the model, first, load it using Keras.
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
from keras.models import load_model
|
| 89 |
+
|
| 90 |
+
# Load the pre-trained model
|
| 91 |
+
model = load_model('path/to/DigitClassifier.keras')
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Preprocessing the Input
|
| 95 |
+
|
| 96 |
+
Preprocess the input image to fit the model's requirements.
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
import numpy as np
|
| 100 |
+
from keras.preprocessing import image
|
| 101 |
+
|
| 102 |
+
def preprocess_image(img_path):
|
| 103 |
+
# Load the image
|
| 104 |
+
img = image.load_img(img_path, color_mode='grayscale', target_size=(28, 28))
|
| 105 |
+
# Convert to numpy array
|
| 106 |
+
img_array = image.img_to_array(img)
|
| 107 |
+
# Normalize the image
|
| 108 |
+
img_array = img_array / 255.0
|
| 109 |
+
# Reshape to add batch dimension
|
| 110 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 111 |
+
return img_array
|
| 112 |
+
|
| 113 |
+
# Example usage
|
| 114 |
+
img_path = 'path/to/your/image.png'
|
| 115 |
+
processed_image = preprocess_image(img_path)
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
### Making Predictions
|
| 119 |
+
|
| 120 |
+
Use the model to predict the digit from the processed image.
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
# Predict the digit
|
| 124 |
+
predictions = model.predict(processed_image)
|
| 125 |
+
|
| 126 |
+
# Get the digit with the highest probability
|
| 127 |
+
predicted_digit = np.argmax(predictions)
|
| 128 |
+
print(f'The predicted digit is: {predicted_digit}')
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### Full Example
|
| 132 |
+
|
| 133 |
+
Combining all steps into a single example.
|
| 134 |
+
|
| 135 |
+
```python
|
| 136 |
+
from keras.models import load_model
|
| 137 |
+
from keras.preprocessing import image
|
| 138 |
+
import numpy as np
|
| 139 |
+
|
| 140 |
+
# Load the pre-trained model
|
| 141 |
+
model = load_model('path/to/DigitClassifier.keras')
|
| 142 |
+
|
| 143 |
+
def preprocess_image(img_path):
|
| 144 |
+
img = image.load_img(img_path, color_mode='grayscale', target_size=(28, 28))
|
| 145 |
+
img_array = image.img_to_array(img)
|
| 146 |
+
img_array = img_array / 255.0
|
| 147 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 148 |
+
return img_array
|
| 149 |
+
|
| 150 |
+
img_path = 'path/to/your/image.png'
|
| 151 |
+
processed_image = preprocess_image(img_path)
|
| 152 |
+
|
| 153 |
+
predictions = model.predict(processed_image)
|
| 154 |
+
predicted_digit = np.argmax(predictions)
|
| 155 |
+
print(f'The predicted digit is: {predicted_digit}')
|
| 156 |
+
```
|
| 157 |
|
| 158 |
---
|
| 159 |
|