{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/jannes/anaconda/lib/python3.5/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", " from ._conv import register_converters as _register_converters\n", "Using TensorFlow backend.\n", "/Users/jannes/anaconda/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.6 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5\n", " return f(*args, **kwds)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Couldn't import dot_parser, loading of dot files will not be possible.\n" ] } ], "source": [ "from keras.datasets import mnist\n", "\n", "(x_train, y_train), (x_test, y_test) = mnist.load_data()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from keras.models import Sequential\n", "from keras.layers import Dense" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "x_train.shape = (60000, 28 * 28)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "x_test.shape = (10000, 28 * 28)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "x_train = x_train / 255\n", "x_test = x_test / 255" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "model = Sequential()\n", "model.add(Dense(512,activation='relu',input_dim= 28*28))\n", "model.add(Dense(512,activation='relu'))\n", "model.add(Dense(512,activation='relu'))\n", "model.add(Dense(10,activation='softmax'))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['acc'])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from keras.callbacks import TensorBoard" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "import tensorflow as tf\n", "from tensorflow.python import debug as tf_debug\n", "import keras\n", "\n", "keras.backend.set_session(\n", " tf_debug.TensorBoardDebugWrapperSession(tf.Session(), \"localhost:2018\"))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "tb = TensorBoard(log_dir='./logs/test2', \n", " histogram_freq=1, \n", " batch_size=32, \n", " write_graph=True, \n", " write_grads=True, \n", " write_images=True, \n", " embeddings_freq=0, \n", " embeddings_layer_names=None, \n", " embeddings_metadata=None)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Train on 60000 samples, validate on 10000 samples\n", "Epoch 1/5\n", "60000/60000 [==============================] - 9s 149us/step - loss: 13.4057 - acc: 0.1680 - val_loss: 14.2823 - val_acc: 0.1139\n", "Epoch 2/5\n", "60000/60000 [==============================] - 9s 144us/step - loss: 12.8723 - acc: 0.2014 - val_loss: 12.7043 - val_acc: 0.2118\n", "Epoch 3/5\n", "60000/60000 [==============================] - 8s 136us/step - loss: 12.7616 - acc: 0.2082 - val_loss: 12.7011 - val_acc: 0.2120\n", "Epoch 4/5\n", "60000/60000 [==============================] - 9s 150us/step - loss: 12.7532 - acc: 0.2088 - val_loss: 12.7011 - val_acc: 0.2120\n", "Epoch 5/5\n", "60000/60000 [==============================] - 9s 143us/step - loss: 13.8286 - acc: 0.1420 - val_loss: 14.2887 - val_acc: 0.1135\n" ] } ], "source": [ "hist = model.fit(x_train*255,y_train,\n", " batch_size=128,\n", " epochs=5,callbacks=[tb],\n", " validation_data=(x_test*255,y_test))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }