{"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":"2021-11-02T09:39:30.141483Z","iopub.execute_input":"2021-11-02T09:39:30.141942Z","iopub.status.idle":"2021-11-02T09:39:30.152598Z","shell.execute_reply.started":"2021-11-02T09:39:30.1419Z","shell.execute_reply":"2021-11-02T09:39:30.151833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls\n","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:30.154564Z","iopub.execute_input":"2021-11-02T09:39:30.155305Z","iopub.status.idle":"2021-11-02T09:39:30.820781Z","shell.execute_reply.started":"2021-11-02T09:39:30.155267Z","shell.execute_reply":"2021-11-02T09:39:30.819931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!unzip ../input/dogs-vs-cats-redux-kernels-edition/test.zip","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:30.822436Z","iopub.execute_input":"2021-11-02T09:39:30.822865Z","iopub.status.idle":"2021-11-02T09:39:36.888386Z","shell.execute_reply.started":"2021-11-02T09:39:30.822822Z","shell.execute_reply":"2021-11-02T09:39:36.887497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!unzip ../input/dogs-vs-cats-redux-kernels-edition/train.zip","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:36.891334Z","iopub.execute_input":"2021-11-02T09:39:36.891852Z","iopub.status.idle":"2021-11-02T09:39:48.173624Z","shell.execute_reply.started":"2021-11-02T09:39:36.891809Z","shell.execute_reply":"2021-11-02T09:39:48.172415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nfrom keras.preprocessing.image import ImageDataGenerator, load_img\nfrom tensorflow.keras.utils import to_categorical\nfrom sklearn.model_selection import train_test_split\nimport matplotlib.pyplot as plt\nimport random\nimport tensorflow as tf\nimport os\nimport random\nimport shutil\nfrom tensorflow.keras.optimizers import RMSprop\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom shutil import copyfile\nfrom os import getcwd\nimport matplotlib.image as mpimg\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport matplotlib.pyplot as plt\nfrom tensorflow.keras.applications.inception_v3 import InceptionV3\nfrom tensorflow.keras import layers\nfrom tensorflow.keras import Model\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras import layers\nfrom tensorflow.keras import Model\nfrom tensorflow.keras.applications.inception_v3 import InceptionV3\nfrom tensorflow.keras.optimizers import RMSprop\nfrom shutil import copyfile\nimport urllib.request\nimport os\nprint(os.listdir(\"../input\"))","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:48.178174Z","iopub.execute_input":"2021-11-02T09:39:48.178426Z","iopub.status.idle":"2021-11-02T09:39:54.310937Z","shell.execute_reply.started":"2021-11-02T09:39:48.178394Z","shell.execute_reply":"2021-11-02T09:39:54.310212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames = os.listdir(\"./train\")\ncategories = []\nfor filename in filenames:\n    category = filename.split('.')[0]\n    if category == 'dog':\n        categories.append(1)\n    else:\n        categories.append(0)\n\ndf = pd.DataFrame({\n    'filename': filenames,\n    'category': categories\n})\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:54.312433Z","iopub.execute_input":"2021-11-02T09:39:54.312731Z","iopub.status.idle":"2021-11-02T09:39:54.378Z","shell.execute_reply.started":"2021-11-02T09:39:54.312691Z","shell.execute_reply":"2021-11-02T09:39:54.377294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['category'].value_counts().plot.bar()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:54.379428Z","iopub.execute_input":"2021-11-02T09:39:54.379709Z","iopub.status.idle":"2021-11-02T09:39:55.00209Z","shell.execute_reply.started":"2021-11-02T09:39:54.379672Z","shell.execute_reply":"2021-11-02T09:39:55.001415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = random.choice(filenames)\nimage = load_img(\"./train/\"+sample)\nplt.imshow(image)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.003246Z","iopub.execute_input":"2021-11-02T09:39:55.003484Z","iopub.status.idle":"2021-11-02T09:39:55.241452Z","shell.execute_reply.started":"2021-11-02T09:39:55.003451Z","shell.execute_reply":"2021-11-02T09:39:55.240798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df, validate_df = train_test_split(df, test_size=0.1)\ntrain_df = train_df.reset_index()\nvalidate_df = validate_df.reset_index()\n\n# validate_df = validate_df.sample(n=100).reset_index() # use for fast testing code purpose\n# train_df = train_df.sample(n=1800).reset_index() # use for fast testing code purpose\n\ntotal_train = train_df.shape[0]\ntotal_validate = validate_df.shape[0]","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.242368Z","iopub.execute_input":"2021-11-02T09:39:55.242581Z","iopub.status.idle":"2021-11-02T09:39:55.25706Z","shell.execute_reply.started":"2021-11-02T09:39:55.242553Z","shell.execute_reply":"2021-11-02T09:39:55.256351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path='train'\ntest_path='test'","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.260309Z","iopub.execute_input":"2021-11-02T09:39:55.2605Z","iopub.status.idle":"2021-11-02T09:39:55.263813Z","shell.execute_reply.started":"2021-11-02T09:39:55.260477Z","shell.execute_reply":"2021-11-02T09:39:55.262934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set = os.listdir(train_path)\ntest_set = os.listdir(test_path)\nprint(\"The numbers of imagaes in training set are {}\".format(len(train_set)))\nprint(\"The numbers of imagaes in test set are {}\".format(len(test_set)))","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.265498Z","iopub.execute_input":"2021-11-02T09:39:55.266083Z","iopub.status.idle":"2021-11-02T09:39:55.2946Z","shell.execute_reply.started":"2021-11-02T09:39:55.266034Z","shell.execute_reply":"2021-11-02T09:39:55.293953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nall_dogs = glob.glob('./train/dog*jpg')\nall_cats = glob.glob('./train/cat*jpg')\n\nprint(\"The numbers of dog images in train dataset {}\".format(len(all_dogs)))\nprint(\"The numbers of cat images in train dataset {}\".format(len(all_cats)))\n","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.295921Z","iopub.execute_input":"2021-11-02T09:39:55.296373Z","iopub.status.idle":"2021-11-02T09:39:55.42079Z","shell.execute_reply.started":"2021-11-02T09:39:55.296339Z","shell.execute_reply":"2021-11-02T09:39:55.420085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dog_train_dir = './training/dog'\ndog_val_dir = './validation/dog'\ncat_train_dir = './training/cat'\ncat_val_dir = './validation/cat'\n\nfile_dirs = [dog_train_dir, dog_val_dir, cat_train_dir, cat_val_dir]\n\nfor dir in file_dirs:\n    os.makedirs(dir,exist_ok = True)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.42188Z","iopub.execute_input":"2021-11-02T09:39:55.422252Z","iopub.status.idle":"2021-11-02T09:39:55.428789Z","shell.execute_reply.started":"2021-11-02T09:39:55.422214Z","shell.execute_reply":"2021-11-02T09:39:55.427959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\ndogs_train, dogs_test = train_test_split(all_dogs, test_size=0.1, shuffle=True,random_state = 100)\ncats_train, cats_test = train_test_split(all_cats, test_size=0.1, shuffle=True,random_state = 100)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.429896Z","iopub.execute_input":"2021-11-02T09:39:55.430699Z","iopub.status.idle":"2021-11-02T09:39:55.446231Z","shell.execute_reply.started":"2021-11-02T09:39:55.430663Z","shell.execute_reply":"2021-11-02T09:39:55.44551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm import tqdm\nfrom shutil import copy, move\n\nfor name in tqdm(dogs_train):\n  copy(name , os.path.join(dog_train_dir , name.split('/')[-1]))\nfor name in tqdm(cats_train):\n  copy(name , os.path.join(cat_train_dir , name.split('/')[-1]))","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:55.447005Z","iopub.execute_input":"2021-11-02T09:39:55.447252Z","iopub.status.idle":"2021-11-02T09:39:57.882432Z","shell.execute_reply.started":"2021-11-02T09:39:55.44722Z","shell.execute_reply":"2021-11-02T09:39:57.881704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for name in tqdm(dogs_test):\n  copy(name , os.path.join(dog_val_dir , name.split('/')[-1]))\nfor name in tqdm(cats_test):\n  copy(name , os.path.join(cat_val_dir , name.split('/')[-1]))","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:57.883748Z","iopub.execute_input":"2021-11-02T09:39:57.884519Z","iopub.status.idle":"2021-11-02T09:39:58.168381Z","shell.execute_reply.started":"2021-11-02T09:39:57.884481Z","shell.execute_reply":"2021-11-02T09:39:58.167574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_imgs(item_dir, top=10):\n    all_item_dirs = os.listdir(item_dir)\n    item_files = [os.path.join(item_dir, file) for file in all_item_dirs][100:106]\n  \n    plt.figure(figsize=(10, 10))\n  \n    for idx, img_path in enumerate(item_files):\n        plt.subplot(1, 6, idx+1)        \n        img = plt.imread(img_path)\n        plt.tight_layout() \n        plt.axis('off')\n        plt.imshow(img, cmap='gray')","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:58.169886Z","iopub.execute_input":"2021-11-02T09:39:58.17016Z","iopub.status.idle":"2021-11-02T09:39:58.176473Z","shell.execute_reply.started":"2021-11-02T09:39:58.170124Z","shell.execute_reply":"2021-11-02T09:39:58.175702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_height = 224\nimg_width = 224\n\ntraining_data_gen = tf.keras.preprocessing.image.ImageDataGenerator(\n                                                                    rescale=1/255.0,\n                                                                    validation_split=0.15)\ntrain_path=\"./training\"\ntrain_generator = training_data_gen.flow_from_directory(train_path,\n                                                        target_size=(img_height, img_width),\n                                                        batch_size=64,\n                                                        shuffle=True,\n                                                        class_mode='binary',\n                                                        subset='training') # set as training data\n\nvalidation_generator = training_data_gen.flow_from_directory(train_path, # same directory as training data\n                                                             target_size=(img_height, img_width),\n                                                             batch_size=64,\n                                                             shuffle=True,\n                                                             class_mode='binary',\n                                                             subset='validation') # set as validation data\n \ntest_path=\"./validation\"\ntesting_data_gen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1/255.0)\n\ntest_generator = testing_data_gen.flow_from_directory(test_path,\n                                                      target_size=(img_height, img_width),\n                                                      batch_size=60,\n                                                      seed=0,\n                                                      shuffle=False,\n                                                      class_mode='binary') ","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:58.177876Z","iopub.execute_input":"2021-11-02T09:39:58.178453Z","iopub.status.idle":"2021-11-02T09:39:59.512875Z","shell.execute_reply.started":"2021-11-02T09:39:58.178373Z","shell.execute_reply":"2021-11-02T09:39:59.510499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img,label=next(train_generator)\nprint(label)\nprint(type(label))","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:59.514699Z","iopub.execute_input":"2021-11-02T09:39:59.515106Z","iopub.status.idle":"2021-11-02T09:39:59.806521Z","shell.execute_reply.started":"2021-11-02T09:39:59.515065Z","shell.execute_reply":"2021-11-02T09:39:59.805707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels=['cat','dog']\nimage = img[1]\nlabel2 = int(label[1])\n\nprint(labels[label2])\nplt.imshow(image)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:39:59.809556Z","iopub.execute_input":"2021-11-02T09:39:59.810117Z","iopub.status.idle":"2021-11-02T09:40:00.038183Z","shell.execute_reply.started":"2021-11-02T09:39:59.810078Z","shell.execute_reply":"2021-11-02T09:40:00.037506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preprocess_image_input(input_images):\n  input_images = input_images.astype('float32')\n  output_ims = tf.keras.applications.resnet50.preprocess_input(input_images)\n  return output_ims\n","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:40:00.039531Z","iopub.execute_input":"2021-11-02T09:40:00.040029Z","iopub.status.idle":"2021-11-02T09:40:00.044486Z","shell.execute_reply.started":"2021-11-02T09:40:00.03999Z","shell.execute_reply":"2021-11-02T09:40:00.043526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def feature_extractor(inputs):\n\n  feature_extractor = tf.keras.applications.resnet.ResNet50(input_shape=(224, 224, 3),\n                                               include_top=False,\n                                               weights='imagenet')(inputs)\n  return feature_extractor","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:40:00.04588Z","iopub.execute_input":"2021-11-02T09:40:00.046395Z","iopub.status.idle":"2021-11-02T09:40:00.053725Z","shell.execute_reply.started":"2021-11-02T09:40:00.04632Z","shell.execute_reply":"2021-11-02T09:40:00.05301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classifier(inputs):\n    x = tf.keras.layers.GlobalAveragePooling2D()(inputs)\n    x = tf.keras.layers.Flatten()(x)\n    x = tf.keras.layers.Dense(1024, activation=\"relu\")(x)\n    x = tf.keras.layers.Dense(512, activation=\"relu\")(x)\n    x = tf.keras.layers.Dense(1, activation=\"sigmoid\", name=\"classification\")(x)\n    return x","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:40:00.05499Z","iopub.execute_input":"2021-11-02T09:40:00.055595Z","iopub.status.idle":"2021-11-02T09:40:00.063174Z","shell.execute_reply.started":"2021-11-02T09:40:00.05556Z","shell.execute_reply":"2021-11-02T09:40:00.062444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def final_model(inputs):\n \n    #resize = tf.keras.layers.UpSampling2D(size=(7,7))(inputs)\n\n    resnet_feature_extractor = feature_extractor(inputs)\n    classification_output = classifier(resnet_feature_extractor)\n\n    return classification_output","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:40:00.064597Z","iopub.execute_input":"2021-11-02T09:40:00.06505Z","iopub.status.idle":"2021-11-02T09:40:00.071375Z","shell.execute_reply.started":"2021-11-02T09:40:00.065012Z","shell.execute_reply":"2021-11-02T09:40:00.070686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def define_compile_model():\n  inputs = tf.keras.layers.Input(shape=(224,224,3))\n  \n  classification_output = final_model(inputs) \n  model = tf.keras.Model(inputs=inputs, outputs = classification_output)\n \n  model.compile(optimizer='SGD', \n                loss=tf.keras.losses.binary_crossentropy,\n                metrics = ['accuracy'])\n  \n  return model","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:40:00.072669Z","iopub.execute_input":"2021-11-02T09:40:00.073075Z","iopub.status.idle":"2021-11-02T09:40:00.080403Z","shell.execute_reply.started":"2021-11-02T09:40:00.07301Z","shell.execute_reply":"2021-11-02T09:40:00.079693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = define_compile_model()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:40:00.081633Z","iopub.execute_input":"2021-11-02T09:40:00.08246Z","iopub.status.idle":"2021-11-02T09:40:04.58521Z","shell.execute_reply.started":"2021-11-02T09:40:00.082424Z","shell.execute_reply":"2021-11-02T09:40:04.58448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:41:29.429127Z","iopub.execute_input":"2021-11-02T09:41:29.429936Z","iopub.status.idle":"2021-11-02T09:41:29.452042Z","shell.execute_reply.started":"2021-11-02T09:41:29.429884Z","shell.execute_reply":"2021-11-02T09:41:29.451307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit(train_generator,validation_data=validation_generator,epochs=50)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T09:45:27.738471Z","iopub.execute_input":"2021-11-02T09:45:27.739264Z","iopub.status.idle":"2021-11-02T11:20:43.242376Z","shell.execute_reply.started":"2021-11-02T09:45:27.739204Z","shell.execute_reply":"2021-11-02T11:20:43.24154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict=model.predict(test_generator)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:20:43.244183Z","iopub.execute_input":"2021-11-02T11:20:43.244431Z","iopub.status.idle":"2021-11-02T11:21:23.485702Z","shell.execute_reply.started":"2021-11-02T11:20:43.244404Z","shell.execute_reply":"2021-11-02T11:21:23.484984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['category'] = np.argmax(predict, axis=-1)\n","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:21:23.487127Z","iopub.execute_input":"2021-11-02T11:21:23.487373Z","iopub.status.idle":"2021-11-02T11:21:23.493827Z","shell.execute_reply.started":"2021-11-02T11:21:23.487338Z","shell.execute_reply":"2021-11-02T11:21:23.492852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_filenames = os.listdir(\"./test\")\ntest_df = pd.DataFrame({\n    'filename': test_filenames\n})\nnb_samples = test_df.shape[0]\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:21:23.496214Z","iopub.execute_input":"2021-11-02T11:21:23.496536Z","iopub.status.idle":"2021-11-02T11:21:23.51618Z","shell.execute_reply.started":"2021-11-02T11:21:23.496501Z","shell.execute_reply":"2021-11-02T11:21:23.515566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_gen = ImageDataGenerator(rescale=1./255)\ntest_generator = test_gen.flow_from_dataframe(\n    test_df, \n    \"./test\", \n    x_col='filename',\n    y_col=None,\n    class_mode=None,\n    batch_size=10,\n    target_size=(224, 224),\n    shuffle=False\n)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:21:23.517152Z","iopub.execute_input":"2021-11-02T11:21:23.517461Z","iopub.status.idle":"2021-11-02T11:21:23.654919Z","shell.execute_reply.started":"2021-11-02T11:21:23.517425Z","shell.execute_reply":"2021-11-02T11:21:23.654076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict = model.predict_generator(test_generator, steps=np.ceil(nb_samples/10))\nthreshold = 0.5\ntest_df['category'] = np.where(predict > threshold, 1,0)","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:21:23.656535Z","iopub.execute_input":"2021-11-02T11:21:23.660223Z","iopub.status.idle":"2021-11-02T11:22:03.037866Z","shell.execute_reply.started":"2021-11-02T11:21:23.660187Z","shell.execute_reply":"2021-11-02T11:22:03.037112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_test = test_df.sample(n=9).reset_index()\nsample_test.head()\nplt.figure(figsize=(12, 12))\nfor index, row in sample_test.iterrows():\n    filename = row['filename']\n    category = row['category']\n    img = load_img(\"./test/\"+filename, target_size=(256, 256))\n    plt.subplot(3, 3, index+1)\n    plt.imshow(img)\n    plt.xlabel(filename + '(' + \"{}\".format(category) + ')')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:28:11.901846Z","iopub.execute_input":"2021-11-02T11:28:11.902552Z","iopub.status.idle":"2021-11-02T11:28:13.310204Z","shell.execute_reply.started":"2021-11-02T11:28:11.902515Z","shell.execute_reply":"2021-11-02T11:28:13.309526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nsubmission_df = test_df.copy()\nsubmission_df['id'] = submission_df['filename'].str.split('.').str[0]\nsubmission_df['label'] = submission_df['category']\nsubmission_df.drop(['filename', 'category'], axis=1, inplace=True)\nsubmission_df.to_csv('submission_13010030.csv', index=False)\n\nplt.figure(figsize=(10,5))\nsns.countplot(submission_df['label'])\nplt.title(\"(Test data)\")","metadata":{"execution":{"iopub.status.busy":"2021-11-02T11:28:28.026575Z","iopub.execute_input":"2021-11-02T11:28:28.027227Z","iopub.status.idle":"2021-11-02T11:28:28.37318Z","shell.execute_reply.started":"2021-11-02T11:28:28.027188Z","shell.execute_reply":"2021-11-02T11:28:28.372469Z"},"trusted":true},"execution_count":null,"outputs":[]}]}