{"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-11-02T21:51:38.099656Z","iopub.execute_input":"2022-11-02T21:51:38.100071Z","iopub.status.idle":"2022-11-02T21:51:38.126719Z","shell.execute_reply.started":"2022-11-02T21:51:38.099983Z","shell.execute_reply":"2022-11-02T21:51:38.125861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.datasets import cifar10","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:17:20.959305Z","iopub.execute_input":"2022-11-02T22:17:20.960195Z","iopub.status.idle":"2022-11-02T22:17:26.197472Z","shell.execute_reply.started":"2022-11-02T22:17:20.960158Z","shell.execute_reply":"2022-11-02T22:17:26.196469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train,y_train) , (X_test, y_test) = cifar10.load_data()","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:17:31.623690Z","iopub.execute_input":"2022-11-02T22:17:31.624296Z","iopub.status.idle":"2022-11-02T22:17:39.777104Z","shell.execute_reply.started":"2022-11-02T22:17:31.624233Z","shell.execute_reply":"2022-11-02T22:17:39.775943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:17:44.424522Z","iopub.execute_input":"2022-11-02T22:17:44.424990Z","iopub.status.idle":"2022-11-02T22:17:44.442203Z","shell.execute_reply.started":"2022-11-02T22:17:44.424943Z","shell.execute_reply":"2022-11-02T22:17:44.441110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train[0]","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:18:00.859083Z","iopub.execute_input":"2022-11-02T22:18:00.859773Z","iopub.status.idle":"2022-11-02T22:18:00.868794Z","shell.execute_reply.started":"2022-11-02T22:18:00.859736Z","shell.execute_reply":"2022-11-02T22:18:00.867882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train[0].shape","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:18:15.145377Z","iopub.execute_input":"2022-11-02T22:18:15.145757Z","iopub.status.idle":"2022-11-02T22:18:15.154891Z","shell.execute_reply.started":"2022-11-02T22:18:15.145724Z","shell.execute_reply":"2022-11-02T22:18:15.153864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(X_train[0])","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:18:30.163186Z","iopub.execute_input":"2022-11-02T22:18:30.163622Z","iopub.status.idle":"2022-11-02T22:18:30.391049Z","shell.execute_reply.started":"2022-11-02T22:18:30.163586Z","shell.execute_reply":"2022-11-02T22:18:30.390107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(X_train[12])","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:18:34.592046Z","iopub.execute_input":"2022-11-02T22:18:34.592435Z","iopub.status.idle":"2022-11-02T22:18:34.803878Z","shell.execute_reply.started":"2022-11-02T22:18:34.592402Z","shell.execute_reply":"2022-11-02T22:18:34.803002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train/255","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:18:46.201566Z","iopub.execute_input":"2022-11-02T22:18:46.202126Z","iopub.status.idle":"2022-11-02T22:18:46.679600Z","shell.execute_reply.started":"2022-11-02T22:18:46.202076Z","shell.execute_reply":"2022-11-02T22:18:46.678529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = X_test/255","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:18:55.973678Z","iopub.execute_input":"2022-11-02T22:18:55.974048Z","iopub.status.idle":"2022-11-02T22:18:56.060072Z","shell.execute_reply.started":"2022-11-02T22:18:55.974016Z","shell.execute_reply":"2022-11-02T22:18:56.059084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.utils import to_categorical","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:19:04.401621Z","iopub.execute_input":"2022-11-02T22:19:04.401978Z","iopub.status.idle":"2022-11-02T22:19:04.408160Z","shell.execute_reply.started":"2022-11-02T22:19:04.401947Z","shell.execute_reply":"2022-11-02T22:19:04.407053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_cat_train  = to_categorical(y_train, 10)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:19:12.857117Z","iopub.execute_input":"2022-11-02T22:19:12.857898Z","iopub.status.idle":"2022-11-02T22:19:12.864786Z","shell.execute_reply.started":"2022-11-02T22:19:12.857861Z","shell.execute_reply":"2022-11-02T22:19:12.863607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_cat_test = to_categorical(y_test, 10)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:19:25.836170Z","iopub.execute_input":"2022-11-02T22:19:25.837315Z","iopub.status.idle":"2022-11-02T22:19:25.842047Z","shell.execute_reply.started":"2022-11-02T22:19:25.837269Z","shell.execute_reply":"2022-11-02T22:19:25.841054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:19:33.687837Z","iopub.execute_input":"2022-11-02T22:19:33.688198Z","iopub.status.idle":"2022-11-02T22:19:33.696192Z","shell.execute_reply.started":"2022-11-02T22:19:33.688168Z","shell.execute_reply":"2022-11-02T22:19:33.694967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, Flatten","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:19:41.337604Z","iopub.execute_input":"2022-11-02T22:19:41.338077Z","iopub.status.idle":"2022-11-02T22:19:41.345457Z","shell.execute_reply.started":"2022-11-02T22:19:41.338028Z","shell.execute_reply":"2022-11-02T22:19:41.344575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\n\nmodel.add(Conv2D(filters = 32, kernel_size = (4,4), input_shape = (32, 32, 3), activation = \"relu\"))\nmodel.add(MaxPool2D(pool_size = (2,2)))\n\nmodel.add(Conv2D(filters = 64, kernel_size = (4,4), input_shape = (32, 32, 3), activation = \"relu\"))\nmodel.add(MaxPool2D(pool_size = (2,2)))\n\nmodel.add(Flatten())\n\nmodel.add(Dense(512, activation = \"relu\"))\nmodel.add(Dense(256, activation = \"relu\"))\nmodel.add(Dense(128, activation = \"relu\"))\n\nmodel.add(Dense(10, activation = \"softmax\"))\n\nmodel.compile(loss = \"categorical_crossentropy\", optimizer = \"adam\", metrics = [\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:19:57.301127Z","iopub.execute_input":"2022-11-02T22:19:57.301822Z","iopub.status.idle":"2022-11-02T22:20:00.701562Z","shell.execute_reply.started":"2022-11-02T22:19:57.301785Z","shell.execute_reply":"2022-11-02T22:20:00.700556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:20:12.620384Z","iopub.execute_input":"2022-11-02T22:20:12.620772Z","iopub.status.idle":"2022-11-02T22:20:12.628787Z","shell.execute_reply.started":"2022-11-02T22:20:12.620743Z","shell.execute_reply":"2022-11-02T22:20:12.627647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.callbacks import EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:20:25.905426Z","iopub.execute_input":"2022-11-02T22:20:25.906236Z","iopub.status.idle":"2022-11-02T22:20:25.912902Z","shell.execute_reply.started":"2022-11-02T22:20:25.906201Z","shell.execute_reply":"2022-11-02T22:20:25.911557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stop = EarlyStopping(monitor = \"val_loss\", patience = 2)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:20:40.613111Z","iopub.execute_input":"2022-11-02T22:20:40.614060Z","iopub.status.idle":"2022-11-02T22:20:40.618960Z","shell.execute_reply.started":"2022-11-02T22:20:40.614022Z","shell.execute_reply":"2022-11-02T22:20:40.617631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train, y_cat_train, validation_data = (X_test, y_cat_test), epochs = 15, callbacks = [early_stop])","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:20:52.084341Z","iopub.execute_input":"2022-11-02T22:20:52.084729Z","iopub.status.idle":"2022-11-02T22:21:38.174883Z","shell.execute_reply.started":"2022-11-02T22:20:52.084694Z","shell.execute_reply":"2022-11-02T22:21:38.173966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics = pd.DataFrame(model.history.history)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:22:20.381043Z","iopub.execute_input":"2022-11-02T22:22:20.381450Z","iopub.status.idle":"2022-11-02T22:22:20.390923Z","shell.execute_reply.started":"2022-11-02T22:22:20.381417Z","shell.execute_reply":"2022-11-02T22:22:20.389918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:22:28.278659Z","iopub.execute_input":"2022-11-02T22:22:28.279027Z","iopub.status.idle":"2022-11-02T22:22:28.300322Z","shell.execute_reply.started":"2022-11-02T22:22:28.278988Z","shell.execute_reply":"2022-11-02T22:22:28.298183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics.columns","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:22:39.190086Z","iopub.execute_input":"2022-11-02T22:22:39.190978Z","iopub.status.idle":"2022-11-02T22:22:39.202323Z","shell.execute_reply.started":"2022-11-02T22:22:39.190935Z","shell.execute_reply":"2022-11-02T22:22:39.201338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics[[\"accuracy\", \"val_accuracy\"]].plot()","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:22:46.602779Z","iopub.execute_input":"2022-11-02T22:22:46.603179Z","iopub.status.idle":"2022-11-02T22:23:16.631159Z","shell.execute_reply.started":"2022-11-02T22:22:46.603144Z","shell.execute_reply":"2022-11-02T22:23:16.630196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics[[\"loss\", \"val_loss\"]].plot()","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:23:16.633288Z","iopub.execute_input":"2022-11-02T22:23:16.633669Z","iopub.status.idle":"2022-11-02T22:23:16.845232Z","shell.execute_reply.started":"2022-11-02T22:23:16.633631Z","shell.execute_reply":"2022-11-02T22:23:16.844196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(X_test, y_cat_test, verbose = 1)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:23:16.846439Z","iopub.execute_input":"2022-11-02T22:23:16.846786Z","iopub.status.idle":"2022-11-02T22:23:18.073128Z","shell.execute_reply.started":"2022-11-02T22:23:16.846750Z","shell.execute_reply":"2022-11-02T22:23:18.072188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report, confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:23:28.781401Z","iopub.execute_input":"2022-11-02T22:23:28.781767Z","iopub.status.idle":"2022-11-02T22:23:29.058268Z","shell.execute_reply.started":"2022-11-02T22:23:28.781736Z","shell.execute_reply":"2022-11-02T22:23:29.057310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict_x=model.predict(X_test) \nclasses_x=np.argmax(predict_x,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:23:39.004293Z","iopub.execute_input":"2022-11-02T22:23:39.004661Z","iopub.status.idle":"2022-11-02T22:23:40.108093Z","shell.execute_reply.started":"2022-11-02T22:23:39.004630Z","shell.execute_reply":"2022-11-02T22:23:40.106767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_test, classes_x))","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:23:48.386626Z","iopub.execute_input":"2022-11-02T22:23:48.386996Z","iopub.status.idle":"2022-11-02T22:23:48.417587Z","shell.execute_reply.started":"2022-11-02T22:23:48.386964Z","shell.execute_reply":"2022-11-02T22:23:48.416569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix(y_test, classes_x)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:00.696106Z","iopub.execute_input":"2022-11-02T22:24:00.696788Z","iopub.status.idle":"2022-11-02T22:24:00.707556Z","shell.execute_reply.started":"2022-11-02T22:24:00.696751Z","shell.execute_reply":"2022-11-02T22:24:00.706309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nplt.figure(figsize = (10, 6))\nsns.heatmap(confusion_matrix(y_test, classes_x), annot = True)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:11.288779Z","iopub.execute_input":"2022-11-02T22:24:11.289132Z","iopub.status.idle":"2022-11-02T22:24:12.460149Z","shell.execute_reply.started":"2022-11-02T22:24:11.289100Z","shell.execute_reply":"2022-11-02T22:24:12.459299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_image = X_test[0]","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:21.425038Z","iopub.execute_input":"2022-11-02T22:24:21.425419Z","iopub.status.idle":"2022-11-02T22:24:21.430773Z","shell.execute_reply.started":"2022-11-02T22:24:21.425388Z","shell.execute_reply":"2022-11-02T22:24:21.429519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_image","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:28.156691Z","iopub.execute_input":"2022-11-02T22:24:28.157144Z","iopub.status.idle":"2022-11-02T22:24:28.166094Z","shell.execute_reply.started":"2022-11-02T22:24:28.157110Z","shell.execute_reply":"2022-11-02T22:24:28.165139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(my_image)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:37.493841Z","iopub.execute_input":"2022-11-02T22:24:37.494200Z","iopub.status.idle":"2022-11-02T22:24:37.698903Z","shell.execute_reply.started":"2022-11-02T22:24:37.494169Z","shell.execute_reply":"2022-11-02T22:24:37.698264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test[0]","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:49.655627Z","iopub.execute_input":"2022-11-02T22:24:49.656013Z","iopub.status.idle":"2022-11-02T22:24:49.666402Z","shell.execute_reply.started":"2022-11-02T22:24:49.655980Z","shell.execute_reply":"2022-11-02T22:24:49.665479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.predict(my_image.reshape(1, 32, 32, 3))","metadata":{"execution":{"iopub.status.busy":"2022-11-02T22:24:57.784753Z","iopub.execute_input":"2022-11-02T22:24:57.785126Z","iopub.status.idle":"2022-11-02T22:24:57.848150Z","shell.execute_reply.started":"2022-11-02T22:24:57.785094Z","shell.execute_reply":"2022-11-02T22:24:57.847183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}