<jupyter_start><jupyter_text><jupyter_code>%tensorflow_version 1.x
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Conv2D, MaxPooling2D, ZeroPadding2D
from keras.layers.normalization import BatchNormalization
from keras.regularizers import l2
from keras.datasets import cifar10, cifar100
from keras.optimizers import Adam
from keras.utils import to_categorical
import numpy as np

np.random.seed(1000)

(X_train10, Y_train10), (X_test10, Y_test10) = cifar10.load_data()
(X_train100, Y_train100), (X_test100, Y_test100) = cifar100.load_data()
alexnet = Sequential()

# Layer 1
alexnet.add(Conv2D(96, (11, 11), input_shape=(32, 32, 3),
  padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 2
alexnet.add(Conv2D(256, (5, 5), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 3
alexnet.add(Conv2D(512, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 4
alexnet.add(Conv2D(1024, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))

# Layer 5
alexnet.add(Conv2D(1024, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 6
alexnet.add(Flatten())
alexnet.add(Dense(4096))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(Dropout(0.5))

# Layer 7
alexnet.add(Dense(4096))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(Dropout(0.5))

# Layer 8
alexnet.add(Dense(100))
alexnet.add(BatchNormalization())
alexnet.add(Activation('softmax'))


alexnet.compile(loss='categorical_crossentropy',
              optimizer=Adam(lr=0.0001),
              metrics=['accuracy'])

alexnet.fit(X_train100 / 255.0, to_categorical(Y_train100),
          batch_size=128,
          shuffle=True,
          epochs=10,
          validation_data=(X_test100 / 255.0, to_categorical(Y_test100)))

scores = alexnet.evaluate(X_test100 / 255.0, to_categorical(Y_test100))

print('Loss: %.3f' % scores[0])
print('Accuracy: %.3f' % scores[1])


alexnet = Sequential()

# Layer 1
alexnet.add(Conv2D(96, (11, 11), input_shape=(32, 32, 3),
  padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 2
alexnet.add(Conv2D(256, (5, 5), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 3
alexnet.add(Conv2D(512, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 4
alexnet.add(Conv2D(1024, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))

# Layer 5
alexnet.add(Conv2D(1024, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 6
alexnet.add(Flatten())
alexnet.add(Dense(4096))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(Dropout(0.5))

# Layer 7
alexnet.add(Dense(4096))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(Dropout(0.5))

# Layer 8
alexnet.add(Dense(10))
alexnet.add(BatchNormalization())
alexnet.add(Activation('softmax'))


alexnet.compile(loss='categorical_crossentropy',
              optimizer=Adam(lr=0.0001),
              metrics=['accuracy'])

alexnet.fit(X_train10 / 255.0, to_categorical(Y_train10),
          batch_size=128,
          shuffle=True,
          epochs=10,
          validation_data=(X_test10 / 255.0, to_categorical(Y_test10)))

scores = alexnet.evaluate(X_test10 / 255.0, to_categorical(Y_test10))

print('Loss: %.3f' % scores[0])
print('Accuracy: %.3f' % scores[1])
# Initialize model
alexnet = Sequential()

# Layer 1
alexnet.add(Conv2D(96, (3, 3), input_shape=(32, 32, 3),
  padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 2
alexnet.add(Conv2D(256, (5, 5), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 3
alexnet.add(Conv2D(512, (3, 3), padding='same'))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(MaxPooling2D(pool_size=(2, 2)))

# Layer 6
alexnet.add(Flatten())
alexnet.add(Dense(4096))
alexnet.add(BatchNormalization())
alexnet.add(Activation('relu'))
alexnet.add(Dropout(0.5))

# Layer 8
alexnet.add(Dense(10))
alexnet.add(BatchNormalization())
alexnet.add(Activation('softmax'))


alexnet.compile(loss='categorical_crossentropy',
              optimizer=Adam(lr=0.0001),
              metrics=['accuracy'])

alexnet.fit(X_train10 / 255.0, to_categorical(Y_train10),
          batch_size=128,
          shuffle=True,
          epochs=10,
          validation_data=(X_test10 / 255.0, to_categorical(Y_test10)))

scores = alexnet.evaluate(X_test10 / 255.0, to_categorical(Y_test10))

print('Loss: %.3f' % scores[0])
print('Accuracy: %.3f' % scores[1])<jupyter_output>Train on 50000 samples, validate on 10000 samples
Epoch 1/10
50000/50000 [==============================] - 27s 534us/step - loss: 1.3169 - accuracy: 0.5859 - val_loss: 2.2067 - val_accuracy: 0.1740
Epoch 2/10
50000/50000 [==============================] - 25s 510us/step - loss: 1.0120 - accuracy: 0.7253 - val_loss: 1.1077 - val_accuracy: 0.6793
Epoch 3/10
50000/50000 [==============================] - 25s 504us/step - loss: 0.8556 - accuracy: 0.7955 - val_loss: 0.9913 - val_accuracy: 0.7199
Epoch 4/10
50000/50000 [==============================] - 25s 508us/step - loss: 0.7308 - accuracy: 0.8533 - val_loss: 0.9633 - val_accuracy: 0.7404
Epoch 5/10
50000/50000 [==============================] - 25s 505us/step - loss: 0.6178 - accuracy: 0.9032 - val_loss: 0.9118 - val_accuracy: 0.7470
Epoch 6/10
50000/50000 [==============================] - 25s 504us/step - loss: 0.5158 - accuracy: 0.9438 - val_loss: 0.9276 - val_accuracy: 0.7499
Epoch 7/10
50000/50000 [==============================] [...]
{'fraction_non_alphanumeric': 0.19489668127739512, 'fraction_numerical': 0.09376956793988729, 'mean_word_length': 5.732349841938883, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '269618', 'license': 'MIT', 'n_tokens_mistral': 2925, 'n_tokens_neox': 2420, 'n_words': 400, 'path': 'keras_cifar10_and_100.ipynb', 'repo_name': 'albertosire/keras-cifar10-test', 'size': '6388'}