Instructions to use kamangir/image-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use kamangir/image-classifier with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0. # See https://github.com/keras-team/tf-keras for more details. # !pip install "huggingface_hub<1.0" tf_keras from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("kamangir/image-classifier") - Notebooks
- Google Colab
- Kaggle
Download image_classifier/plot.py from kamangir/image-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/kamangir/image-classifier/resolve/main/image_classifier/plot.py
- Command line
-
hf download hf://kamangir/image-classifier/image_classifier/plot.py
-
curl -L -o plot.py https://huggingface.co/kamangir/image-classifier/resolve/main/image_classifier/plot.py
1.27 kB
| from abcli import string | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import abcli.logging | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| def plot_image(i, predictions_array, true_label, image, class_names): | |
| plt.grid(False) | |
| plt.xticks([]) | |
| plt.yticks([]) | |
| plt.imshow(image[i], cmap=plt.cm.binary) | |
| predicted_label = np.argmax(predictions_array) | |
| if true_label is None: | |
| color = "black" | |
| elif predicted_label == true_label[i]: | |
| color = "blue" | |
| else: | |
| color = "red" | |
| plt.xlabel( | |
| "{} {:2.0f}%{}".format( | |
| string.shorten(class_names[predicted_label]), | |
| 100 * np.max(predictions_array), | |
| "" | |
| if true_label is None | |
| else " ({})".format(string.shorten(class_names[true_label[i]])), | |
| ), | |
| color=color, | |
| ) | |
| def plot_value_array(i, predictions_array, true_label): | |
| plt.grid(False) | |
| plt.xticks(range(len(predictions_array))) | |
| plt.yticks([]) | |
| handle = plt.bar(range(len(predictions_array)), predictions_array, color="#777777") | |
| plt.ylim([0, 1]) | |
| predicted_label = np.argmax(predictions_array) | |
| handle[predicted_label].set_color("green") | |
| if true_label is not None: | |
| handle[true_label[i]].set_color("blue") | |