Cifar-CNN (Teeny-Tiny Castle)
This model is part of a tutorial tied to the Teeny-Tiny Castle, an open-source repository containing educational tools for AI Ethics and Safety research.
How to Use
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)} %.')
- Downloads last month
- 0