{"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 tensorflow as tf\nimport matplotlib.pyplot as plt\nfrom IPython import display\nimport seaborn as sns\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n%matplotlib inline","metadata":{"id":"O11tbvtGhbkS","execution":{"iopub.status.busy":"2022-04-01T12:00:07.168806Z","iopub.execute_input":"2022-04-01T12:00:07.169099Z","iopub.status.idle":"2022-04-01T12:00:07.176251Z","shell.execute_reply.started":"2022-04-01T12:00:07.169068Z","shell.execute_reply":"2022-04-01T12:00:07.175296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()","metadata":{"id":"DP77CJ5nl6xb","execution":{"iopub.status.busy":"2022-04-01T11:47:58.121809Z","iopub.execute_input":"2022-04-01T11:47:58.122353Z","iopub.status.idle":"2022-04-01T11:48:07.474289Z","shell.execute_reply.started":"2022-04-01T11:47:58.122295Z","shell.execute_reply":"2022-04-01T11:48:07.473537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"97xwwueUmCY7"}},{"cell_type":"code","source":"from tensorflow.keras.utils import to_categorical\ny_train = to_categorical(y_train, num_classes = 10)\ny_test = to_categorical(y_test, num_classes = 10)\n","metadata":{"id":"0coAG5hUhxdi","execution":{"iopub.status.busy":"2022-04-01T11:48:07.475707Z","iopub.execute_input":"2022-04-01T11:48:07.475953Z","iopub.status.idle":"2022-04-01T11:48:07.483794Z","shell.execute_reply.started":"2022-04-01T11:48:07.475921Z","shell.execute_reply":"2022-04-01T11:48:07.483047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape,x_test.shape","metadata":{"id":"1oFvT1gWh31M","outputId":"613f0fcb-23c3-49a7-e8ae-7dcd02b48637","execution":{"iopub.status.busy":"2022-04-01T11:48:07.485242Z","iopub.execute_input":"2022-04-01T11:48:07.485507Z","iopub.status.idle":"2022-04-01T11:48:07.497087Z","shell.execute_reply.started":"2022-04-01T11:48:07.485475Z","shell.execute_reply":"2022-04-01T11:48:07.496366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train / 255\nx_test = x_test /255","metadata":{"id":"bpEUhMSLJQsg","execution":{"iopub.status.busy":"2022-04-01T11:48:07.499977Z","iopub.execute_input":"2022-04-01T11:48:07.500620Z","iopub.status.idle":"2022-04-01T11:48:07.956870Z","shell.execute_reply.started":"2022-04-01T11:48:07.500586Z","shell.execute_reply":"2022-04-01T11:48:07.956129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"randInt = np.random.randint(0,x_train.shape[0]-1,30)\n_,axs=plt.subplots(nrows=3,ncols=10,figsize=(24,6))\nfor i, ax in enumerate(axs.flat):\n    ax.imshow(x_train[randInt[i]].squeeze())\nplt.show()","metadata":{"id":"jU3VHbBTmTkf","outputId":"778c639f-28e2-456b-c9f9-a6cedee2db21","execution":{"iopub.status.busy":"2022-04-01T11:48:07.958125Z","iopub.execute_input":"2022-04-01T11:48:07.958388Z","iopub.status.idle":"2022-04-01T11:48:10.317600Z","shell.execute_reply.started":"2022-04-01T11:48:07.958355Z","shell.execute_reply":"2022-04-01T11:48:10.316955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"randInt = np.random.randint(0,x_test.shape[0]-1,30)\n_,axs=plt.subplots(nrows=3,ncols=10,figsize=(24,6))\nfor i, ax in enumerate(axs.flat):\n    ax.imshow(x_test[randInt[i]].squeeze())\nplt.show()","metadata":{"outputId":"1d435c75-724f-4e93-ada7-9b91d7e949ce","id":"h7T6jW7Lm5xH","execution":{"iopub.status.busy":"2022-04-01T11:48:10.318527Z","iopub.execute_input":"2022-04-01T11:48:10.318755Z","iopub.status.idle":"2022-04-01T11:48:12.627796Z","shell.execute_reply.started":"2022-04-01T11:48:10.318725Z","shell.execute_reply":"2022-04-01T11:48:12.627166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_shape = (32, 32, 3)\nnum_classes = 10","metadata":{"id":"GAE8C4y7Iux_","execution":{"iopub.status.busy":"2022-04-01T11:48:12.628874Z","iopub.execute_input":"2022-04-01T11:48:12.629567Z","iopub.status.idle":"2022-04-01T11:48:12.633689Z","shell.execute_reply.started":"2022-04-01T11:48:12.629533Z","shell.execute_reply":"2022-04-01T11:48:12.632877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input = tf.keras.Input(shape=input_shape) \nx = tf.keras.layers.Conv2D(32,kernel_size=3, use_bias=False, padding='same')(input)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Conv2D(32,kernel_size=3, use_bias=False, padding='same')(x)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Conv2D(32,kernel_size=5, use_bias=False, padding='same', strides=2)(x)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Dropout(0.2)(x)\nx = tf.keras.layers.Conv2D(64,kernel_size=3, use_bias=False, padding='same')(x)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Conv2D(64,kernel_size=3, use_bias=False, padding='same')(x)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Conv2D(64,kernel_size=5,  use_bias=False, padding='same', strides=2)(x)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Dropout(0.2)(x)\nx = tf.keras.layers.Conv2D(128,kernel_size=4,  use_bias=False, padding='same', strides=2)(x)\nx = tf.keras.layers.BatchNormalization(center=True, scale=False)(x)\nx = tf.keras.layers.Activation('relu')(x)\nx = tf.keras.layers.Flatten()(x)\nx = tf.keras.layers.Dropout(0.2)(x)\noutput = tf.keras.layers.Dense(num_classes,activation=\"softmax\")(x)\nmodel = tf.keras.Model(input,output,name=\"convnet\")\nmodel.summary()","metadata":{"id":"qJvrL2SUXI9s","execution":{"iopub.status.busy":"2022-04-01T12:00:23.037762Z","iopub.execute_input":"2022-04-01T12:00:23.038016Z","iopub.status.idle":"2022-04-01T12:00:23.181524Z","shell.execute_reply.started":"2022-04-01T12:00:23.037988Z","shell.execute_reply":"2022-04-01T12:00:23.180840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"id":"JZyF-NkupeXT"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 32\nepochs = 15\n\ndef scheduler(epoch, lr):\n    if epoch < 3:\n        return lr\n    else:\n\n        return lr * tf.math.exp(-0.1)\n\nclass myCallback(tf.keras.callbacks.Callback):\n    def on_epoch_end(self, epoch, logs={}):\n   \n\n    # Check accuracy\n        val_acc = 0.993\n        val_loss = 0.025\n        if(logs.get('val_accuracy') > val_acc) and ((logs.get('val_loss') < val_loss)):\n\n            # Stop if threshold is met\n            print(f\"\\n\\nval_accuracy is reached {val_acc} and val_loss lower than {val_loss} so cancelling training!\")\n            print(\"\")\n            self.model.stop_training = True\n\nstopCallback = myCallback()\nlr = tf.keras.callbacks.LearningRateScheduler(scheduler)\ntf.keras.callbacks.Callback()\nmodel.compile(loss=\"categorical_crossentropy\", optimizer=\"adam\", metrics=[\"accuracy\"])\nmodel.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, callbacks=[lr,stopCallback],validation_data=(x_test,y_test))","metadata":{"outputId":"e8e951d8-a0e0-4a54-d898-f5541608d86c","id":"-O323KSiWGz7","execution":{"iopub.status.busy":"2022-04-01T12:04:06.781093Z","iopub.execute_input":"2022-04-01T12:04:06.781657Z","iopub.status.idle":"2022-04-01T12:07:03.242937Z","shell.execute_reply.started":"2022-04-01T12:04:06.781617Z","shell.execute_reply":"2022-04-01T12:07:03.242122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_,ax = plt.subplots( ncols=2,nrows=1,figsize=(16,4))\nax[0].set_xlabel(\"epochs\")\nax[0].set_ylabel(\"loss\")\nax[0].set_title(\"final val_loss %1.4f\"%(model.history.history[\"val_loss\"][-1:][0]))\nax[1].set_xlabel(\"epochs\")\nax[1].set_ylabel(\"accuracy\")\nax[1].set_title(\"final val_acc %1.4f\"%(model.history.history[\"val_accuracy\"][-1:][0]))\npd.DataFrame([model.history.history[\"accuracy\"],model.history.history[\"val_accuracy\"]],index=[\"accuracy\",\"val_accuracy\"]).T.plot(ax=ax[1])\npd.DataFrame([model.history.history[\"loss\"],model.history.history[\"val_loss\"]],index=[\"loss\",\"val_loss\"]).T.plot(ax=ax[0])\n","metadata":{"outputId":"07d288b9-c5da-485b-ee2f-991469afa3dc","id":"Xk22OGgFWG0C","execution":{"iopub.status.busy":"2022-04-01T12:07:03.244521Z","iopub.execute_input":"2022-04-01T12:07:03.244922Z","iopub.status.idle":"2022-04-01T12:07:03.604138Z","shell.execute_reply.started":"2022-04-01T12:07:03.244882Z","shell.execute_reply":"2022-04-01T12:07:03.603156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"true_y = np.argmax(y_test,axis=1)\ntrue_y","metadata":{"id":"f50HbXIzyKOb","outputId":"0a3030a6-8032-4b1f-e4fc-8d354fa11b91","execution":{"iopub.status.busy":"2022-04-01T12:07:03.605438Z","iopub.execute_input":"2022-04-01T12:07:03.605670Z","iopub.status.idle":"2022-04-01T12:07:03.612394Z","shell.execute_reply.started":"2022-04-01T12:07:03.605638Z","shell.execute_reply":"2022-04-01T12:07:03.611519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = np.argmax(model.predict(x_test),axis=1)","metadata":{"id":"TNjcD24gxsez","execution":{"iopub.status.busy":"2022-04-01T12:07:03.614702Z","iopub.execute_input":"2022-04-01T12:07:03.615132Z","iopub.status.idle":"2022-04-01T12:07:04.755946Z","shell.execute_reply.started":"2022-04-01T12:07:03.615094Z","shell.execute_reply":"2022-04-01T12:07:04.755069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"id":"cLbhuKNWzfla","outputId":"74d21012-8aee-47e5-b8f6-5f2f6d58ff58","execution":{"iopub.status.busy":"2022-04-01T12:07:04.757305Z","iopub.execute_input":"2022-04-01T12:07:04.757561Z","iopub.status.idle":"2022-04-01T12:07:04.762212Z","shell.execute_reply.started":"2022-04-01T12:07:04.757527Z","shell.execute_reply":"2022-04-01T12:07:04.761583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"randInt = np.random.randint(0,x_test.shape[0]-1,30)\n_,axs=plt.subplots(nrows=5,ncols=6,figsize=(24,14))\nplt.subplots_adjust(wspace=-0.6, hspace=0.6)\nfor i, ax in enumerate(axs.flat):\n    ax.imshow(x_test4[randInt[i]].squeeze())\n\n    if pred[randInt[i]] == true_y[randInt[i]]:\n        ax.set_title( f\"pred: {class_names[pred[randInt[i]]]} , \\ntrue: {class_names[true_y[randInt[i]]]}\" ,fontdict={\"color\":\"green\"})\n    else: \n        ax.set_title( f\"pred: {class_names[pred[randInt[i]]]} , \\ntrue: {class_names[true_y[randInt[i]]]}\" ,fontdict={\"color\":\"red\"})\n    ax.set_xticks([])\n    ax.set_yticks([])     \n    \nplt.show()","metadata":{"outputId":"7b821d95-db80-4317-9db3-fae42214ad0f","id":"PhZjg0BFxM05","execution":{"iopub.status.busy":"2022-04-01T12:07:21.100365Z","iopub.execute_input":"2022-04-01T12:07:21.101165Z","iopub.status.idle":"2022-04-01T12:07:22.320817Z","shell.execute_reply.started":"2022-04-01T12:07:21.101113Z","shell.execute_reply":"2022-04-01T12:07:22.320184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def noise(array): # https://keras.io/examples/vision/autoencoder/\n    \"\"\"\n    Adds random noise to each image in the supplied array.\n    \"\"\"\n\n    noise_factor = 0.1\n    noisy_array = array + noise_factor * np.random.normal(\n        loc=0.0, scale=1.0, size=array.shape\n    )\n\n    return np.clip(noisy_array, 0.0, 1.0)","metadata":{"id":"P9UbT4FAh3si","execution":{"iopub.status.busy":"2022-04-01T11:51:40.008258Z","iopub.execute_input":"2022-04-01T11:51:40.010171Z","iopub.status.idle":"2022-04-01T11:51:40.016624Z","shell.execute_reply.started":"2022-04-01T11:51:40.010135Z","shell.execute_reply":"2022-04-01T11:51:40.015973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train2 = noise(x_train)\nx_test2 = noise(x_test)\n","metadata":{"id":"b77oRHmQqmxz","execution":{"iopub.status.busy":"2022-04-01T11:51:40.019699Z","iopub.execute_input":"2022-04-01T11:51:40.020226Z","iopub.status.idle":"2022-04-01T11:51:46.421963Z","shell.execute_reply.started":"2022-04-01T11:51:40.020198Z","shell.execute_reply":"2022-04-01T11:51:46.421166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator\ndef image_gen(rotation_range,zoom_range,width_shift,height_shift,train,labels,end_slice): #end_slice = train.shape[0]\n    datagen = ImageDataGenerator(\n                                    rotation_range=rotation_range,  \n                                    zoom_range = zoom_range,  \n                                    width_shift_range=width_shift, \n                                    height_shift_range=height_shift)\n    first = np.arange(0,int(end_slice),32)\n    end = np.arange(32,int(end_slice)+1,32)\n    train44=[]\n    labels44=[]\n\n    for i in range(end.shape[0]):\n        train4, labels4 = datagen.flow(train[first[i]:end[i]],labels[first[i]:end[i]]).next()\n        train44.append(train4)\n        labels44.append(labels4[0:int(end_slice)])\n\n    gen_train = np.concatenate(train44,axis=0)\n    gen_labels = np.concatenate(labels44,axis=0)\n\n    print(\"gen_train_shape:\",gen_train.shape,\"gen_labels_shape:\",gen_labels.shape)\n    train44=[]\n    labels44=[]\n    return gen_train, gen_labels","metadata":{"id":"_-_EjosWqW6Q","execution":{"iopub.status.busy":"2022-04-01T11:51:46.425596Z","iopub.execute_input":"2022-04-01T11:51:46.425873Z","iopub.status.idle":"2022-04-01T11:51:46.434719Z","shell.execute_reply.started":"2022-04-01T11:51:46.425843Z","shell.execute_reply":"2022-04-01T11:51:46.433969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train3,y_train3 = image_gen(rotation_range=10,zoom_range=0.1,width_shift=0.1,height_shift=0.1,train=x_train,labels=y_train,end_slice=x_train.shape[0]/4)\nx_test3,y_test3 = image_gen(rotation_range=10,zoom_range=0.1,width_shift=0.1,height_shift=0.1,train=x_test,labels=y_test,end_slice=x_test.shape[0]/4)\n","metadata":{"id":"hANX_yCrqW2z","outputId":"6e5efea0-43c4-4de3-d4b8-ad30df5c54ca","execution":{"iopub.status.busy":"2022-04-01T11:51:46.436146Z","iopub.execute_input":"2022-04-01T11:51:46.436669Z","iopub.status.idle":"2022-04-01T11:51:52.909583Z","shell.execute_reply.started":"2022-04-01T11:51:46.436630Z","shell.execute_reply":"2022-04-01T11:51:52.908101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train4 = np.concatenate([x_train,x_train2,x_train3],axis=0)\ny_train4 = np.concatenate([y_train,y_train,y_train3],axis=0)\nx_test4 = np.concatenate([x_test,x_test2,x_test3],axis=0)\ny_test4 = np.concatenate([y_test,y_test,y_test3],axis=0)","metadata":{"id":"Tp9v602cxBTa","execution":{"iopub.status.busy":"2022-04-01T11:51:52.910701Z","iopub.execute_input":"2022-04-01T11:51:52.910940Z","iopub.status.idle":"2022-04-01T11:51:54.519290Z","shell.execute_reply.started":"2022-04-01T11:51:52.910904Z","shell.execute_reply":"2022-04-01T11:51:54.518468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(x_train4.shape,y_train4.shape)\nprint(x_test4.shape,y_test4.shape)","metadata":{"id":"Ke4-p1eduYWc","outputId":"004687b5-206c-476b-a9af-04aa9cc8f3a8","execution":{"iopub.status.busy":"2022-04-01T11:51:54.520477Z","iopub.execute_input":"2022-04-01T11:51:54.520740Z","iopub.status.idle":"2022-04-01T11:51:54.525701Z","shell.execute_reply.started":"2022-04-01T11:51:54.520698Z","shell.execute_reply":"2022-04-01T11:51:54.525005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 32\nepochs = 15\n\nstopCallback = myCallback()\nlr = tf.keras.callbacks.LearningRateScheduler(scheduler)\ntf.keras.callbacks.Callback()\nmodel.compile(loss=\"categorical_crossentropy\", optimizer=\"adam\", metrics=[\"accuracy\"])\nmodel.fit(x_train4, y_train4, batch_size=batch_size, epochs=epochs, callbacks=[lr,stopCallback],validation_data=(x_test4,y_test4))","metadata":{"outputId":"023264f3-1fc5-4825-9824-2c223a1c01c9","id":"fbn4qUubpo-U","execution":{"iopub.status.busy":"2022-04-01T11:51:54.526789Z","iopub.execute_input":"2022-04-01T11:51:54.527630Z","iopub.status.idle":"2022-04-01T11:58:20.998019Z","shell.execute_reply.started":"2022-04-01T11:51:54.527595Z","shell.execute_reply":"2022-04-01T11:58:20.997256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_,ax = plt.subplots( ncols=2,nrows=1,figsize=(16,4))\nax[0].set_xlabel(\"epochs\")\nax[0].set_ylabel(\"loss\")\nax[0].set_title(\"final val_loss %1.4f\"%(model.history.history[\"val_loss\"][-1:][0]))\nax[1].set_xlabel(\"epochs\")\nax[1].set_ylabel(\"accuracy\")\nax[1].set_title(\"final val_acc %1.4f\"%(model.history.history[\"val_accuracy\"][-1:][0]))\npd.DataFrame([model.history.history[\"accuracy\"],model.history.history[\"val_accuracy\"]],index=[\"accuracy\",\"val_accuracy\"]).T.plot(ax=ax[1])\npd.DataFrame([model.history.history[\"loss\"],model.history.history[\"val_loss\"]],index=[\"loss\",\"val_loss\"]).T.plot(ax=ax[0])\n","metadata":{"outputId":"6aef5419-dd4d-4ea5-b88a-173d62b43156","id":"0rMw2uygpo-c","execution":{"iopub.status.busy":"2022-04-01T11:58:20.999758Z","iopub.execute_input":"2022-04-01T11:58:21.000031Z","iopub.status.idle":"2022-04-01T11:58:21.372537Z","shell.execute_reply.started":"2022-04-01T11:58:20.999995Z","shell.execute_reply":"2022-04-01T11:58:21.371858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = [\n    \"Airplane\",\n    \"Automobile\",\n    \"Bird\",\n    \"Cat\",\n    \"Deer\",\n    \"Dog\",\n    \"Frog\",\n    \"Horse\",\n    \"Ship\",\n    \"Truck\",\n]","metadata":{"id":"VsyZr4xuh3pi","execution":{"iopub.status.busy":"2022-04-01T11:58:21.373792Z","iopub.execute_input":"2022-04-01T11:58:21.374194Z","iopub.status.idle":"2022-04-01T11:58:21.379260Z","shell.execute_reply.started":"2022-04-01T11:58:21.374157Z","shell.execute_reply":"2022-04-01T11:58:21.378384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test4.shape","metadata":{"id":"6gTBSbHIh3mC","outputId":"aa854f27-97ef-4492-ed80-3bcc246464e0","execution":{"iopub.status.busy":"2022-04-01T11:58:21.380445Z","iopub.execute_input":"2022-04-01T11:58:21.380759Z","iopub.status.idle":"2022-04-01T11:58:21.389919Z","shell.execute_reply.started":"2022-04-01T11:58:21.380723Z","shell.execute_reply":"2022-04-01T11:58:21.389089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"true_y = np.argmax(y_test4,axis=1)\ntrue_y","metadata":{"id":"f50HbXIzyKOb","outputId":"0a3030a6-8032-4b1f-e4fc-8d354fa11b91","execution":{"iopub.status.busy":"2022-04-01T11:58:21.391305Z","iopub.execute_input":"2022-04-01T11:58:21.391578Z","iopub.status.idle":"2022-04-01T11:58:21.400633Z","shell.execute_reply.started":"2022-04-01T11:58:21.391530Z","shell.execute_reply":"2022-04-01T11:58:21.399839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = np.argmax(model.predict(x_test4),axis=1)","metadata":{"id":"TNjcD24gxsez","execution":{"iopub.status.busy":"2022-04-01T11:58:21.402110Z","iopub.execute_input":"2022-04-01T11:58:21.402478Z","iopub.status.idle":"2022-04-01T11:58:23.358355Z","shell.execute_reply.started":"2022-04-01T11:58:21.402446Z","shell.execute_reply":"2022-04-01T11:58:23.357562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"id":"cLbhuKNWzfla","outputId":"74d21012-8aee-47e5-b8f6-5f2f6d58ff58","execution":{"iopub.status.busy":"2022-04-01T11:58:23.359830Z","iopub.execute_input":"2022-04-01T11:58:23.360074Z","iopub.status.idle":"2022-04-01T11:58:23.368297Z","shell.execute_reply.started":"2022-04-01T11:58:23.360041Z","shell.execute_reply":"2022-04-01T11:58:23.367606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"randInt = np.random.randint(0,x_test4.shape[0]-1,30)\n_,axs=plt.subplots(nrows=5,ncols=6,figsize=(24,14))\nplt.subplots_adjust(wspace=-0.6, hspace=0.6)\nfor i, ax in enumerate(axs.flat):\n    ax.imshow(x_test4[randInt[i]].squeeze())\n\n    if pred[randInt[i]] == true_y[randInt[i]]:\n        ax.set_title( f\"pred: {class_names[pred[randInt[i]]]} , \\ntrue: {class_names[true_y[randInt[i]]]}\" ,fontdict={\"color\":\"green\"})\n    else: \n        ax.set_title( f\"pred: {class_names[pred[randInt[i]]]} , \\ntrue: {class_names[true_y[randInt[i]]]}\" ,fontdict={\"color\":\"red\"})\n    ax.set_xticks([])\n    ax.set_yticks([])     \n    \nplt.show()","metadata":{"outputId":"7b821d95-db80-4317-9db3-fae42214ad0f","id":"PhZjg0BFxM05","execution":{"iopub.status.busy":"2022-04-01T11:59:34.633862Z","iopub.execute_input":"2022-04-01T11:59:34.634122Z","iopub.status.idle":"2022-04-01T11:59:35.587432Z","shell.execute_reply.started":"2022-04-01T11:59:34.634093Z","shell.execute_reply":"2022-04-01T11:59:35.586756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"id":"-gPSDekXh3jC"},"execution_count":null,"outputs":[]}]}