diff --git a/Framework/Keras/Keras Assingment/YugalJain_ModelwithLogs.ipynb b/Framework/Keras/Keras Assingment/YugalJain_ModelwithLogs.ipynb new file mode 100644 index 0000000..2fa06e8 --- /dev/null +++ b/Framework/Keras/Keras Assingment/YugalJain_ModelwithLogs.ipynb @@ -0,0 +1,173 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\PC\\Anaconda3\\envs\\python35\\lib\\site-packages\\h5py\\__init__.py:36: 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" + ] + } + ], + "source": [ + "import keras\n", + "from keras import optimizers\n", + "from keras.models import Sequential\n", + "model=Sequential()\n", + "from keras.datasets import mnist\n", + "(x_train,y_train),(x_test,y_test)=mnist.load_data()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "x_train=keras.utils.normalize(x_train,axis=1)\n", + "x_test=keras.utils.normalize(x_test,axis=1)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "Error when checking target: expected dense_8 to have shape (10,) but got array with shape (1,)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 8\u001b[0m metrics=['accuracy'])\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx_train\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my_train\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mepochs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbatch_size\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m32\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mverbose\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\envs\\python35\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)\u001b[0m\n\u001b[0;32m 950\u001b[0m \u001b[0msample_weight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 951\u001b[0m \u001b[0mclass_weight\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mclass_weight\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 952\u001b[1;33m batch_size=batch_size)\n\u001b[0m\u001b[0;32m 953\u001b[0m \u001b[1;31m# Prepare validation data.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 954\u001b[0m \u001b[0mdo_validation\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\envs\\python35\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36m_standardize_user_data\u001b[1;34m(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)\u001b[0m\n\u001b[0;32m 787\u001b[0m \u001b[0mfeed_output_shapes\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 788\u001b[0m \u001b[0mcheck_batch_axis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;31m# Don't enforce the batch size.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 789\u001b[1;33m exception_prefix='target')\n\u001b[0m\u001b[0;32m 790\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 791\u001b[0m \u001b[1;31m# Generate sample-wise weight values given the `sample_weight` and\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\envs\\python35\\lib\\site-packages\\keras\\engine\\training_utils.py\u001b[0m in \u001b[0;36mstandardize_input_data\u001b[1;34m(data, names, shapes, check_batch_axis, exception_prefix)\u001b[0m\n\u001b[0;32m 136\u001b[0m \u001b[1;34m': expected '\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mnames\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' to have shape '\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 137\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' but got array with shape '\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 138\u001b[1;33m str(data_shape))\n\u001b[0m\u001b[0;32m 139\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 140\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: Error when checking target: expected dense_8 to have shape (10,) but got array with shape (1,)" + ] + } + ], + "source": [ + "from keras.layers import Dense,Flatten\n", + "model=Sequential()\n", + "model.add(Flatten())\n", + "model.add(Dense(512,activation='relu'))\n", + "model.add(Dense(10,activation='softmax'))\n", + "model.compile(optimizer='rmsprop',\n", + " loss='',\n", + " metrics=['accuracy'])\n", + "\n", + "model.fit(x_train,y_train,epochs=10,batch_size=32,verbose=1)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Framework/Keras/Keras Assingment/YugalJain_ModelwithLogs/YugalJain_ModelwithLogs.ipynb b/Framework/Keras/Keras Assingment/YugalJain_ModelwithLogs/YugalJain_ModelwithLogs.ipynb new file mode 100644 index 0000000..43a1501 --- /dev/null +++ b/Framework/Keras/Keras Assingment/YugalJain_ModelwithLogs/YugalJain_ModelwithLogs.ipynb @@ -0,0 +1,335 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "YugalJain_ModelwithLogs.ipynb", + "version": "0.3.2", + "provenance": [], + "collapsed_sections": [] + }, + "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.5" + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } + }, + "cells": [ + { + "cell_type": "code", + "metadata": { + "id": "FToxEB5V9y6b", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "acf96764-bb8f-48e6-97ef-3dc50522cca0" + }, + "source": [ + "import keras\n", + "from keras import optimizers\n", + "from keras.models import Sequential\n", + "from keras.datasets import mnist\n", + "(x_train,y_train),(x_test,y_test)=mnist.load_data()\n" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Using TensorFlow backend.\n" + ], + "name": "stderr" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "HxzF9klN9y6v", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Normalizing input training and testing data\n", + "x_train=keras.utils.normalize(x_train,axis=1)\n", + "x_test=keras.utils.normalize(x_test,axis=1)\n", + "\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "uPZNHmtx9y7K", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "tOeoupjs9y7R", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 666 + }, + "outputId": "8e1596be-196b-427a-9ad6-61ea2978c52a" + }, + "source": [ + "from keras.layers import Dense,Flatten\n", + "# Creating an instance for sequential model\n", + "model=Sequential()\n", + "\n", + "# Adding flatten layer to convert 28*28 pixels into an array of size 784\n", + "model.add(Flatten())\n", + "\n", + "# Adding hidden dense layer of 512 units and relu activation function \n", + "model.add(Dense(512,activation='relu'))\n", + "\n", + "# Adding dense layer of 10 units with softmax activation function\n", + "\n", + "model.add(Dense(10,activation='softmax'))\n", + "\n", + "# Compiling our model with sgd as optimizer\n", + "model.compile(optimizer='sgd',\n", + " loss='sparse_categorical_crossentropy',\n", + " metrics=['accuracy'])\n", + "\n", + "model.fit(x_train,y_train,epochs=10,batch_size=32,verbose=1)\n", + "\n", + "\n" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "WARNING: Logging before flag parsing goes to stderr.\n", + "W0713 11:02:35.218778 140436485834624 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n", + "\n", + "W0713 11:02:35.246967 140436485834624 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n", + "\n", + "W0713 11:02:35.268220 140436485834624 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n", + "\n", + "W0713 11:02:35.281612 140436485834624 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.\n", + "\n", + "W0713 11:02:35.316654 140436485834624 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3341: The name tf.log is deprecated. Please use tf.math.log instead.\n", + "\n", + "W0713 11:02:35.408233 140436485834624 deprecation.py:323] From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_grad.py:1250: add_dispatch_support..wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use tf.where in 2.0, which has the same broadcast rule as np.where\n", + "W0713 11:02:35.438150 140436485834624 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:986: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.\n", + "\n" + ], + "name": "stderr" + }, + { + "output_type": "stream", + "text": [ + "Epoch 1/10\n", + "60000/60000 [==============================] - 11s 183us/step - loss: 1.0670 - acc: 0.7842\n", + "Epoch 2/10\n", + "60000/60000 [==============================] - 10s 174us/step - loss: 0.4594 - acc: 0.8799\n", + "Epoch 3/10\n", + "60000/60000 [==============================] - 10s 171us/step - loss: 0.3753 - acc: 0.8968\n", + "Epoch 4/10\n", + "60000/60000 [==============================] - 10s 169us/step - loss: 0.3370 - acc: 0.9049\n", + "Epoch 5/10\n", + "60000/60000 [==============================] - 11s 179us/step - loss: 0.3123 - acc: 0.9118\n", + "Epoch 6/10\n", + "60000/60000 [==============================] - 11s 177us/step - loss: 0.2939 - acc: 0.9176\n", + "Epoch 7/10\n", + "60000/60000 [==============================] - 10s 172us/step - loss: 0.2789 - acc: 0.9222\n", + "Epoch 8/10\n", + "60000/60000 [==============================] - 10s 171us/step - loss: 0.2658 - acc: 0.9258\n", + "Epoch 9/10\n", + "60000/60000 [==============================] - 11s 176us/step - loss: 0.2545 - acc: 0.9286\n", + "Epoch 10/10\n", + "60000/60000 [==============================] - 11s 176us/step - loss: 0.2442 - acc: 0.9315\n" + ], + "name": "stdout" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 4 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Gcdf7QL69y7g", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "outputId": "cad2aee7-ea1a-4d7d-95cb-ee3389d06be1" + }, + "source": [ + "#Evaluating the model on test dataset\n", + "loss, acc = model.evaluate(x_test, y_test)\n", + "print(\"Loss: \" + str(loss))\n", + "print(\"Accuarcy: \" + str(100*acc) + \"%\")" + ], + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "text": [ + "10000/10000 [==============================] - 1s 61us/step\n", + "Loss: 0.23936950590610503\n", + "Accuarcy: 93.24%\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "4EzjH1Cc9y7q", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "sRPmEoDz9y72", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "tEWCSqMO9y7-", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "gkwcYtzo9y8J", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "Po1HrIxd9y8Y", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "1LA6Q5GT9y8k", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "grys8Ui19y81", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nHRTV2409y89", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "UjHaC1Wh9y9J", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +}