{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-25T15:13:08.868536Z","iopub.execute_input":"2022-03-25T15:13:08.86891Z","iopub.status.idle":"2022-03-25T15:13:08.909833Z","shell.execute_reply.started":"2022-03-25T15:13:08.868822Z","shell.execute_reply":"2022-03-25T15:13:08.908898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt                                    # Visualization\n\n\nimport tensorflow as tf                                            # It is the lovely tensorflow :) There is no need for any explaination <3\nfrom keras.models import Sequential \nfrom keras.layers import Conv2D\nfrom keras.layers import MaxPooling2D\nfrom keras.layers import Flatten\nfrom keras.layers import Dense\nfrom tensorflow.keras import datasets\nfrom tensorflow.keras.utils import to_categorical, plot_model","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:05.388886Z","iopub.execute_input":"2022-03-25T15:15:05.389216Z","iopub.status.idle":"2022-03-25T15:15:05.397943Z","shell.execute_reply.started":"2022-03-25T15:15:05.389152Z","shell.execute_reply":"2022-03-25T15:15:05.396861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lable=pd.read_csv('/kaggle/input/cifar-10/trainLabels.csv')\nsubmission=pd.read_csv('/kaggle/input/cifar-10/sampleSubmission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:05.827833Z","iopub.execute_input":"2022-03-25T15:15:05.828129Z","iopub.status.idle":"2022-03-25T15:15:05.90499Z","shell.execute_reply.started":"2022-03-25T15:15:05.828099Z","shell.execute_reply":"2022-03-25T15:15:05.903894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train, y_train), (X_test, y_test) = datasets.cifar10.load_data()\ny_train = to_categorical(y_train)\ny_test = to_categorical(y_test)\n\nX_train = X_train.astype('float32')\nX_test = X_test.astype('float32')","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:06.078318Z","iopub.execute_input":"2022-03-25T15:15:06.078567Z","iopub.status.idle":"2022-03-25T15:15:07.189193Z","shell.execute_reply.started":"2022-03-25T15:15:06.078537Z","shell.execute_reply":"2022-03-25T15:15:07.188226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train / 255.0\nX_test = X_test / 255.0\nclass_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',\n               'dog', 'frog', 'horse', 'ship', 'truck']\nclass_names = np.array(class_names)\n\nplt.figure(figsize=(10,10))\nfor i in range(25):\n    plt.subplot(5,5,i+1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.grid(False)\n    plt.imshow(X_train[i])\n    # The CIFAR labels happen to be arrays, \n    # which is why you need the extra index\n    plt.xlabel(class_names[y_train[i]==1])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:11.853081Z","iopub.execute_input":"2022-03-25T15:15:11.853481Z","iopub.status.idle":"2022-03-25T15:15:13.441707Z","shell.execute_reply.started":"2022-03-25T15:15:11.853452Z","shell.execute_reply":"2022-03-25T15:15:13.439257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train[0]\n","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:14.797788Z","iopub.execute_input":"2022-03-25T15:15:14.798101Z","iopub.status.idle":"2022-03-25T15:15:14.807781Z","shell.execute_reply.started":"2022-03-25T15:15:14.798053Z","shell.execute_reply":"2022-03-25T15:15:14.806305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:16.057623Z","iopub.execute_input":"2022-03-25T15:15:16.057906Z","iopub.status.idle":"2022-03-25T15:15:16.066533Z","shell.execute_reply.started":"2022-03-25T15:15:16.057876Z","shell.execute_reply":"2022-03-25T15:15:16.06523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:16.84839Z","iopub.execute_input":"2022-03-25T15:15:16.849108Z","iopub.status.idle":"2022-03-25T15:15:16.856992Z","shell.execute_reply.started":"2022-03-25T15:15:16.849061Z","shell.execute_reply":"2022-03-25T15:15:16.855954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:17.497969Z","iopub.execute_input":"2022-03-25T15:15:17.498895Z","iopub.status.idle":"2022-03-25T15:15:17.506137Z","shell.execute_reply.started":"2022-03-25T15:15:17.49886Z","shell.execute_reply":"2022-03-25T15:15:17.504996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:18.0576Z","iopub.execute_input":"2022-03-25T15:15:18.058435Z","iopub.status.idle":"2022-03-25T15:15:18.066417Z","shell.execute_reply.started":"2022-03-25T15:15:18.05839Z","shell.execute_reply":"2022-03-25T15:15:18.065327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lable.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:18.57737Z","iopub.execute_input":"2022-03-25T15:15:18.577618Z","iopub.status.idle":"2022-03-25T15:15:18.596218Z","shell.execute_reply.started":"2022-03-25T15:15:18.57759Z","shell.execute_reply":"2022-03-25T15:15:18.595235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:19.258301Z","iopub.execute_input":"2022-03-25T15:15:19.258594Z","iopub.status.idle":"2022-03-25T15:15:19.273995Z","shell.execute_reply.started":"2022-03-25T15:15:19.258563Z","shell.execute_reply":"2022-03-25T15:15:19.273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# CNN","metadata":{}},{"cell_type":"code","source":"classifier=Sequential()\n\nclassifier.add(Conv2D(32,(3,3),input_shape=(32,32,3),activation='relu'))\nclassifier.add(Conv2D(32,(3,3),activation='relu'))\n\nclassifier.add(MaxPooling2D(pool_size=(2,2)))\nclassifier.add(Conv2D(32,(3,3),activation='relu'))\nclassifier.add(MaxPooling2D(pool_size=(2,2)))\nclassifier.add(Conv2D(32,(3,3),activation='relu'))\nclassifier.add(MaxPooling2D(pool_size=(2,2)))\nclassifier.add(Flatten())\n\nclassifier.add(Dense(units=128,activation='relu'))\nclassifier.add(Dense(units=10,activation='softmax'))\nclassifier.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:20.387807Z","iopub.execute_input":"2022-03-25T15:15:20.388281Z","iopub.status.idle":"2022-03-25T15:15:23.612092Z","shell.execute_reply.started":"2022-03-25T15:15:20.388246Z","shell.execute_reply":"2022-03-25T15:15:23.611049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = classifier.fit(X_train, y_train, validation_data = (X_test, y_test),epochs=50, batch_size=64, verbose=1)","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:15:23.61436Z","iopub.execute_input":"2022-03-25T15:15:23.614709Z","iopub.status.idle":"2022-03-25T15:19:38.46722Z","shell.execute_reply.started":"2022-03-25T15:15:23.614662Z","shell.execute_reply":"2022-03-25T15:19:38.466241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_, accuracy = classifier.evaluate(X_test, y_test, verbose=0)\nprint('CNN model Accuracy trained and tested on all data: %.3f' % (accuracy * 100.0))","metadata":{"execution":{"iopub.status.busy":"2022-03-25T15:20:12.599151Z","iopub.execute_input":"2022-03-25T15:20:12.59947Z","iopub.status.idle":"2022-03-25T15:20:13.765747Z","shell.execute_reply.started":"2022-03-25T15:20:12.599436Z","shell.execute_reply":"2022-03-25T15:20:13.764695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}