Last active
August 19, 2019 15:40
-
-
Save ground0state/44ef3d13ae4e0cf02d2cfe864c685007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import keras | |
from tensorflow.python.keras.datasets import cifar10 | |
from tensorflow.python.keras.utils import to_categorical | |
from tensorflow.python.keras.models import Sequential | |
from tensorflow.python.keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense | |
from tensorflow.python.keras.callbacks import TensorBoard | |
(x_train, y_train), (x_test, y_test) = cifar10.load_data() | |
x_train = x_train/255 | |
x_test = x_test/255 | |
y_train = to_categorical(y_train, 10) | |
y_test = to_categorical(y_test, 10) | |
model = Sequential() | |
model.add(Conv2D(filters=32, input_shape=(32,32,3), kernel_size=(3,3), strides=(1,1), padding='same', activation='relu')) | |
model.add(Conv2D(filters=32, kernel_size=(3,3), strides=(1,1), padding='same', activation='relu')) | |
model.add(MaxPooling2D(pool_size=(2,2))) | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(filters=64, kernel_size=(3,3), strides=(1,1), padding='same', activation='relu')) | |
model.add(Conv2D(filters=64, kernel_size=(3,3), strides=(1,1), padding='same', activation='relu')) | |
model.add(MaxPooling2D(pool_size=(2,2))) | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(units=512, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(units=10, activation='softmax')) | |
model.compile( | |
optimizer='adam', | |
loss='categorical_crossentropy', | |
metrics=['accuracy'] | |
) | |
tsb = TensorBoard(log_dir='./logs') | |
history_model1 = model.fit( | |
x_train, | |
y_train, | |
batch_size=32, | |
epochs=20, | |
validation_split=0.2, | |
callbacks=[tsb] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment