{"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":"2023-01-04T18:22:49.603456Z","iopub.execute_input":"2023-01-04T18:22:49.603924Z","iopub.status.idle":"2023-01-04T18:22:49.615072Z","shell.execute_reply.started":"2023-01-04T18:22:49.603885Z","shell.execute_reply":"2023-01-04T18:22:49.613613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport cv2\nimport keras\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:22:49.621486Z","iopub.execute_input":"2023-01-04T18:22:49.622354Z","iopub.status.idle":"2023-01-04T18:22:49.961710Z","shell.execute_reply.started":"2023-01-04T18:22:49.622301Z","shell.execute_reply":"2023-01-04T18:22:49.960135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# UNZIP THE DATASET\nimport zipfile\n\nwith zipfile.ZipFile('/kaggle/input/dogs-vs-cats/test1.zip', 'r') as zip_ref:\n    zip_ref.extractall('./')\n    \nwith zipfile.ZipFile('/kaggle/input/dogs-vs-cats/train.zip', 'r') as zip_ref:\n    zip_ref.extractall('./')\n    \ntrain_path = '/kaggle/working/train'\ntest_path = '/kaggle/working/test1'","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:22:49.964755Z","iopub.execute_input":"2023-01-04T18:22:49.965825Z","iopub.status.idle":"2023-01-04T18:23:10.764123Z","shell.execute_reply.started":"2023-01-04T18:22:49.965772Z","shell.execute_reply":"2023-01-04T18:23:10.762859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Data Preprocessing","metadata":{}},{"cell_type":"code","source":"import glob\nglob.glob(\"/kaggle/working/train/*.jpg\")[:5]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:10.765666Z","iopub.execute_input":"2023-01-04T18:23:10.766032Z","iopub.status.idle":"2023-01-04T18:23:10.858954Z","shell.execute_reply.started":"2023-01-04T18:23:10.765998Z","shell.execute_reply":"2023-01-04T18:23:10.857570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file = 'dog.9281.jpg'\nfile.split('.')[0]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:10.860500Z","iopub.execute_input":"2023-01-04T18:23:10.860991Z","iopub.status.idle":"2023-01-04T18:23:10.868736Z","shell.execute_reply.started":"2023-01-04T18:23:10.860947Z","shell.execute_reply":"2023-01-04T18:23:10.867451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categories = []\n\nfor file in os.listdir(train_path):\n    category = file.split('.')[0]\n    \n    if category == 'dog':\n        categories.append(1)\n    else:\n        categories.append(0)\n# 0 for CAT\n# 1 for DOG\n\ncategories[:5]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:10.872578Z","iopub.execute_input":"2023-01-04T18:23:10.873381Z","iopub.status.idle":"2023-01-04T18:23:10.914690Z","shell.execute_reply.started":"2023-01-04T18:23:10.873332Z","shell.execute_reply":"2023-01-04T18:23:10.913477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create dataframe with CAT(0)-DOG(1) labels:\ntrain_set = pd.DataFrame({'file': os.listdir(train_path), 'label':categories})","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:10.916394Z","iopub.execute_input":"2023-01-04T18:23:10.916901Z","iopub.status.idle":"2023-01-04T18:23:10.951765Z","shell.execute_reply.started":"2023-01-04T18:23:10.916854Z","shell.execute_reply":"2023-01-04T18:23:10.950514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:10.953445Z","iopub.execute_input":"2023-01-04T18:23:10.953949Z","iopub.status.idle":"2023-01-04T18:23:10.971208Z","shell.execute_reply.started":"2023-01-04T18:23:10.953901Z","shell.execute_reply":"2023-01-04T18:23:10.969936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_id = os.listdir(train_path)[np.random.randint(100)]\nimage = cv2.imread(train_path + f'/{image_id}')\nplt.imshow(image)\nplt.title(image_id)\nplt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:10.972852Z","iopub.execute_input":"2023-01-04T18:23:10.973241Z","iopub.status.idle":"2023-01-04T18:23:11.243797Z","shell.execute_reply.started":"2023-01-04T18:23:10.973175Z","shell.execute_reply":"2023-01-04T18:23:11.242527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Load Train and Test Data","metadata":{}},{"cell_type":"code","source":"train_set.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.245479Z","iopub.execute_input":"2023-01-04T18:23:11.246735Z","iopub.status.idle":"2023-01-04T18:23:11.255653Z","shell.execute_reply.started":"2023-01-04T18:23:11.246684Z","shell.execute_reply":"2023-01-04T18:23:11.254084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Shuffle (optional)\n# train_set = train_set.sample(frac=1)","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.258304Z","iopub.execute_input":"2023-01-04T18:23:11.258862Z","iopub.status.idle":"2023-01-04T18:23:11.267220Z","shell.execute_reply.started":"2023-01-04T18:23:11.258814Z","shell.execute_reply":"2023-01-04T18:23:11.265799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"split the data into train(80%) and test(20%) set","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\ntrain , test = train_test_split(train_set, test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.268969Z","iopub.execute_input":"2023-01-04T18:23:11.269698Z","iopub.status.idle":"2023-01-04T18:23:11.666031Z","shell.execute_reply.started":"2023-01-04T18:23:11.269609Z","shell.execute_reply":"2023-01-04T18:23:11.664759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('no of Training data: ' + str(train.shape[0]))\nprint('no of Test data: ' + str(test.shape[0]))","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.667844Z","iopub.execute_input":"2023-01-04T18:23:11.668363Z","iopub.status.idle":"2023-01-04T18:23:11.675589Z","shell.execute_reply.started":"2023-01-04T18:23:11.668323Z","shell.execute_reply":"2023-01-04T18:23:11.674184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.677154Z","iopub.execute_input":"2023-01-04T18:23:11.677524Z","iopub.status.idle":"2023-01-04T18:23:11.697490Z","shell.execute_reply.started":"2023-01-04T18:23:11.677482Z","shell.execute_reply":"2023-01-04T18:23:11.696116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_data():\n    path = train_path\n    \n    dataframes = [train, test]\n    \n    output = []\n    \n    for df in dataframes:\n        images = []\n        labels = []\n        \n        for i in range(len(df)):\n            file = df.iloc[i]['file']\n            \n            img_path = path + f'/{file}'\n            \n            # open (and resize the image)\n            image = cv2.imread(img_path)\n            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n            image = cv2.resize(image, (150,150))\n            \n            images.append(image)\n            labels.append(df.iloc[i]['label'])\n        \n        images = np.array(images, dtype='float32')\n        labels = np.array(labels, dtype='int32')\n        \n        output.append((images, labels))\n    \n    \n    return output\n    \n#     returns [(x_train, y_train), (x_test, y_test)]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.704577Z","iopub.execute_input":"2023-01-04T18:23:11.705021Z","iopub.status.idle":"2023-01-04T18:23:11.717879Z","shell.execute_reply.started":"2023-01-04T18:23:11.704983Z","shell.execute_reply":"2023-01-04T18:23:11.716293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(x_train, y_train), (x_test, y_test) = load_data()","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:23:11.719905Z","iopub.execute_input":"2023-01-04T18:23:11.720404Z","iopub.status.idle":"2023-01-04T18:24:48.685569Z","shell.execute_reply.started":"2023-01-04T18:23:11.720357Z","shell.execute_reply":"2023-01-04T18:24:48.684279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"x_train.shape: \" + str(x_train.shape))\nprint(\"y_train.shape: \" + str(y_train.shape))\nprint(\"x_test.shape: \" + str(x_test.shape))\nprint(\"y_test.shape: \" + str(y_test.shape))","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:48.687486Z","iopub.execute_input":"2023-01-04T18:24:48.687898Z","iopub.status.idle":"2023-01-04T18:24:48.696018Z","shell.execute_reply.started":"2023-01-04T18:24:48.687863Z","shell.execute_reply":"2023-01-04T18:24:48.694375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Prepare the labels\nfrom keras.utils import np_utils\nnum_classes = len(np.unique(y_train))\ny_train = keras.utils.np_utils.to_categorical(y_train, num_classes)\ny_test = keras.utils.np_utils.to_categorical(y_test, num_classes)","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:48.697687Z","iopub.execute_input":"2023-01-04T18:24:48.698054Z","iopub.status.idle":"2023-01-04T18:24:48.712574Z","shell.execute_reply.started":"2023-01-04T18:24:48.698021Z","shell.execute_reply":"2023-01-04T18:24:48.711332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Rescale the images\nx_train = x_train.astype('float32')/255\nx_test = x_test.astype('float32')/255","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:48.714746Z","iopub.execute_input":"2023-01-04T18:24:48.715094Z","iopub.status.idle":"2023-01-04T18:24:52.882421Z","shell.execute_reply.started":"2023-01-04T18:24:48.715063Z","shell.execute_reply":"2023-01-04T18:24:52.881142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Divide the train set into Train(80% - 16000) and Validation(20% - 4000)\nx_val = x_train[:4000]\ny_val = y_train[:4000]\nx_train = x_train[4000:]\ny_train = y_train[4000:]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:52.884172Z","iopub.execute_input":"2023-01-04T18:24:52.884532Z","iopub.status.idle":"2023-01-04T18:24:52.890340Z","shell.execute_reply.started":"2023-01-04T18:24:52.884500Z","shell.execute_reply":"2023-01-04T18:24:52.888957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"x_train.shape: \" + str(x_train.shape))\nprint(\"y_train.shape: \" + str(y_train.shape))\nprint(\"x_val.shape: \" + str(x_val.shape))\nprint(\"y_val.shape: \" + str(y_val.shape))","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:52.891919Z","iopub.execute_input":"2023-01-04T18:24:52.893127Z","iopub.status.idle":"2023-01-04T18:24:52.905674Z","shell.execute_reply.started":"2023-01-04T18:24:52.893077Z","shell.execute_reply":"2023-01-04T18:24:52.904348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Define The Model","metadata":{}},{"cell_type":"code","source":"# CNN : INPUT -> CONV1 -> CONV2 -> POOL1 -> CONV3 -> POOL2 -> FLATTEN -> DROPOUT -> FC1 ->  FC2(SIGMOID)\n# DEFINE THE MODEL USING FUNCTIONAL API\n\nfrom keras.models import Model\nfrom keras.layers import Input, Conv2D, MaxPooling2D, Flatten, Dropout, Dense\n\ninput_layer = Input(shape=(150,150,3))\nconv1 = Conv2D(16, kernel_size=(3,3), strides=1, padding='same', activation='relu')(input_layer)\npool1 = MaxPooling2D(pool_size=(2,2))(conv1)\n\nconv2 = Conv2D(32, kernel_size=(3,3), strides=1, padding='same', activation='relu')(pool1)\npool2 = MaxPooling2D(pool_size=(2,2))(conv2)\n\nconv3 = Conv2D(64, kernel_size=(3,3), strides=1, padding='same', activation='relu')(pool2)\npool3 = MaxPooling2D(pool_size=(2,2))(conv3)\n\nconv4 = Conv2D(128,kernel_size=(3,3), strides=1, padding='same', activation='relu')(pool3)\npool4 = MaxPooling2D(pool_size=(2,2))(conv4)\n\nflat = Flatten()(pool4)\ndo1 = Dropout(0.4)(flat)\ndense1 = Dense(400, activation='relu')(do1)\noutput_layer = Dense(2, activation='sigmoid')(dense1)\n\nmodel = Model(inputs=input_layer, outputs = output_layer)\n\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:52.907497Z","iopub.execute_input":"2023-01-04T18:24:52.907930Z","iopub.status.idle":"2023-01-04T18:24:53.025281Z","shell.execute_reply.started":"2023-01-04T18:24:52.907892Z","shell.execute_reply":"2023-01-04T18:24:53.023964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:53.027041Z","iopub.execute_input":"2023-01-04T18:24:53.027454Z","iopub.status.idle":"2023-01-04T18:24:53.043851Z","shell.execute_reply.started":"2023-01-04T18:24:53.027417Z","shell.execute_reply":"2023-01-04T18:24:53.042617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train the Model","metadata":{}},{"cell_type":"code","source":"from keras.callbacks import ModelCheckpoint\ncheckpointer = ModelCheckpoint(filepath='model.weights.best.hdf5', verbose=1, save_best_only=True)\n\nhist = model.fit(x_train, y_train, batch_size=32, epochs=10, verbose=2, callbacks=[checkpointer], validation_data=(x_val, y_val))","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:24:53.045633Z","iopub.execute_input":"2023-01-04T18:24:53.046073Z","iopub.status.idle":"2023-01-04T18:43:48.749266Z","shell.execute_reply.started":"2023-01-04T18:24:53.046028Z","shell.execute_reply":"2023-01-04T18:43:48.746854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.load_weights('model.weights.best.hdf5')","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:43:48.753929Z","iopub.execute_input":"2023-01-04T18:43:48.754475Z","iopub.status.idle":"2023-01-04T18:43:48.789822Z","shell.execute_reply.started":"2023-01-04T18:43:48.754410Z","shell.execute_reply":"2023-01-04T18:43:48.788567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score = model.evaluate(x_test, y_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:43:48.792121Z","iopub.execute_input":"2023-01-04T18:43:48.792631Z","iopub.status.idle":"2023-01-04T18:44:00.656026Z","shell.execute_reply.started":"2023-01-04T18:43:48.792583Z","shell.execute_reply":"2023-01-04T18:44:00.654728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Accuracy = ' + str(score[1]))","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:44:00.658288Z","iopub.execute_input":"2023-01-04T18:44:00.658806Z","iopub.status.idle":"2023-01-04T18:44:00.670005Z","shell.execute_reply.started":"2023-01-04T18:44:00.658758Z","shell.execute_reply":"2023-01-04T18:44:00.668631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(hist.history['loss'], color='orange', label='Train loss')\nplt.plot(hist.history['val_loss'], color='blue', label='Val loss')\nplt.grid(True)\nplt.title(\"Train & Test loss with epochs\\n\", fontsize=16)\nplt.xlabel(\"Training epochs\", fontsize=12)\nplt.ylabel(\"Train & Test loss\", fontsize=12)\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:44:00.672327Z","iopub.execute_input":"2023-01-04T18:44:00.673269Z","iopub.status.idle":"2023-01-04T18:44:00.978850Z","shell.execute_reply.started":"2023-01-04T18:44:00.673155Z","shell.execute_reply":"2023-01-04T18:44:00.977317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(hist.history['accuracy'], color='orange', label='Train accuracy')\nplt.plot(hist.history['val_accuracy'], color='blue', label='Val accuracy')\nplt.grid(True)\nplt.title(\"Train & Test accuracy with epochs\\n\", fontsize=16)\nplt.xlabel(\"Training epochs\", fontsize=12)\nplt.ylabel(\"Train & Test accuracy\", fontsize=12)\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2023-01-04T18:44:00.981220Z","iopub.execute_input":"2023-01-04T18:44:00.981782Z","iopub.status.idle":"2023-01-04T18:44:01.280653Z","shell.execute_reply.started":"2023-01-04T18:44:00.981732Z","shell.execute_reply":"2023-01-04T18:44:01.279114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Make Predictions for new data","metadata":{}},{"cell_type":"code","source":"glob.glob(\"/kaggle/working/test1/*.jpg\")[:5]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T19:00:23.031287Z","iopub.execute_input":"2023-01-04T19:00:23.032608Z","iopub.status.idle":"2023-01-04T19:00:23.082571Z","shell.execute_reply.started":"2023-01-04T19:00:23.032562Z","shell.execute_reply":"2023-01-04T19:00:23.081071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Prepare the test data","metadata":{}},{"cell_type":"code","source":"test_path\ntest_img = []\n\nfor file in os.listdir(test_path):\n    img_path = test_path + f'/{file}'\n    \n    image = cv2.imread(img_path)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    image = cv2.resize(image, (150,150))\n    \n    test_img.append(image)\n    \ntest_img = np.array(test_img, dtype= 'float32')\n\n# Rescale the images\ntest_img = test_img.astype('float32')/255","metadata":{"execution":{"iopub.status.busy":"2023-01-04T19:44:59.113815Z","iopub.execute_input":"2023-01-04T19:44:59.114306Z","iopub.status.idle":"2023-01-04T19:45:47.094558Z","shell.execute_reply.started":"2023-01-04T19:44:59.114257Z","shell.execute_reply":"2023-01-04T19:45:47.093281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_img.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-04T19:46:02.264253Z","iopub.execute_input":"2023-01-04T19:46:02.265107Z","iopub.status.idle":"2023-01-04T19:46:02.273760Z","shell.execute_reply.started":"2023-01-04T19:46:02.265051Z","shell.execute_reply":"2023-01-04T19:46:02.272556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Make Predictions","metadata":{}},{"cell_type":"code","source":"predictions = model.predict(test_img)","metadata":{"execution":{"iopub.status.busy":"2023-01-04T19:48:19.874572Z","iopub.execute_input":"2023-01-04T19:48:19.875029Z","iopub.status.idle":"2023-01-04T19:48:44.696371Z","shell.execute_reply.started":"2023-01-04T19:48:19.874993Z","shell.execute_reply":"2023-01-04T19:48:44.695108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions","metadata":{"execution":{"iopub.status.busy":"2023-01-04T19:48:50.669878Z","iopub.execute_input":"2023-01-04T19:48:50.670362Z","iopub.status.idle":"2023-01-04T19:48:50.681474Z","shell.execute_reply.started":"2023-01-04T19:48:50.670320Z","shell.execute_reply":"2023-01-04T19:48:50.679767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict_labels = [int(round(p[1])) for p in predictions]","metadata":{"execution":{"iopub.status.busy":"2023-01-04T20:09:02.133994Z","iopub.execute_input":"2023-01-04T20:09:02.134475Z","iopub.status.idle":"2023-01-04T20:09:02.163604Z","shell.execute_reply.started":"2023-01-04T20:09:02.134430Z","shell.execute_reply":"2023-01-04T20:09:02.162345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Display Sample Predictions:","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(15,30))\nrows, cols = (1, 5)\n\nfor i in range(5):\n    idx = np.random.randint(test_img.shape[0])\n    label = 'dog' if predict_labels[idx]==1 else 'cat'\n    \n    fig.add_subplot(1, 5, i+1)\n    plt.imshow(test_img[idx])\n    plt.title(label)\n    plt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2023-01-04T20:10:58.846909Z","iopub.execute_input":"2023-01-04T20:10:58.847381Z","iopub.status.idle":"2023-01-04T20:10:59.271766Z","shell.execute_reply.started":"2023-01-04T20:10:58.847339Z","shell.execute_reply":"2023-01-04T20:10:59.270587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}