{"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 \nimport pandas as pd\nimport tensorflow as tf\nfrom tensorflow.keras import datasets,layers,models\nimport matplotlib.pyplot as plt\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":"2023-03-18T23:39:12.618175Z","iopub.execute_input":"2023-03-18T23:39:12.619446Z","iopub.status.idle":"2023-03-18T23:39:12.630251Z","shell.execute_reply.started":"2023-03-18T23:39:12.619396Z","shell.execute_reply":"2023-03-18T23:39:12.628878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(x_train,y_train),(x_test,y_test)=datasets.cifar10.load_data()","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:12.632410Z","iopub.execute_input":"2023-03-18T23:39:12.632739Z","iopub.status.idle":"2023-03-18T23:39:13.418590Z","shell.execute_reply.started":"2023-03-18T23:39:12.632709Z","shell.execute_reply":"2023-03-18T23:39:13.417338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train[:3]","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.420111Z","iopub.execute_input":"2023-03-18T23:39:13.420592Z","iopub.status.idle":"2023-03-18T23:39:13.429916Z","shell.execute_reply.started":"2023-03-18T23:39:13.420545Z","shell.execute_reply":"2023-03-18T23:39:13.428616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one-dimensional array\ny_test=y_test.reshape(-1,)\ny_test","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.431848Z","iopub.execute_input":"2023-03-18T23:39:13.432344Z","iopub.status.idle":"2023-03-18T23:39:13.441386Z","shell.execute_reply.started":"2023-03-18T23:39:13.432295Z","shell.execute_reply":"2023-03-18T23:39:13.440403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#examine data\nimg_classes=[\"airplane\",\"automobile\",\"bird\",\"cat\",\"deer\",\"dog\",\"frog\",\"horse\",\"ship\",\"truck\"]","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.443527Z","iopub.execute_input":"2023-03-18T23:39:13.444425Z","iopub.status.idle":"2023-03-18T23:39:13.452802Z","shell.execute_reply.started":"2023-03-18T23:39:13.444384Z","shell.execute_reply":"2023-03-18T23:39:13.451318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_sample(x,y,index):\n    plt.figure(figsize=(12,4))\n    plt.imshow(x[index])\n    plt.xlabel(img_classes[y[index]])","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.454522Z","iopub.execute_input":"2023-03-18T23:39:13.455137Z","iopub.status.idle":"2023-03-18T23:39:13.464357Z","shell.execute_reply.started":"2023-03-18T23:39:13.455052Z","shell.execute_reply":"2023-03-18T23:39:13.463169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_sample(x_test,y_test,13)","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.465990Z","iopub.execute_input":"2023-03-18T23:39:13.466438Z","iopub.status.idle":"2023-03-18T23:39:13.700945Z","shell.execute_reply.started":"2023-03-18T23:39:13.466404Z","shell.execute_reply":"2023-03-18T23:39:13.699319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_sample(x_test,y_test,12)","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.702471Z","iopub.execute_input":"2023-03-18T23:39:13.702829Z","iopub.status.idle":"2023-03-18T23:39:13.930466Z","shell.execute_reply.started":"2023-03-18T23:39:13.702794Z","shell.execute_reply":"2023-03-18T23:39:13.929032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#normalization\nx_train=x_train/255\nx_test=x_test/255","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:39:13.931788Z","iopub.execute_input":"2023-03-18T23:39:13.932125Z","iopub.status.idle":"2023-03-18T23:39:14.441660Z","shell.execute_reply.started":"2023-03-18T23:39:13.932078Z","shell.execute_reply":"2023-03-18T23:39:14.440606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#CNN\ndeep_lrng_model=models.Sequential([\n    layers.Conv2D(filters=32,kernel_size=(3,3),activation=\"relu\",input_shape=(32,32,3)),\n    layers.MaxPooling2D((2,2)),\n    \n    layers.Conv2D(filters=64,kernel_size=(3,3),activation=\"relu\"),\n    layers.MaxPooling2D((2,2)),\n    \n    layers.Flatten(),\n    layers.Dense(64,activation=\"relu\"),\n    layers.Dense(10,activation=\"softmax\")\n])","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:44:51.681370Z","iopub.execute_input":"2023-03-18T23:44:51.681782Z","iopub.status.idle":"2023-03-18T23:44:51.931157Z","shell.execute_reply.started":"2023-03-18T23:44:51.681747Z","shell.execute_reply":"2023-03-18T23:44:51.929895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"deep_lrng_model.compile(optimizer=\"adam\",loss=\"sparse_categorical_crossentropy\",metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:48:22.169333Z","iopub.execute_input":"2023-03-18T23:48:22.170223Z","iopub.status.idle":"2023-03-18T23:48:22.185737Z","shell.execute_reply.started":"2023-03-18T23:48:22.170178Z","shell.execute_reply":"2023-03-18T23:48:22.184168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"deep_lrng_model.fit(x_train,y_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2023-03-18T23:48:24.460869Z","iopub.execute_input":"2023-03-18T23:48:24.462136Z","iopub.status.idle":"2023-03-18T23:51:29.703707Z","shell.execute_reply.started":"2023-03-18T23:48:24.462053Z","shell.execute_reply":"2023-03-18T23:51:29.702643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"deep_lrng_model.evaluate(x_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:05:58.098239Z","iopub.execute_input":"2023-03-19T00:05:58.098633Z","iopub.status.idle":"2023-03-19T00:06:03.710551Z","shell.execute_reply.started":"2023-03-19T00:05:58.098599Z","shell.execute_reply":"2023-03-19T00:06:03.709192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=deep_lrng_model.predict(x_test)\ny_pred[:5]","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:07:50.982455Z","iopub.execute_input":"2023-03-19T00:07:50.983237Z","iopub.status.idle":"2023-03-19T00:07:54.094562Z","shell.execute_reply.started":"2023-03-19T00:07:50.983191Z","shell.execute_reply":"2023-03-19T00:07:54.093304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_class=[np.argmax(element) for element in y_pred]\ny_pred_class[:5]","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:08:59.091762Z","iopub.execute_input":"2023-03-19T00:08:59.092218Z","iopub.status.idle":"2023-03-19T00:08:59.122258Z","shell.execute_reply.started":"2023-03-19T00:08:59.092176Z","shell.execute_reply":"2023-03-19T00:08:59.120950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test[:5]","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:09:23.211625Z","iopub.execute_input":"2023-03-19T00:09:23.212058Z","iopub.status.idle":"2023-03-19T00:09:23.220242Z","shell.execute_reply.started":"2023-03-19T00:09:23.212018Z","shell.execute_reply":"2023-03-19T00:09:23.218930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_sample(x_test,y_test,13)","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:10:13.054509Z","iopub.execute_input":"2023-03-19T00:10:13.054913Z","iopub.status.idle":"2023-03-19T00:10:13.286382Z","shell.execute_reply.started":"2023-03-19T00:10:13.054871Z","shell.execute_reply":"2023-03-19T00:10:13.285314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_classes[y_pred_class[13]]","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:10:37.806759Z","iopub.execute_input":"2023-03-19T00:10:37.807458Z","iopub.status.idle":"2023-03-19T00:10:37.814336Z","shell.execute_reply.started":"2023-03-19T00:10:37.807414Z","shell.execute_reply":"2023-03-19T00:10:37.812860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_sample(x_test,y_test,12)","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:11:40.321461Z","iopub.execute_input":"2023-03-19T00:11:40.321905Z","iopub.status.idle":"2023-03-19T00:11:40.553540Z","shell.execute_reply.started":"2023-03-19T00:11:40.321863Z","shell.execute_reply":"2023-03-19T00:11:40.552131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_classes[y_pred_class[12]]","metadata":{"execution":{"iopub.status.busy":"2023-03-19T00:11:54.250479Z","iopub.execute_input":"2023-03-19T00:11:54.250902Z","iopub.status.idle":"2023-03-19T00:11:54.261373Z","shell.execute_reply.started":"2023-03-19T00:11:54.250867Z","shell.execute_reply":"2023-03-19T00:11:54.259498Z"},"trusted":true},"execution_count":null,"outputs":[]}]}