File size: 1,522 Bytes
2ae4da2 b41d93e |
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 44 45 46 47 48 49 50 51 52 |
---
library_name: keras
tags:
- Image Classification
---
# Cifar-CNN (Teeny-Tiny Castle)
This model is part of a tutorial tied to the [Teeny-Tiny Castle](https://github.com/Nkluge-correa/TeenyTinyCastle), an open-source repository containing educational tools for AI Ethics and Safety research.
## How to Use
```python
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from huggingface_hub import from_pretrained_keras
# Download the CIFAR-10 dataset
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()
class_names = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer',
'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
plt.figure(figsize=[10, 10])
for i in range(25):
plt.subplot(5, 5, i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(x_test[i], cmap=plt.cm.binary)
plt.xlabel(class_names[y_test[i][0]])
plt.show()
# Load the model from the Hub
model = from_pretrained_keras("AiresPucrs/Cifar-CNN")
model.compile(
loss=tf.keras.losses.CategoricalCrossentropy(),
metrics=['categorical_accuracy']
)
x_train = x_train.astype('float32')
x_train = x_train / 255.
y_train = tf.keras.utils.to_categorical(y_train, 10)
x_test = x_test.astype('float32')
x_test = x_test / 255.
y_test = tf.keras.utils.to_categorical(y_test, 10)
test_loss_score, test_acc_score = model.evaluate(x_test, y_test, verbose=0)
model.summary()
print(f'Loss: {round(test_loss_score, 2)}.')
print(f'Accuracy: {round(test_acc_score * 100, 2)} %.')
```
|