{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.12"},"papermill":{"default_parameters":{},"duration":26.601064,"end_time":"2023-11-13T02:44:18.358611","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2023-11-13T02:43:51.757547","version":"2.4.0"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":45867,"databundleVersionId":6924515,"sourceType":"competition"},{"sourceId":6640479,"sourceType":"datasetVersion","datasetId":3833517},{"sourceId":6746686,"sourceType":"datasetVersion","datasetId":3884593},{"sourceId":6827935,"sourceType":"datasetVersion","datasetId":3926155},{"sourceId":6874344,"sourceType":"datasetVersion","datasetId":3950227},{"sourceId":7259757,"sourceType":"datasetVersion","datasetId":4207197},{"sourceId":7270449,"sourceType":"datasetVersion","datasetId":4214573},{"sourceId":147635265,"sourceType":"kernelVersion"}],"dockerImageVersionId":30627,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"papermill":{"duration":8.038554,"end_time":"2023-11-13T02:44:03.310789","exception":false,"start_time":"2023-11-13T02:43:55.272235","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:02:59.817382Z","iopub.execute_input":"2023-12-28T16:02:59.817945Z","iopub.status.idle":"2023-12-28T16:02:59.827679Z","shell.execute_reply.started":"2023-12-28T16:02:59.817913Z","shell.execute_reply":"2023-12-28T16:02:59.826853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import StratifiedKFold\nfrom sklearn.preprocessing import LabelEncoder\n\n\nfrom torch.utils.data import Dataset, DataLoader\nfrom torch.optim import lr_scheduler\nimport torch.nn.functional as F\nimport torch.optim as optim\nfrom torch.cuda import amp\nimport torch.nn as nn\nimport torchvision\nimport torch\n\n\nfrom albumentations.pytorch import ToTensorV2\nimport albumentations as A\n\n\nfrom collections import defaultdict\nfrom tqdm import tqdm\nfrom PIL import Image\nimport pandas as pd\nimport numpy as np\nimport joblib\nimport random\nimport timm\nimport math\nimport copy\nimport time\nimport glob\nimport cv2\nimport os\nimport gc\n\n\n\nos.environ['CUDA_LAUNCH_BLOCKING'] = \"1\"","metadata":{"execution":{"iopub.status.busy":"2023-12-28T16:02:59.832706Z","iopub.execute_input":"2023-12-28T16:02:59.833356Z","iopub.status.idle":"2023-12-28T16:03:07.172741Z","shell.execute_reply.started":"2023-12-28T16:02:59.833325Z","shell.execute_reply":"2023-12-28T16:03:07.171335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CONFIG = {\n    \"seed\"            : 40,  \n    \"img_size\"        : 2054,  \n    \"model_name\"      : \"tf_efficientnetv2_s_in21ft1k\",  \n    \"num_classes\"     : 5,  \n    \"valid_batch_size\": 4,  \n    \"device\"          : torch.device(\"cuda:0\" \n                                     if torch.cuda.is_available() \n                                     else \"cpu\"), \n}","metadata":{"papermill":{"duration":0.071669,"end_time":"2023-11-13T02:44:03.4033","exception":false,"start_time":"2023-11-13T02:44:03.331631","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:07.174596Z","iopub.execute_input":"2023-12-28T16:03:07.175014Z","iopub.status.idle":"2023-12-28T16:03:07.207489Z","shell.execute_reply.started":"2023-12-28T16:03:07.174957Z","shell.execute_reply":"2023-12-28T16:03:07.206478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_seed(seed=42):\n    np.random.seed(seed) \n    \n    torch.manual_seed(seed)  \n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n    \n    os.environ['PYTHONHASHSEED'] = str(seed)\n    \n    \n    \nset_seed(CONFIG['seed'])","metadata":{"papermill":{"duration":0.019962,"end_time":"2023-11-13T02:44:03.43038","exception":false,"start_time":"2023-11-13T02:44:03.410418","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:07.208748Z","iopub.execute_input":"2023-12-28T16:03:07.209714Z","iopub.status.idle":"2023-12-28T16:03:07.231921Z","shell.execute_reply.started":"2023-12-28T16:03:07.209675Z","shell.execute_reply":"2023-12-28T16:03:07.230477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT_DIR          = '/kaggle/input/UBC-OCEAN'\nTEST_DIR          = '/kaggle/input/UBC-OCEAN/test_thumbnails'\nALT_TEST_DIR      = '/kaggle/input/UBC-OCEAN/test_images'\nModel_predict     = '/kaggle/input/check-ponit007'\nLABEL_ENCODER_BIN = \"/kaggle/input/ubcpytorchwith-classweights-training-fold1of5/label_encoder.pkl\"\nBEST_WEIGHT       = \"/kaggle/input/baseline-0-36/Acc0.70_Loss1.0140_epoch29_tf_efficientnetv2_s_in21ft1k_0.36.bin\"\nBEST_WEIGHT2      = \"/kaggle/input/ubc-efficienetnetb0-fold1of10-2048pix-thumbnails/Recall0.9178_Acc0.9437_Loss0.1685_epoch9.bin\"\nBEST_WEIGHT3      = \"/kaggle/input/ubc-efficienetnetb0-fold1of10-2048pix-thumbnails/Recall0.8858_Acc0.9155_Loss0.2106_epoch1.bin\"\nBEST_WEIGHT4      = \"/kaggle/input/ver-21-10/Acc0.50_Loss1.2095_epoch4.bin\"","metadata":{"papermill":{"duration":0.014908,"end_time":"2023-11-13T02:44:03.452122","exception":false,"start_time":"2023-11-13T02:44:03.437214","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:07.235082Z","iopub.execute_input":"2023-12-28T16:03:07.235702Z","iopub.status.idle":"2023-12-28T16:03:07.24248Z","shell.execute_reply.started":"2023-12-28T16:03:07.235668Z","shell.execute_reply":"2023-12-28T16:03:07.24165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_test_file_path(image_id):\n    if os.path.exists(f\"{TEST_DIR}/{image_id}_thumbnail.png\"):\n        return f\"{TEST_DIR}/{image_id}_thumbnail.png\"\n    else:\n        return f\"{ALT_TEST_DIR}/{image_id}.png\"\n    \n    \ndf = pd.read_csv(f\"{ROOT_DIR}/test.csv\")\ndf['file_path'] = df['image_id'].apply(get_test_file_path)\n# Dummy label for test data\ndf['label'] = 0\ndf.head()","metadata":{"papermill":{"duration":0.015472,"end_time":"2023-11-13T02:44:03.47424","exception":false,"start_time":"2023-11-13T02:44:03.458768","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:07.243542Z","iopub.execute_input":"2023-12-28T16:03:07.243934Z","iopub.status.idle":"2023-12-28T16:03:07.284094Z","shell.execute_reply.started":"2023-12-28T16:03:07.2439Z","shell.execute_reply":"2023-12-28T16:03:07.283215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_cropped_images(file_path, image_id, th_area=1000):\n    sxs, exs, sys, eys = [], [], [], []\n    image = Image.open(file_path)\n    \n    as_ratio = image.size[0] / image.size[1]\n    if as_ratio >= 1.5:\n        mask = np.max(np.array(image) > 0, axis=-1).astype(np.uint8)\n        retval, labels = cv2.connectedComponents(mask)\n        \n        if retval >= as_ratio:\n            x, y = np.meshgrid(np.arange(image.size[0]), np.arange(image.size[1]))\n            \n            for label in range(1, retval):\n                area = np.sum(labels == label)\n                if area < th_area:\n                    continue\n                \n                xs, ys = x[labels == label], y[labels == label]\n                sx, ex = np.min(xs), np.max(xs)\n                cx = (sx + ex) // 2\n                crop_size = image.size[1]\n                sx = max(0, cx - crop_size // 2)\n                ex = min(sx + crop_size - 1, image.size[0] - 1)\n                sx = ex - crop_size + 1\n                sy, ey = 0, image.size[1] - 1\n                sxs.append(sx)\n                exs.append(ex)\n                sys.append(sy)\n                eys.append(ey)\n        \n        else:\n            crop_size = image.size[1]\n            for i in range(int(as_ratio)):\n                sxs.append(i * crop_size)\n                exs.append((i + 1) * crop_size - 1)\n                sys.append(0)\n                eys.append(crop_size - 1)\n    else:\n        sxs, exs, sys, eys = [0,], [image.size[0] - 1], [0,], [image.size[1] - 1]\n\n    df_crop = pd.DataFrame()\n    df_crop[\"image_id\"] = [image_id] * len(sxs)\n    df_crop[\"file_path\"] = [file_path] * len(sxs)\n    df_crop[\"sx\"] = sxs\n    df_crop[\"ex\"] = exs\n    df_crop[\"sy\"] = sys\n    df_crop[\"ey\"] = eys\n    return df_crop\n\n\n\ndfs = []\nfor (file_path, image_id) in zip(df[\"file_path\"], df[\"image_id\"]):\n    dfs.append(get_cropped_images(file_path, image_id))\n\ndf_crop = pd.concat(dfs)\ndf_crop = df_crop.drop_duplicates(subset=[\"image_id\", \"sx\", \"ex\", \"sy\", \"ey\"]).reset_index(drop=True)\ndf_crop[\"label\"] = 0\ndf_crop.head()","metadata":{"papermill":{"duration":0.024171,"end_time":"2023-11-13T02:44:03.607376","exception":false,"start_time":"2023-11-13T02:44:03.583205","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:07.285381Z","iopub.execute_input":"2023-12-28T16:03:07.28573Z","iopub.status.idle":"2023-12-28T16:03:07.991343Z","shell.execute_reply.started":"2023-12-28T16:03:07.285699Z","shell.execute_reply":"2023-12-28T16:03:07.990416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class UBCDataset(Dataset):\n    def __init__(self, df, transforms=None, test = True):\n        self.df = df\n        self.file_names = df['file_path'].values\n        self.labels = df['label'].values\n        self.transforms = transforms\n        self.sxs  = df[\"sx\"].values\n        self.exs  = df[\"ex\"].values\n        self.sys  = df[\"sy\"].values\n        self.eys  = df[\"ey\"].values\n        self.test = test\n        \n    def __len__(self):\n        return len(self.df)\n    \n    def __getitem__(self, index):\n        img_path = self.file_names[index]\n        sx, ex, sy, ey = (self.sxs[index], self.exs[index], \n                          self.sys[index], self.eys[index])\n        \n        img = cv2.imread(img_path)\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n        img = img[sy:ey, sx:ex, :]\n        label = self.labels[index]\n        if self.transforms:\n            img = self.transforms(image=img)[\"image\"]\n        return {\n            'image': img,\n            'label': torch.tensor(label, dtype=torch.long) if self.test else label \n        }","metadata":{"papermill":{"duration":0.020623,"end_time":"2023-11-13T02:44:04.262244","exception":false,"start_time":"2023-11-13T02:44:04.241621","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:07.992576Z","iopub.execute_input":"2023-12-28T16:03:07.992923Z","iopub.status.idle":"2023-12-28T16:03:08.003412Z","shell.execute_reply.started":"2023-12-28T16:03:07.992897Z","shell.execute_reply":"2023-12-28T16:03:08.002336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_transforms = {\n    \"valid\": A.Compose(\n        [A.Resize(CONFIG['img_size'], CONFIG['img_size']),\n         A.Normalize(\n             mean = [0.485, 0.456, 0.406], \n             std  = [0.229, 0.224, 0.225], \n             max_pixel_value = 255.0, \n             p=1.0),\n         ToTensorV2()\n        ], p=1.)\n}","metadata":{"papermill":{"duration":0.01697,"end_time":"2023-11-13T02:44:04.287059","exception":false,"start_time":"2023-11-13T02:44:04.270089","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:08.004795Z","iopub.execute_input":"2023-12-28T16:03:08.005107Z","iopub.status.idle":"2023-12-28T16:03:08.016113Z","shell.execute_reply.started":"2023-12-28T16:03:08.005074Z","shell.execute_reply":"2023-12-28T16:03:08.015323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class GeM(nn.Module):\n    def __init__(self, p=3, eps=1e-6):\n        super(GeM, self).__init__()\n        self.p = nn.Parameter(torch.ones(1) * p)\n        self.eps = eps\n\n    def forward(self, x):\n        return self.gem(x, p=self.p, eps=self.eps)\n        \n    def gem(self, x, p=3, eps=1e-6):\n        return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))).pow(1./p)\n        \n    def __repr__(self):\n        return self.__class__.__name__ + \\\n                '(' + 'p=' + '{:.4f}'.format(self.p.data.tolist()[0]) + \\\n                ', ' + 'eps=' + str(self.eps) + ')'\n","metadata":{"papermill":{"duration":0.019491,"end_time":"2023-11-13T02:44:04.313901","exception":false,"start_time":"2023-11-13T02:44:04.29441","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:08.017145Z","iopub.execute_input":"2023-12-28T16:03:08.017399Z","iopub.status.idle":"2023-12-28T16:03:08.027209Z","shell.execute_reply.started":"2023-12-28T16:03:08.017375Z","shell.execute_reply":"2023-12-28T16:03:08.026339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class UBCModel(nn.Module):\n    def __init__(self, model_name, num_classes, pretrained=False, checkpoint_path=None):\n        super(UBCModel, self).__init__()\n        self.model = timm.create_model(model_name, pretrained=pretrained)\n        in_features = self.model.classifier.in_features\n        \n        self.linear  = nn.Linear(in_features, num_classes)\n        self.model.global_pool = nn.Identity()\n        self.model.classifier = nn.Identity()\n        self.softmax = nn.Softmax(dim=1)\n        self.pooling = GeM()\n        \n\n\n    def forward(self, images):\n        features = self.model(images)\n        pooled_features = self.pooling(features).flatten(1)\n        output = self.linear(pooled_features)\n        return output\n\n    \nmodel  = UBCModel('tf_efficientnetv2_s_in21ft1k', CONFIG['num_classes'])\nmodel2 = UBCModel('tf_efficientnet_b0_ns', CONFIG['num_classes'])\nmodel3 = UBCModel('tf_efficientnet_b0_ns', CONFIG['num_classes'])\nmodel4 = UBCModel('tf_efficientnet_b0_ns', CONFIG['num_classes'])\n\n\nmodel.load_state_dict(torch.load(BEST_WEIGHT))\nmodel2.load_state_dict(torch.load(BEST_WEIGHT2))\nmodel3.load_state_dict(torch.load(BEST_WEIGHT3))\nmodel4.load_state_dict(torch.load(BEST_WEIGHT3))\n\n\nmodel.to(CONFIG['device'])\nmodel2.to(CONFIG['device'])\nmodel3.to(CONFIG['device'])\nmodel4.to(CONFIG['device'])\nprint()","metadata":{"papermill":{"duration":5.537674,"end_time":"2023-11-13T02:44:09.859078","exception":false,"start_time":"2023-11-13T02:44:04.321404","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:08.030833Z","iopub.execute_input":"2023-12-28T16:03:08.031108Z","iopub.status.idle":"2023-12-28T16:03:13.781058Z","shell.execute_reply.started":"2023-12-28T16:03:08.031085Z","shell.execute_reply":"2023-12-28T16:03:13.780037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dataset = UBCDataset(df_crop, transforms=data_transforms[\"valid\"])\n\n\ntest_loader = DataLoader(\n    test_dataset, \n    batch_size  = CONFIG['valid_batch_size'], \n    num_workers = 2,  \n    shuffle     = False,   \n    pin_memory  = True  \n)","metadata":{"papermill":{"duration":0.017005,"end_time":"2023-11-13T02:44:09.884413","exception":false,"start_time":"2023-11-13T02:44:09.867408","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:13.782437Z","iopub.execute_input":"2023-12-28T16:03:13.782818Z","iopub.status.idle":"2023-12-28T16:03:13.788902Z","shell.execute_reply.started":"2023-12-28T16:03:13.782788Z","shell.execute_reply":"2023-12-28T16:03:13.787885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = []\n\nwith torch.no_grad():\n    bar = tqdm(enumerate(test_loader), total=len(test_loader))\n    \n    for step, data in bar:\n        images = data['image'].to(CONFIG[\"device\"], dtype=torch.float)\n        \n        outputs1 = model(images)\n        outputs2 = model2(images)\n        outputs3 = model3(images)\n        outputs4 = model4(images)\n        outputs = 0.66 * (0.34 * outputs4 + 0.7 * outputs2) + 0.322 * (0.4 * outputs1 + 0.6 * outputs3)\n        outputs = model.softmax(outputs)\n        \n        preds.append(outputs.detach().cpu().numpy())\n\n\npreds = np.vstack(preds)\nprint(preds.shape)\npreds","metadata":{"papermill":{"duration":5.8547,"end_time":"2023-11-13T02:44:15.747075","exception":false,"start_time":"2023-11-13T02:44:09.892375","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:13.790103Z","iopub.execute_input":"2023-12-28T16:03:13.790413Z","iopub.status.idle":"2023-12-28T16:03:19.390105Z","shell.execute_reply.started":"2023-12-28T16:03:13.790386Z","shell.execute_reply":"2023-12-28T16:03:19.389035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(preds.shape[-1]):\n    df_crop[f\"cat{i}\"] = preds[:, i]\n\ndf_crop.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-28T16:03:19.391615Z","iopub.execute_input":"2023-12-28T16:03:19.391955Z","iopub.status.idle":"2023-12-28T16:03:19.40961Z","shell.execute_reply.started":"2023-12-28T16:03:19.39191Z","shell.execute_reply":"2023-12-28T16:03:19.408722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub = pd.read_csv(f\"{ROOT_DIR}/sample_submission.csv\")\ndf_sub.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-28T16:03:19.410674Z","iopub.execute_input":"2023-12-28T16:03:19.410948Z","iopub.status.idle":"2023-12-28T16:03:19.430815Z","shell.execute_reply.started":"2023-12-28T16:03:19.410924Z","shell.execute_reply":"2023-12-28T16:03:19.42993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"encoder = joblib.load(LABEL_ENCODER_BIN)\ndict_label = {}\n\nfor image_id, gdf in df_crop.groupby(\"image_id\"):\n    dict_label[image_id] = np.argmax(gdf[[f\"cat{i}\" for i in range(preds.shape[-1])]].values.max(axis=0))\n\n\npreds = np.array([dict_label[image_id] for image_id in df[\"image_id\"].values])\ndf_sub[\"label\"] = encoder.inverse_transform(preds)\ndf_sub.to_csv(\"submission.csv\", index=False)\ndf_sub.head()","metadata":{"papermill":{"duration":0.027482,"end_time":"2023-11-13T02:44:15.783349","exception":false,"start_time":"2023-11-13T02:44:15.755867","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-28T16:03:19.43369Z","iopub.execute_input":"2023-12-28T16:03:19.433962Z","iopub.status.idle":"2023-12-28T16:03:19.456565Z","shell.execute_reply.started":"2023-12-28T16:03:19.43394Z","shell.execute_reply":"2023-12-28T16:03:19.455768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# See Train Images","metadata":{}},{"cell_type":"code","source":"TRAIN_DIR          = '/kaggle/input/UBC-OCEAN/train_thumbnails'\nALT_TRAIN_DIR      = '/kaggle/input/UBC-OCEAN/train_images'\n\ndef get_test_file_path(image_id):\n    if os.path.exists(f\"{TRAIN_DIR}/{image_id}_thumbnail.png\"):\n        return f\"{TRAIN_DIR}/{image_id}_thumbnail.png\"\n    else:\n        return f\"{ALT_TRAIN_DIR}/{image_id}.png\"\n    \n    \ndf = pd.read_csv(f\"{ROOT_DIR}/train.csv\")\ndf['file_path'] = df['image_id'].apply(get_test_file_path)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-28T16:03:19.457516Z","iopub.execute_input":"2023-12-28T16:03:19.457783Z","iopub.status.idle":"2023-12-28T16:03:19.889224Z","shell.execute_reply.started":"2023-12-28T16:03:19.457753Z","shell.execute_reply":"2023-12-28T16:03:19.888267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfs = []\nfor (file_path, image_id) in zip(df[\"file_path\"], df[\"image_id\"]):\n    dfs.append(get_cropped_images(file_path, image_id))\n\ndf_crop = pd.concat(dfs)\ndf_crop = df_crop.drop_duplicates(subset=[\"image_id\", \"sx\", \"ex\", \"sy\", \"ey\"]).reset_index(drop=True)\ndf_crop[\"label\"] = df[\"label\"]\ndf_crop.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-28T16:03:19.890468Z","iopub.execute_input":"2023-12-28T16:03:19.891273Z","iopub.status.idle":"2023-12-28T16:05:26.370758Z","shell.execute_reply.started":"2023-12-28T16:03:19.891237Z","shell.execute_reply":"2023-12-28T16:05:26.369819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\ntrain_dataset = UBCDataset(df_crop, transforms=data_transforms[\"valid\"], test=False)\n\nCNT_SHOW_IMAGES = 10\ncnt = 0\nwith torch.no_grad():\n    bar = tqdm(enumerate(train_dataset), total=len(train_dataset))\n    \n    for step, data in bar:\n        plt.imshow(data['image'].numpy().T[::-1])\n        plt.title(data['label'])\n        plt.show()\n        cnt += 1\n        if cnt > CNT_SHOW_IMAGES:\n            break","metadata":{"execution":{"iopub.status.busy":"2023-12-28T16:05:40.902953Z","iopub.execute_input":"2023-12-28T16:05:40.903293Z","iopub.status.idle":"2023-12-28T16:05:55.556087Z","shell.execute_reply.started":"2023-12-28T16:05:40.903266Z","shell.execute_reply":"2023-12-28T16:05:55.555172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}