├── .gitattributes ├── LICENSE ├── README.md └── kerasboard.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Mert Cobanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Keras-Tensorboard 2 | 3 | Bu repo tensorboard özelliklerini keras ile kullanmak için örnek çalışmalar içerir. 4 | 5 | ![Tensorboard Keras](https://media.giphy.com/media/1pA8T9iMWWnOg7Kuej/giphy.gif) 6 | 7 | ## Getting Started 8 | 9 | Oluşturulan bir yapay sinir ağında elde edilen parametreleri ve katmanların incelenmesi için kullanılan tensorboard'un keras ile nasıl çalıştırılacağı adına örnek bir proje. 10 | 11 | Ayrıca kapsamlı rehbere Deep Learning Türkiye Medium sayfasından ulaşabilirsiniz. 12 | [Rehber Linki](https://medium.com/deep-learning-turkiye/tensorboard-başlangıç-rehberi-198ea522b01) 13 | 14 | ### Prerequisites 15 | 16 | ``` 17 | Python 3.x.x 18 | TensorFlow 19 | Keras 20 | Numpy 21 | ``` 22 | 23 | ### Installing 24 | Gerekli kütüphaneler kurulduğunda komut satırı üzerinden `python kerasboard.py` komutu ile çalıştırılabilir. 25 | 26 | Model eğitimi tamamlandıktan sonra programın son çıktısı komut satırında çalıştırılarak tarayıcıda `localhost:6006` adresinde grafikler gözlenebilir. 27 | 28 | ![Kerasboard](https://media.giphy.com/media/7zxZ8mOddFwZvTZJoa/giphy.gif) 29 | 30 | ### Notes: 31 | Path error alındığı takdirde, C: dizini altında *tmp* adlı klasör oluşturun. 32 | 33 | ## Model: 34 | * Data: MNIST 35 | * Tür: ConvNet 36 | * Optimizer: Adam 37 | * Loss: Categorical Crossentropy 38 | 39 | ## Authors 40 | 41 | * **Mert Çobanoğlu** - [cobanov](https://github.com/cobanov) 42 | 43 | ## License 44 | 45 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details 46 | 47 | 48 | -------------------------------------------------------------------------------- /kerasboard.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Deep Learning Türkiye topluluğu için Mert Çobanoğlu tarafından hazırlanmıştır. 5 | Amaç: Keras ile TensorBoard kullanımı. 6 | Veriseti: MNIST (http://yann.lecun.com/exdb/mnist/) 7 | Algoritma: Evrişimli Sinir Ağları (Convolutional Neural Networks) 8 | Ek: Çalışma ile ilgili rehber README.md dosyasında belirtilmiştir. 9 | """ 10 | 11 | import keras 12 | from keras.datasets import mnist 13 | from keras.models import Sequential 14 | from keras.layers import Dense, Dropout, Flatten 15 | from keras.layers import Conv2D, MaxPooling2D 16 | from keras.layers import Activation 17 | from keras.optimizers import Adam 18 | from keras.callbacks import TensorBoard 19 | import time 20 | 21 | 22 | batch_size = 128 23 | num_classes = 10 24 | epochs = 10 25 | time = time.strftime("%Y_%m_%d_%H_%M_%S") 26 | 27 | (x_train, y_train), (x_test, y_test) = mnist.load_data() 28 | x_train = x_train.reshape(60000,28,28,1) 29 | x_test = x_test.reshape(10000,28,28,1) 30 | x_train = x_train.astype('float32') 31 | x_test = x_test.astype('float32') 32 | x_train /= 255 33 | x_test /= 255 34 | 35 | print('x_train shape:', x_train.shape) 36 | print(x_train.shape[0], 'train samples') 37 | print(x_test.shape[0], 'test samples') 38 | 39 | y_train = keras.utils.to_categorical(y_train, num_classes) 40 | y_test = keras.utils.to_categorical(y_test, num_classes) 41 | 42 | model = Sequential() 43 | 44 | model.add(Conv2D(32, (3,3), padding="same", input_shape=(28,28,1), activation= "relu")) 45 | model.add(MaxPooling2D(pool_size=(3, 3))) 46 | model.add(Dropout(0.25)) 47 | 48 | model.add(Flatten()) 49 | model.add(Dense(128, activation="relu")) 50 | model.add(Dropout(0.5)) 51 | 52 | model.add(Dense(num_classes, activation='softmax')) 53 | 54 | kerasboard = TensorBoard(log_dir="/tmp/tensorboard/{}".format(time), 55 | batch_size=batch_size, 56 | histogram_freq=1, 57 | write_grads=False) 58 | 59 | model.compile(loss="categorical_crossentropy", 60 | optimizer="adam", 61 | metrics=['accuracy']) 62 | 63 | model.fit(x_train, y_train, 64 | batch_size=batch_size, 65 | epochs=epochs, 66 | validation_split=0.3, 67 | validation_data=(x_test, y_test), 68 | callbacks=[kerasboard]) 69 | 70 | 71 | print("tensorboard --logdir="+kerasboard.log_dir) --------------------------------------------------------------------------------