nicholasKluge commited on
Commit
c1f9c13
·
verified ·
1 Parent(s): d331be9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -38
README.md CHANGED
@@ -4,41 +4,50 @@ tags:
4
  - Image Classification
5
  ---
6
 
7
- ## Model description
8
-
9
- More information needed
10
-
11
- ## Intended uses & limitations
12
-
13
- More information needed
14
-
15
- ## Training and evaluation data
16
-
17
- More information needed
18
-
19
- ## Training procedure
20
-
21
- ### Training hyperparameters
22
-
23
- The following hyperparameters were used during training:
24
-
25
- | Hyperparameters | Value |
26
- | :-- | :-- |
27
- | name | Adam |
28
- | learning_rate | 0.0010000000474974513 |
29
- | decay | 0.0 |
30
- | beta_1 | 0.8999999761581421 |
31
- | beta_2 | 0.9990000128746033 |
32
- | epsilon | 1e-07 |
33
- | amsgrad | False |
34
- | training_precision | float32 |
35
-
36
-
37
- ## Model Plot
38
-
39
- <details>
40
- <summary>View Model Plot</summary>
41
-
42
- ![Model Image](./model.png)
43
-
44
- </details>
 
 
 
 
 
 
 
 
 
 
4
  - Image Classification
5
  ---
6
 
7
+ # Cifar CNN with Adversarial Training (Teeny-Tiny Castle)
8
+
9
+ 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.
10
+
11
+ ## How to Use
12
+
13
+ ```python
14
+ !pip install huggingface_hub["tensorflow"] -q
15
+ import numpy as np
16
+ import tensorflow as tf
17
+ import matplotlib.pyplot as plt
18
+ from huggingface_hub import from_pretrained_keras
19
+
20
+ # Download the CIFAR-10 dataset
21
+ (x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()
22
+
23
+ class_names = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer',
24
+ 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
25
+
26
+ plt.figure(figsize=[10, 10])
27
+ for i in range(25):
28
+ plt.subplot(5, 5, i+1)
29
+ plt.xticks([])
30
+ plt.yticks([])
31
+ plt.grid(False)
32
+ plt.imshow(x_test[i], cmap=plt.cm.binary)
33
+ plt.xlabel(class_names[y_test[i][0]])
34
+
35
+ plt.show()
36
+
37
+ # Load the model from the Hub
38
+ model = from_pretrained_keras("AiresPucrs/Cifar-CNN-with-adversarial-training")
39
+ model.compile(
40
+ loss=tf.keras.losses.CategoricalCrossentropy(),
41
+ metrics=['categorical_accuracy']
42
+ )
43
+ x_train = x_train.astype('float32')
44
+ x_train = x_train / 255.
45
+ y_train = tf.keras.utils.to_categorical(y_train, 10)
46
+ x_test = x_test.astype('float32')
47
+ x_test = x_test / 255.
48
+ y_test = tf.keras.utils.to_categorical(y_test, 10)
49
+ test_loss_score, test_acc_score = model.evaluate(x_test, y_test, verbose=0)
50
+ model.summary()
51
+ print(f'Loss: {round(test_loss_score, 2)}.')
52
+ print(f'Accuracy: {round(test_acc_score * 100, 2)} %.')
53
+ ```