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 keras | |
from keras.datasets import mnist | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Flatten | |
from keras.layers import Conv2D, MaxPooling2D | |
from keras.layers import Activation | |
from keras.optimizers import Adam | |
from keras.callbacks import TensorBoard | |
import time |
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
batch_size = 128 | |
num_classes = 10 | |
epochs = 10 | |
time = time.strftime("%Y_%m_%d_%H_%M_%S") |
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
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
x_train = x_train.reshape(60000,28,28,1) | |
x_test = x_test.reshape(10000,28,28,1) | |
x_train = x_train.astype('float32') | |
x_test = x_test.astype('float32') | |
x_train /= 255 | |
x_test /= 255 | |
print('x_train shape:', x_train.shape) | |
print(x_train.shape[0], 'train samples') |
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
model = Sequential() | |
model.add(Conv2D(32, (3,3), padding="same", input_shape=(28,28,1), activation= "relu")) | |
model.add(MaxPooling2D(pool_size=(3, 3))) | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(128, activation="relu")) | |
model.add(Dropout(0.5)) |
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
kerasboard = TensorBoard(log_dir="/tmp/tensorboard/{}".format(time), | |
batch_size=batch_size, | |
histogram_freq=1, | |
write_grads=False) |
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
model.compile(loss="categorical_crossentropy", | |
optimizer="adam", | |
metrics=['accuracy']) | |
model.fit(x_train, y_train, | |
batch_size=batch_size, | |
epochs=epochs, | |
validation_split=0.3, | |
validation_data=(x_test, y_test), | |
callbacks=[kerasboard]) |
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
# -*- coding: utf-8 -*- | |
""" | |
Deep Learning Türkiye topluluğu için Mert Çobanoğlu tarafından hazırlanmıştır. | |
Amaç: Keras ile nesne tanıma. | |
Algoritma: Evrişimli Sinir Ağları (Convolutional Neural Networks) | |
Ek: Çalışma ile ilgili rehber README.md dosyasında belirtilmiştir. | |
""" | |
from keras.applications.vgg16 import VGG16 |
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
from keras.applications.vgg16 import VGG16 | |
from keras.preprocessing import image | |
from keras.applications.vgg16 import preprocess_input, decode_predictions | |
import numpy as np |
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
model = VGG16(weights='imagenet') | |
img_path = 'images/bird.jpg' | |
img = image.load_img(img_path, target_size=(224, 224)) | |
x = image.img_to_array(img) | |
x = np.expand_dims(x, axis=0) | |
x = preprocess_input(x) |
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
preds = model.predict(x) | |
print('Predicted:', decode_predictions(preds, top=3)[0]) |
OlderNewer