{"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":"# !mkdir processed_images\n# !find ../input/rsna-breast-cancer-1024-pngs/ -name \"*\" -exec cp -ruf \"{}\" ./processed_images/ \\;\n!rm ./processed_images\n# !ln -s ../input/rsna-breast-cancer-512-pngs/ ./processed_images\n!ln -s ../input/rsna-mammography-images-as-pngs/images_as_pngs_512/train_images_processed_512/ ./processed_images","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:07:56.383163Z","iopub.execute_input":"2023-02-25T00:07:56.383661Z","iopub.status.idle":"2023-02-25T00:07:58.749575Z","shell.execute_reply.started":"2023-02-25T00:07:56.38361Z","shell.execute_reply":"2023-02-25T00:07:58.747829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p /opt/conda/lib/python3.7/site-packages/nvidia/dali/plugin/\n!cp ../input/rsna-image-preprocessing/RSNA_image_preprocessing.py ./preprocessing.py\n!unzip -o -q ../input/timm-with-dependencies/timm_all -d timm-with-dependencies","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:07:58.75596Z","iopub.execute_input":"2023-02-25T00:07:58.758471Z","iopub.status.idle":"2023-02-25T00:08:38.544574Z","shell.execute_reply.started":"2023-02-25T00:07:58.758422Z","shell.execute_reply":"2023-02-25T00:08:38.543027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --no-index --find-links timm-with-dependencies timm\n!pip install --no-index /kaggle/input/nvidia-dali-wheel/nvidia_dali_nightly_cuda110-1.22.0.dev20221213-6757685-py3-none-manylinux2014_x86_64.whl\n!pip install /kaggle/input/nvidia-dali-wheel/dicomsdl-0.109.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl\n!cp /kaggle/input/modified-pytorchpy/pytorch.py /opt/conda/lib/python3.7/site-packages/nvidia/dali/plugin/pytorch.py\n!pip install --no-index ../input/rsna-python-libraries/pydicom-2.3.1-py3-none-any.whl\n!pip install --no-index ../input/rsna-python-libraries/pylibjpeg-1.4.0-py3-none-any.whl\n!pip install --no-index ../input/rsna-python-libraries/numpy-1.21.6-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl\n!pip install --no-index ../input/rsna-python-libraries/dicomsdl-0.109.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl\n!pip install --no-index ../input/rsna-python-libraries/python_gdcm-3.0.21-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\n!pip install --no-index ../input/rsna-python-libraries/pylibjpeg_libjpeg-1.3.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\n!pip install --no-index ../input/rsna-python-libraries/pylibjpeg_openjpeg-1.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:08:38.551199Z","iopub.execute_input":"2023-02-25T00:08:38.551889Z","iopub.status.idle":"2023-02-25T00:11:33.499162Z","shell.execute_reply.started":"2023-02-25T00:08:38.55184Z","shell.execute_reply":"2023-02-25T00:11:33.497784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pandas as pd\nimport numpy as np\nimport importlib\nimport pydicom\nimport matplotlib.pyplot as plt\nimport gdcm\n\nimportlib.reload(__import__(\"gdcm\"))\n\nfrom pathlib import Path\nfrom gdcm import DataElement\nfrom collections import defaultdict\nfrom fastai.basics import *\nfrom fastai.callback.all import *\nfrom fastai.vision.all import *\nfrom fastai.medical.imaging import *\nfrom sklearn.model_selection import StratifiedKFold\nfrom sklearn.metrics import accuracy_score, f1_score\nfrom pydicom import dcmread\nfrom PIL import Image\nfrom pdb import set_trace\nfrom fastai.tabular.core import *\nfrom fastai.tabular.learner import tabular_learner\n\nfrom timm.models.layers.adaptive_avgmax_pool import SelectAdaptivePool2d\nfrom torch.nn import Flatten\nfrom fastai.metrics import ActivationType\n\n","metadata":{"_uuid":"335b7335-b926-45d0-8de9-d81f870d6a9f","_cell_guid":"1ec149b9-f104-4a70-a25a-ce825992541a","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-02-25T00:11:33.506948Z","iopub.execute_input":"2023-02-25T00:11:33.509661Z","iopub.status.idle":"2023-02-25T00:11:33.536987Z","shell.execute_reply.started":"2023-02-25T00:11:33.50961Z","shell.execute_reply":"2023-02-25T00:11:33.535956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"competition_name = \"rsna-breast-cancer-detection\"\njson = False\nlines = False\nsubset_rows = 10000\nfile_path = f\"/kaggle/input/{competition_name}\"\n\npath = Path(file_path)\ntrain_csv = pd.read_csv(f\"{path}/train.csv\", nrows=subset_rows)\n\n# \"\"\" START https://www.kaggle.com/code/radek1/fast-ai-starter-pack-train-inference/data \"\"\"\n# NUM_EPOCHS = 4\n# NUM_SPLITS = 4\n# RESIZE_TO = (1024, 1024)\n\n# patient_id_any_cancer = train_csv.groupby('patient_id').cancer.max().reset_index()\n# skf = StratifiedKFold(NUM_SPLITS, shuffle=True, random_state=42)\n# splits = list(skf.split(patient_id_any_cancer.patient_id, patient_id_any_cancer.cancer))\n# \"\"\"END\"\"\"\n\n\n# train_csv.head()","metadata":{"_uuid":"97aad611-eecb-4117-b5cf-853cb59c099d","_cell_guid":"dedef351-d1a9-41b4-a977-bf3ccaabdca4","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-02-25T00:11:33.541569Z","iopub.execute_input":"2023-02-25T00:11:33.543929Z","iopub.status.idle":"2023-02-25T00:11:33.568368Z","shell.execute_reply.started":"2023-02-25T00:11:33.543887Z","shell.execute_reply":"2023-02-25T00:11:33.567394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(len(train_csv.iloc[np.where(train_csv.loc[:,'cancer'])]))\n# print(len(train_csv))\n","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.572746Z","iopub.execute_input":"2023-02-25T00:11:33.575633Z","iopub.status.idle":"2023-02-25T00:11:33.581541Z","shell.execute_reply.started":"2023-02-25T00:11:33.575583Z","shell.execute_reply":"2023-02-25T00:11:33.580254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# NUM_SPLITS = 2\n# from sklearn.model_selection import StratifiedKFold\n# patient_id_any_cancer = train_csv.groupby('patient_id').cancer.max().reset_index()\n# skf = StratifiedKFold(NUM_SPLITS, shuffle=True, random_state=42)\n# splits = list(skf.split(patient_id_any_cancer.patient_id, patient_id_any_cancer.cancer))","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.586621Z","iopub.execute_input":"2023-02-25T00:11:33.589193Z","iopub.status.idle":"2023-02-25T00:11:33.595393Z","shell.execute_reply.started":"2023-02-25T00:11:33.589155Z","shell.execute_reply":"2023-02-25T00:11:33.594332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# splits[0]","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.598834Z","iopub.execute_input":"2023-02-25T00:11:33.600121Z","iopub.status.idle":"2023-02-25T00:11:33.646346Z","shell.execute_reply.started":"2023-02-25T00:11:33.600081Z","shell.execute_reply":"2023-02-25T00:11:33.64284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id_column = train_csv.columns.get_loc('patient_id')\nimage_id_column = train_csv.columns.get_loc('image_id')\ncancer_column = train_csv.columns.get_loc('cancer')","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:13:24.185524Z","iopub.execute_input":"2023-02-25T00:13:24.186042Z","iopub.status.idle":"2023-02-25T00:13:24.195181Z","shell.execute_reply.started":"2023-02-25T00:13:24.185999Z","shell.execute_reply":"2023-02-25T00:13:24.194035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# view_column = train_csv.columns.get_loc('view')\n# age_column = train_csv.columns.get_loc('age')\n# biopsy_column = train_csv.columns.get_loc('biopsy')\n# invasive_column = train_csv.columns.get_loc('invasive')\n# birads_column = train_csv.columns.get_loc('BIRADS')\n# implant_column = train_csv.columns.get_loc('implant')\n# difficult_negative_case_column = train_csv.columns.get_loc('difficult_negative_case')\n\n# view_vocab = train_csv.iloc[:,view_column].unique()\n# age_vocab = train_csv.iloc[:,age_column].unique()\n# biopsy_vocab = train_csv.iloc[:,biopsy_column].unique()\n# invasive_vocab = train_csv.iloc[:,invasive_column].unique()\n# # birads_vocab = train_csv.iloc[:,birads_column].unique()\n# implant_vocab = train_csv.iloc[:,implant_column].unique()\n# difficult_negative_case_vocab = train_csv.iloc[:,difficult_negative_case_column].unique()\n\n# blocks = (\n#     CategoryBlock(vocab=view_vocab), \n#     CategoryBlock(vocab=age_vocab), \n#     CategoryBlock(vocab=biopsy_vocab),\n#     CategoryBlock(vocab=invasive_vocab), \n#     #           CategoryBlock(vocab=birads_vocab), \n#     CategoryBlock(vocab=implant_vocab),\n#     CategoryBlock(vocab=difficult_negative_case_vocab),\n#     CategoryBlock(vocab=[0,1])\n# )\n\n# getters = [\n#     ColReader(view_column),\n#     ColReader(age_column),\n#     ColReader(biopsy_column),\n#     ColReader(invasive_column),\n# #     ColReader(birads_column),\n#     ColReader(implant_column),\n#     ColReader(difficult_negative_case_column),\n#     ColReader(cancer_column)    \n# ]","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.655932Z","iopub.status.idle":"2023-02-25T00:11:33.658434Z","shell.execute_reply.started":"2023-02-25T00:11:33.658155Z","shell.execute_reply":"2023-02-25T00:11:33.658182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.device('cuda')","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:13:26.723872Z","iopub.execute_input":"2023-02-25T00:13:26.724355Z","iopub.status.idle":"2023-02-25T00:13:26.735875Z","shell.execute_reply.started":"2023-02-25T00:13:26.724316Z","shell.execute_reply":"2023-02-25T00:13:26.734852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id_column = train_csv.columns.get_loc('patient_id')\nimage_id_column = train_csv.columns.get_loc('image_id')\ncancer_column = train_csv.columns.get_loc('cancer')\n\n\ndef get_x(x):\n    return f\"../input/rsna-breast-cancer-detection/train_images/{x[patient_id_column]}/{x[image_id_column]}.dcm\"\n#     return f\"./processed_images/{x[patient_id_column]}/{x[image_id_column]}.png\"\n\ndef get_y(y):\n    return y[cancer_column]\n\n\ncancer = DataBlock(\n        blocks=(\n            ImageBlock(cls=PILDicom),\n            CategoryBlock\n        ),\n        get_x=get_x,\n        get_y=get_y,\n        splitter=RandomSplitter(),\n        item_tfms=[Resize(224, resamples= (Image.Resampling.NEAREST,0))],\n        batch_tfms=[\n            IntToFloatTensor(div=2**16-1),\n            \n            *aug_transforms(size=224),\n            Normalize.from_stats(*imagenet_stats)\n        ]\n    )\n\n\ndls = cancer.dataloaders(train_csv.values, num_workers=0) \n# dls.device = \"cpu\"\ndls.show_batch(max_n=32, nrows=8, unique=True)","metadata":{"_uuid":"50377e80-7a03-4441-82f0-dacae3ff3c46","_cell_guid":"5820b86c-70da-4182-a4c0-254d0a45cf42","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-02-25T00:13:27.603932Z","iopub.execute_input":"2023-02-25T00:13:27.604426Z","iopub.status.idle":"2023-02-25T00:14:01.481255Z","shell.execute_reply.started":"2023-02-25T00:13:27.604387Z","shell.execute_reply":"2023-02-25T00:14:01.480163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# download https://download.pytorch.org/models/resnet34-b627a593.pth & upload as data source / https://www.kaggle.com/datasets/pytorch/resnet34\nimport os\nif not os.path.exists('/root/.cache/torch/hub/checkpoints/'):\n        os.makedirs('/root/.cache/torch/hub/checkpoints/')\n!cp '../input/resnet34/resnet34.pth' '/root/.cache/torch/hub/checkpoints/resnet34-b627a593.pth'\n!cp '../input/pytorch-pretrained/resnet18-f37072fd.pth' '/root/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth'\n!cp '../input/fastai017-whl/tf_efficientnetv2_s-eb54923e.pth' '/root/.cache/torch/hub/checkpoints/tf_efficientnetv2_s-eb54923e.pth'\n!cp '/kaggle/input/timm-pretrained-efficientnet/efficientnet/efficientnet_b0_ra-3dd342df.pth' '/root/.cache/torch/hub/checkpoints/efficientnet_b0_ra-3dd342df.pth'\n!cp '/kaggle/input/timm-pretrained-efficientnet/efficientnet/efficientnet_lite0_ra-37913777.pth' '/root/.cache/torch/hub/checkpoints/efficientnet_lite0_ra-37913777.pth'","metadata":{"_uuid":"0beb0796-a356-41ce-9ba2-5a24a603876d","_cell_guid":"1c45a99b-42e4-4694-9321-f008d1910356","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-02-25T00:14:01.483565Z","iopub.execute_input":"2023-02-25T00:14:01.484286Z","iopub.status.idle":"2023-02-25T00:14:11.199191Z","shell.execute_reply.started":"2023-02-25T00:14:01.484245Z","shell.execute_reply":"2023-02-25T00:14:11.19756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#https://www.kaggle.com/competitions/rsna-breast-cancer-detection/discussion/369267  \ndef pfbeta_torch(preds, labels, beta=.5):\n    if preds.dim() != 2 or (preds.dim() == 2 and preds.shape[1] !=2): raise ValueError('Houston, we got a problem')\n    preds = preds[:, 1]\n    preds = preds.clip(0, 1)\n    y_true_count = labels.sum()\n    ctp = preds[labels==1].sum()\n    cfp = preds[labels==0].sum()\n    beta_squared = beta * beta\n    c_precision = ctp / (ctp + cfp)\n    c_recall = ctp / y_true_count\n    if (c_precision > 0 and c_recall > 0):\n        result = (1 + beta_squared) * (c_precision * c_recall) / (beta_squared * c_precision + c_recall)\n        return result\n    else:\n        return 0.0\n\n# https://www.kaggle.com/competitions/rsna-breast-cancer-detection/discussion/369886    \ndef pfbeta_torch_thresh(preds, labels):\n    optimized_preds = optimize_preds(preds, labels)\n    return pfbeta_torch(optimized_preds, labels)\n\ndef optimize_preds(preds, labels=None, thresh=None, return_thresh=False, print_results=False):\n    preds = preds.clone()\n    if labels is not None: without_thresh = pfbeta_torch(preds, labels)\n    \n    if not thresh and labels is not None:\n        threshs = np.linspace(0, 1, 101)\n        f1s = [pfbeta_torch((preds > thr).float(), labels) for thr in threshs]\n        idx = np.argmax(f1s)\n        thresh, best_pfbeta = threshs[idx], f1s[idx]\n\n    preds = (preds > thresh).float()\n\n    if print_results:\n        print(f'without optimization: {without_thresh}')\n        pfbeta = pfbeta_torch(preds, labels)\n        print(f'with optimization: {pfbeta}')\n        print(f'best_thresh = {thresh}')\n    if return_thresh:\n        return thresh\n    return preds\n\nfn2label = {fn: cancer_or_not for fn, cancer_or_not in zip(train_csv['image_id'].astype('str'), train_csv['cancer'])}\n\ndef splitting_func(paths):\n    train = []\n    valid = []\n    for idx, path in enumerate(paths):\n        if int(path.parent.name) in patient_id_any_cancer.iloc[splits[SPLIT][0]].patient_id.values:\n            train.append(idx)\n        else:\n            valid.append(idx)\n    return train, valid\n\ndef label_func(path):\n    return fn2label[path.stem]\n\ndef get_items(image_dir_path):\n    items = []\n    for p in get_image_files(image_dir_path):\n        items.append(p)\n        if p.stem in fn2label and int(p.parent.name) in patient_id_any_cancer.iloc[splits[SPLIT][0]].patient_id.values:\n            if label_func(p) == 1:\n                for _ in range(5):\n                    items.append(p)\n    return items\n\ndef pfbeta_torch_tabular(preds, labels):\n    labels = labels.squeeze(1)\n    return pfbeta_torch(preds, labels)\n\ndef pfbeta_torch_thresh_tabular(preds, labels):\n    labels = labels.squeeze(1)\n    return pfbeta_torch_thresh(preds, labels)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:14:11.205107Z","iopub.execute_input":"2023-02-25T00:14:11.207521Z","iopub.status.idle":"2023-02-25T00:14:11.243694Z","shell.execute_reply.started":"2023-02-25T00:14:11.207472Z","shell.execute_reply":"2023-02-25T00:14:11.241468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# learn_tab = tabular_learner(\n#     tabular_dls,\n# #     layers=[1000,500],\n# #     emb_szs=[600],\n#     metrics=[\n#         error_rate,\n#         AccumMetric(pfbeta_torch_tabular, activation=ActivationType.Softmax, flatten=False),\n#         AccumMetric(pfbeta_torch_thresh_tabular, activation=ActivationType.Softmax, flatten=False)\n#     ],\n#     loss_func=CrossEntropyLossFlat(weight=torch.tensor([1,50]).float())\n# )\n# learn_tab.lr_find()\n# learn_tab.fit_one_cycle(3)\n# learn_tab.lr_find()\n# learn_tab.fit_one_cycle(3)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.67738Z","iopub.status.idle":"2023-02-25T00:11:33.68295Z","shell.execute_reply.started":"2023-02-25T00:11:33.682676Z","shell.execute_reply":"2023-02-25T00:11:33.682702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# interp_tab = ClassificationInterpretation.from_learner(learn_tab)\n# interp_tab.plot_confusion_matrix()","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.684409Z","iopub.status.idle":"2023-02-25T00:11:33.685195Z","shell.execute_reply.started":"2023-02-25T00:11:33.684917Z","shell.execute_reply":"2023-02-25T00:11:33.684941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from timm.models.layers.adaptive_avgmax_pool import SelectAdaptivePool2d\nfrom torch.nn import Flatten\nfrom fastai.metrics import ActivationType\n\nlearn = vision_learner(\n    dls,\n    resnet34,\n    \n#     custom_head=nn.Sequential(SelectAdaptivePool2d(pool_type='avg', flatten=Flatten()), nn.Linear(512, 2)),\n    metrics=[\n        error_rate,\n        AccumMetric(pfbeta_torch, activation=ActivationType.Softmax, flatten=False),\n        AccumMetric(pfbeta_torch_thresh, activation=ActivationType.Softmax, flatten=False)\n    ],\n    loss_func=CrossEntropyLossFlat(),\n    pretrained=True,\n    normalize=True\n#     lr=0.001\n).to_fp16()\n\n\n# learn = synth_learner(n_trn=2, metrics=F.mse_loss)\n# learn.fit(n_epoch=200, lr=1e-7, cbs=EarlyStoppingCallback(monitor='mse_loss', min_delta=0.1, patience=2))\n# learn.lr_find()\nlearn.model.cuda()\nlearn.fine_tune(1)\n# learn.fine_tune()\nlearn.export('learner.pkl')","metadata":{"_uuid":"21bfb103-8d1e-4de5-a8d2-822b0c50d47b","_cell_guid":"42d453de-859e-4cc7-827a-4fdeb9cb2b37","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2023-02-25T00:14:11.249655Z","iopub.execute_input":"2023-02-25T00:14:11.252205Z","iopub.status.idle":"2023-02-25T00:15:47.832056Z","shell.execute_reply.started":"2023-02-25T00:14:11.252164Z","shell.execute_reply":"2023-02-25T00:15:47.825811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# learn.model.cuda()\n# # print(dir(learn.model))\n# # learn.unfreeze()\n# learn.model.cuda()\n# learn.fine_tune(1)\n# # learn.fit_one_cycle(4, 1e-4, pct_start=0.1)\n# # learn.export('learner.pkl')","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.688951Z","iopub.status.idle":"2023-02-25T00:11:33.696327Z","shell.execute_reply.started":"2023-02-25T00:11:33.69606Z","shell.execute_reply":"2023-02-25T00:11:33.696087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# RESIZE_TO = (1024, 1024)\n# preds_all = []\n\n# # test_dl = learn.dls.test_dl())\n# for SPLIT in range(NUM_SPLITS):\n# #     learn.load(f'{MODEL_PATH}/{SPLIT}')\n#     preds, _ = learn.get_preds(dl=test_dl)\n#     preds_all.append(preds)\n#     preds = torch.zeros_like(preds_all[0])\n\n# for pred in preds_all:\n#     preds += pred\n\n# preds /= NUM_SPLITS\n# preds = optimize_preds(preds, thresh=threshold)\n# image_ids = [path.stem for path in test_dl.items]\n\n# image_id2pred = defaultdict(lambda: 0)\n# for image_id, pred in zip(image_ids, preds[:, 1]):\n#     image_id2pred[int(image_id)] = pred.item()","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.697779Z","iopub.status.idle":"2023-02-25T00:11:33.698555Z","shell.execute_reply.started":"2023-02-25T00:11:33.698293Z","shell.execute_reply":"2023-02-25T00:11:33.698317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"interp = ClassificationInterpretation.from_learner(learn)\ninterp.plot_confusion_matrix()a","metadata":{"execution":{"iopub.status.busy":"2023-02-25T00:11:33.700011Z","iopub.status.idle":"2023-02-25T00:11:33.700785Z","shell.execute_reply.started":"2023-02-25T00:11:33.700512Z","shell.execute_reply":"2023-02-25T00:11:33.700536Z"},"trusted":true},"execution_count":null,"outputs":[]}]}