{"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 sys\nsys.path.append('../input/timm-pytorch-image-models/pytorch-image-models-master')\nimport timm\n!conda install '/kaggle/input/pydicom-conda-helper/libjpeg-turbo-2.1.0-h7f98852_0.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/libgcc-ng-9.3.0-h2828fa1_19.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/gdcm-2.8.9-py37h500ead1_1.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/conda-4.10.1-py37h89c1867_0.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/certifi-2020.12.5-py37h89c1867_1.tar.bz2' -c conda-forge -y\n!conda install '/kaggle/input/pydicom-conda-helper/openssl-1.1.1k-h7f98852_0.tar.bz2' -c conda-forge -y\n!cp -r ../input/valid-siim-mmdetection-uni20-08-101/* ./\n!pip install ./cache/typing_extensions-3.10.0.0-py3-none-any.whl\n# !pip install ./cache/numpy-1.20.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl\n!pip install ./cache/Pillow-8.2.0-cp37-cp37m-manylinux1_x86_64.whl\n!pip install ./cache/torch-1.7.1-cp37-cp37m-manylinux1_x86_64.whl\n!pip install ./cache/torchvision-0.8.2-cp37-cp37m-manylinux1_x86_64.whl\n!pip install ./cache/addict-2.4.0-py3-none-any.whl\n!pip install ./cache/PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl\n!pip install ./cache/yapf-0.31.0-py2.py3-none-any.whl\n!pip install ./cache/mmcv_full-1.3.0-cp37-cp37m-manylinux1_x86_64.whl\n!pip install ./cache/mmpycocotools-12.0.3.tar.gz\n!pip install -e .\n!pip install ./cache/Pillow-7.0.0-cp37-cp37m-manylinux1_x86_64.whl\nimport sys\nsys.path = ['../input/timm-pytorch-image-models/pytorch-image-models-master',\n    '../input/smp20210127/segmentation_models.pytorch-master/segmentation_models.pytorch-master/',\n    '../input/smp20210127/EfficientNet-PyTorch-master/EfficientNet-PyTorch-master',\n    '../input/smp20210127/pretrained-models.pytorch-master/pretrained-models.pytorch-master',\n] + sys.path\n#     '../input/smp20210127/pytorch-image-models-master/pytorch-image-models-master',","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-07-24T19:07:48.023601Z","iopub.execute_input":"2021-07-24T19:07:48.023888Z","iopub.status.idle":"2021-07-24T19:15:08.190789Z","shell.execute_reply.started":"2021-07-24T19:07:48.023822Z","shell.execute_reply":"2021-07-24T19:15:08.189769Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install ../input/weightedboxesfusion/.","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:15:08.192599Z","iopub.execute_input":"2021-07-24T19:15:08.192961Z","iopub.status.idle":"2021-07-24T19:15:35.153251Z","shell.execute_reply.started":"2021-07-24T19:15:08.192921Z","shell.execute_reply":"2021-07-24T19:15:35.1522Z"},"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)\nimport os\nimport pydicom\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nimport cv2\nimport glob\nfrom joblib import Parallel, delayed\nfrom tqdm.auto import tqdm\nimport datetime\nimport json","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:15:35.157Z","iopub.execute_input":"2021-07-24T19:15:35.157423Z","iopub.status.idle":"2021-07-24T19:15:35.497203Z","shell.execute_reply.started":"2021-07-24T19:15:35.157373Z","shell.execute_reply":"2021-07-24T19:15:35.496309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir tmp","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:15:35.498661Z","iopub.execute_input":"2021-07-24T19:15:35.498968Z","iopub.status.idle":"2021-07-24T19:15:36.172516Z","shell.execute_reply.started":"2021-07-24T19:15:35.498935Z","shell.execute_reply":"2021-07-24T19:15:36.171427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def histeq(im,nbr_bins=256):\n    #get image histogram\n    imhist,bins = np.histogram(im.flatten(),nbr_bins,density=True)\n    cdf = imhist.cumsum() #cumulative distribution function\n    cdf = 255 * cdf / cdf[-1] #normalize\n\n    #use linear interpolation of cdf to find new pixel values\n    im2 = np.interp(im.flatten(),bins[:-1],cdf)\n\n    return im2.reshape(im.shape)\ndef write_dicom_image(image_file, voi_lut=True, fix_monochrome=True,hist_eq=True,fix_limits=0):\n    name = image_file.split(\"/\")[-1].split(\".d\")[0]\n    s_id = image_file.split(\"/\")[-3]\n    dicom = pydicom.read_file(image_file)\n    # VOI LUT (if available by DICOM device) is used to\n    # transform raw DICOM data to \"human-friendly\" view\n    if voi_lut:\n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n    # depending on this value, X-ray may look inverted - fix that:\n    if fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        data = np.amax(data) - data\n    data =histeq(data) if hist_eq else data\n    if fix_limits==0:\n        data = data - np.min(data)\n        data = data / np.max(data)\n    else:\n        data_min=data.min()\n        data_max=data.max()\n        mid=(data!=data_min)&(data!=data_max)\n        dmean=data[mid].mean()\n        dstd=data[mid].std()\n        data_min = max(dmean-fix_limits*dstd,data.min())\n        data_max = min(dmean+fix_limits*dstd,data.max())\n        data = (data-data_min)/(data_max-data_min)\n    data = (np.clip(0,1,data) * 255).astype(np.uint8)\n#     image = np.stack([data,data,data],-1)\n    cv2.imwrite(f\"./tmp/{name}.jpg\",data)\n    return [name,0,0,1,1,\"Lung\",0,data.shape[0],data.shape[1],-1,s_id+\"_study\"]\ndef test2coco(df_annotations,labels = [\"Lung\",\"Covid_Abnormality\"],test_out_file = f'test.json'):\n    ''''\n    image_id\txmin\tymin\txmax\tymax\tclass\tclass_id\twidth\theight\tfold\n    '''\n    now = datetime.datetime.now()\n\n    data = dict(\n        info=dict(\n            description='SIIM Covid-19',\n            url=None,\n            version=None,\n            year=now.year,\n            contributor=None,\n            date_created=now.strftime('%Y-%m-%d %H:%M:%S.%f'),\n        ),\n        licenses=[dict(\n            url=None,\n            id=0,\n            name=None,\n        )],\n        images=[\n            # license, url, file_name, height, width, date_captured, id\n        ],\n        type='instances',\n        annotations=[\n            # segmentation, area, iscrowd, image_id, bbox, category_id, id\n        ],\n        categories=[\n            # supercategory, id, name\n        ],\n    )\n\n\n    class_name_to_id = {}\n\n    for i, each_label in enumerate(labels):\n        class_id = i  # starts with -1\n        class_name = each_label\n        if class_id == -1:\n            assert class_name == '__ignore__'\n            continue\n        class_name_to_id[class_name] = class_id\n        data['categories'].append(dict(\n            supercategory=None,\n            id=class_id,\n            name=class_name,\n        ))\n\n    train_ids = df_annotations.image_id.unique()\n    data_train = data.copy()\n    data_train['images'] = []\n    data_train['annotations'] = []\n    for i, img_id in tqdm(enumerate(train_ids), total=len(train_ids)):\n        W, H = df_annotations[df_annotations.image_id == img_id][['width', 'height']].values[0]\n        data_train['images'].append(dict(license=0,\n                                         url=None,\n                                         file_name=img_id + '.jpg',\n                                         height=int(H),\n                                         width=int(W),\n                                         date_captured=None,\n                                         id=i\n                                         ))\n\n        img_annotations = df_annotations[df_annotations.image_id == img_id]\n        boxes = img_annotations[['xmin', 'ymin', 'xmax', 'ymax']].to_numpy()\n        box_labels = img_annotations['class_id']\n\n        for box, label in zip(boxes, box_labels):\n            x_min, y_min, x_max, y_max = (box[0], box[1], box[2], box[3])\n            area = round((x_max - x_min) * (y_max - y_min), 1)\n            bbox = [\n                int(x_min),\n                int(y_min),\n                int(x_max - x_min),\n                int(y_max - y_min)\n            ]\n\n            data_train['annotations'].append(dict(id=len(data_train['annotations']),\n                                                  image_id=i,\n                                                  category_id=int(label),\n                                                  area=int(area),\n                                                  bbox=bbox,\n                                                  iscrowd=0))\n    with open(test_out_file, 'w') as f:\n        json.dump(data_train, f, indent=4)\n    print(f\"save {test_out_file}\")","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:15:36.176036Z","iopub.execute_input":"2021-07-24T19:15:36.17633Z","iopub.status.idle":"2021-07-24T19:15:36.202599Z","shell.execute_reply.started":"2021-07-24T19:15:36.176299Z","shell.execute_reply":"2021-07-24T19:15:36.201542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"paths = glob.glob(\"../input/siim-covid19-detection/test/*/*/*.*\")\nif len(paths) < 2000:\n    paths = paths[0:12]\n    print(\"DEBUG\")\ndf = Parallel(n_jobs=4)(delayed(write_dicom_image)(p) for p in tqdm(paths))\ndf_annotations = pd.DataFrame(df,columns=['image_id','xmin','ymin','xmax','ymax','class','class_id','width','height','fold',\"s_id\"])\ntest2coco(df_annotations)\ndf_annotations.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:15:36.204115Z","iopub.execute_input":"2021-07-24T19:15:36.204565Z","iopub.status.idle":"2021-07-24T19:15:51.983856Z","shell.execute_reply.started":"2021-07-24T19:15:36.204526Z","shell.execute_reply":"2021-07-24T19:15:51.982698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Yuval models","metadata":{}},{"cell_type":"code","source":"image_size = 1024\n# models_path1 = glob.glob(\"../input/molecular-classification-trained/*v7.2*.pth\")\n# models_path2 = glob.glob(\"../input/molecular-classification-trained/*v5.3*.pth\")\n# models_path = glob.glob(\"../input/molecular-classification-trained/*v7.2*.pth\")\n\n# models_path = models_path1 + models_path2\nmodels_path = [\"../input/molecular-classification-trained/tf_efficientnet_b5_ns_1024_8153_v7.2_s0.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b5_ns_1024_8153_v7.2_s1.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b5_ns_1024_8153_v7.2_s2.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b5_ns_1024_8153_v7.2_s3.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b5_ns_1024_8153_v7.2_s4.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b6_ns_1024_8153_v7.2_s0.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b6_ns_1024_8153_v7.2_s1.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b6_ns_1024_8153_v7.2_s2.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b6_ns_1024_8153_v7.2_s3.pth\",\n              \"../input/molecular-classification-trained/tf_efficientnet_b6_ns_1024_8153_v7.2_s4.pth\"]\n\nprint(models_path)\nclasses=4","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:11.631311Z","iopub.execute_input":"2021-07-24T19:16:11.631732Z","iopub.status.idle":"2021-07-24T19:16:11.638641Z","shell.execute_reply.started":"2021-07-24T19:16:11.631692Z","shell.execute_reply":"2021-07-24T19:16:11.637516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings(action='once')\nimport matplotlib.pylab as plt\nimport seaborn as sns\nimport datetime\nfrom IPython.core.interactiveshell import InteractiveShell\nInteractiveShell.ast_node_interactivity = \"all\"\nimport pickle\n%matplotlib inline\nimport torch\nimport torch.nn as nn\nimport torch.utils.data as D\nimport torch.nn.functional as F\nimport copy\nfrom types import MethodType\nimport timm\nimport os\nfrom torch.utils.data import TensorDataset, DataLoader, Dataset\nimport albumentations \nimport random","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:14.037375Z","iopub.execute_input":"2021-07-24T19:16:14.037738Z","iopub.status.idle":"2021-07-24T19:16:15.588456Z","shell.execute_reply.started":"2021-07-24T19:16:14.037706Z","shell.execute_reply":"2021-07-24T19:16:15.587634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = 'cuda:0'\n# torch.cuda.set_device(device)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:16.90692Z","iopub.execute_input":"2021-07-24T19:16:16.907368Z","iopub.status.idle":"2021-07-24T19:16:16.914613Z","shell.execute_reply.started":"2021-07-24T19:16:16.907329Z","shell.execute_reply":"2021-07-24T19:16:16.913384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def set_seed(seed):\n    \"\"\"Sets the random seeds.\"\"\"\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n    os.environ['PYTHONHASHSEED'] = str(seed)\nset_seed(8153)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:17.199161Z","iopub.execute_input":"2021-07-24T19:16:17.199447Z","iopub.status.idle":"2021-07-24T19:16:17.206865Z","shell.execute_reply.started":"2021-07-24T19:16:17.199418Z","shell.execute_reply":"2021-07-24T19:16:17.205771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class XRAYDatasetCLS(Dataset):\n\n    def __init__(self, names, mode='train', path=None, transform=None):\n        assert mode in ['train','test']\n        self.names = names\n        self.mode = mode\n        self.transform = transform\n        self.path = path\n\n    def __len__(self):\n        return len(self.names)\n\n    def __getitem__(self, index):\n        name = self.names[index]\n        image = cv2.imread(self.path+name,0)\n        image = np.stack([image,image,image],-1)\n        res = self.transform(image=image)\n        image = res['image'].astype(np.float32).transpose(2, 0, 1) / 255.\n        return torch.tensor(image)\n    \ntransforms_tta = albumentations.Compose([\n    albumentations.LongestMaxSize(max_size=image_size),\n    albumentations.PadIfNeeded(image_size,image_size),])","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:19.264638Z","iopub.execute_input":"2021-07-24T19:16:19.264969Z","iopub.status.idle":"2021-07-24T19:16:19.274357Z","shell.execute_reply.started":"2021-07-24T19:16:19.26494Z","shell.execute_reply":"2021-07-24T19:16:19.27209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model(path,classes=4):\n    print(path.split(\"/\")[-1].split(\"_1024\")[0])\n    model=timm.create_model(path.split(\"/\")[-1].split(\"_1024\")[0], False)\n    model.reset_classifier(classes)\n    model=nn.DataParallel(model)\n    model.load_state_dict(torch.load(path,map_location='cpu'))\n    model=model.to(device).eval()\n    return model","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:21.267389Z","iopub.execute_input":"2021-07-24T19:16:21.267752Z","iopub.status.idle":"2021-07-24T19:16:21.274878Z","shell.execute_reply.started":"2021-07-24T19:16:21.267719Z","shell.execute_reply":"2021-07-24T19:16:21.274027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class model_ensemble:\n    def __init__(self,model_path,w=[0.25,0.25,0.25,0.25]):\n        self.models = []\n        self.w = w\n        for path in model_path:\n            self.models.append(get_model(path))\n    def __call__(self,x):\n        x  = x.cuda().float()\n        y = []\n        with torch.no_grad():\n            for i,m in enumerate(self.models):\n                if i==0:\n                    y = self.w[i]*m(x)\n                else:\n                    y+=self.w[i]*m(x)\n        return y","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:23.164999Z","iopub.execute_input":"2021-07-24T19:16:23.165324Z","iopub.status.idle":"2021-07-24T19:16:23.171397Z","shell.execute_reply.started":"2021-07-24T19:16:23.165292Z","shell.execute_reply":"2021-07-24T19:16:23.170618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sum([0.1]*5 + [0.05]*10)\n# sum([0.15]*5 + [0.025]*10)\nsum([0.08]*10 + [0.04]*5)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:23.498847Z","iopub.execute_input":"2021-07-24T19:16:23.499161Z","iopub.status.idle":"2021-07-24T19:16:23.504951Z","shell.execute_reply.started":"2021-07-24T19:16:23.499131Z","shell.execute_reply":"2021-07-24T19:16:23.503783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = model_ensemble(models_path, np.ones([len(models_path)])/len(models_path)) # ","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:16:39.128168Z","iopub.execute_input":"2021-07-24T19:16:39.128549Z","iopub.status.idle":"2021-07-24T19:17:34.990764Z","shell.execute_reply.started":"2021-07-24T19:16:39.128515Z","shell.execute_reply":"2021-07-24T19:17:34.989892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"names = os.listdir(\"./tmp/\")\ntta_ds=XRAYDatasetCLS(names = names,transform=transforms_tta,mode='train',path=\"./tmp/\")\ndl=D.DataLoader(tta_ds,num_workers=4,batch_size=6,shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:17:38.938313Z","iopub.execute_input":"2021-07-24T19:17:38.938668Z","iopub.status.idle":"2021-07-24T19:17:38.945949Z","shell.execute_reply.started":"2021-07-24T19:17:38.938637Z","shell.execute_reply":"2021-07-24T19:17:38.945013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PREDS = []\nwith torch.no_grad():\n    for im in tqdm(dl):\n        logits = model(im)\n        for row in logits:\n            PREDS += [row.softmax(0).detach().cpu().reshape(1,-1)]\n    test_preds = torch.cat(PREDS).cpu().numpy()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:17:40.158118Z","iopub.execute_input":"2021-07-24T19:17:40.15846Z","iopub.status.idle":"2021-07-24T19:17:59.444188Z","shell.execute_reply.started":"2021-07-24T19:17:40.158428Z","shell.execute_reply":"2021-07-24T19:17:59.443005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"names = [row.split(\".\")[0]+\"_image\" for row in names]\ndf_study = pd.DataFrame(test_preds,columns=['Negative for Pneumonia','Typical Appearance','Indeterminate Appearance','Atypical Appearance'])\ndf_study['image_id'] = names","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:01.794576Z","iopub.execute_input":"2021-07-24T19:18:01.795008Z","iopub.status.idle":"2021-07-24T19:18:01.806689Z","shell.execute_reply.started":"2021-07-24T19:18:01.794968Z","shell.execute_reply":"2021-07-24T19:18:01.805904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_annotations.image_id = df_annotations.image_id+\"_image\"","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:02.550618Z","iopub.execute_input":"2021-07-24T19:18:02.550953Z","iopub.status.idle":"2021-07-24T19:18:02.583783Z","shell.execute_reply.started":"2021-07-24T19:18:02.550924Z","shell.execute_reply":"2021-07-24T19:18:02.582999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study = df_study.merge(df_annotations[['image_id','s_id']],on='image_id')","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:03.103718Z","iopub.execute_input":"2021-07-24T19:18:03.10407Z","iopub.status.idle":"2021-07-24T19:18:03.118261Z","shell.execute_reply.started":"2021-07-24T19:18:03.104038Z","shell.execute_reply":"2021-07-24T19:18:03.117357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study_res = df_study.copy()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:03.566828Z","iopub.execute_input":"2021-07-24T19:18:03.567166Z","iopub.status.idle":"2021-07-24T19:18:03.570958Z","shell.execute_reply.started":"2021-07-24T19:18:03.56713Z","shell.execute_reply":"2021-07-24T19:18:03.569896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study_res.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:03.894205Z","iopub.execute_input":"2021-07-24T19:18:03.894547Z","iopub.status.idle":"2021-07-24T19:18:03.909035Z","shell.execute_reply.started":"2021-07-24T19:18:03.894515Z","shell.execute_reply":"2021-07-24T19:18:03.907825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study = df_study[[\"s_id\",'Negative for Pneumonia','Typical Appearance','Indeterminate Appearance','Atypical Appearance']]","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:04.184638Z","iopub.execute_input":"2021-07-24T19:18:04.18497Z","iopub.status.idle":"2021-07-24T19:18:04.191768Z","shell.execute_reply.started":"2021-07-24T19:18:04.184937Z","shell.execute_reply":"2021-07-24T19:18:04.190762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def return_PredictionString(x):\n    PredictionString = f'negative {x[\"Negative for Pneumonia\"]} 0 0 1 1 typical {x[\"Typical Appearance\"]} 0 0 1 1 indeterminate {x[\"Indeterminate Appearance\"]} 0 0 1 1 atypical {x[\"Atypical Appearance\"]} 0 0 1 1'\n    return PredictionString\ndf_study['PredictionString'] = df_study.apply(return_PredictionString, axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:04.862058Z","iopub.execute_input":"2021-07-24T19:18:04.862379Z","iopub.status.idle":"2021-07-24T19:18:04.874436Z","shell.execute_reply.started":"2021-07-24T19:18:04.862348Z","shell.execute_reply":"2021-07-24T19:18:04.873491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study = df_study[['s_id','PredictionString']].drop_duplicates(\"s_id\")\ndf_study.columns = ['id','PredictionString']","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:05.41559Z","iopub.execute_input":"2021-07-24T19:18:05.415938Z","iopub.status.idle":"2021-07-24T19:18:05.423258Z","shell.execute_reply.started":"2021-07-24T19:18:05.415907Z","shell.execute_reply":"2021-07-24T19:18:05.422265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Uni 101 fold4","metadata":{}},{"cell_type":"code","source":"import sys\nsys.path.insert(0, \"./mmdetection\")\n\nimport os\n# Check Pytorch installation\nimport torch, torchvision\nprint(torch.__version__, torch.cuda.is_available())\n\n# Check mmcv installation\nfrom mmcv.ops import get_compiling_cuda_version, get_compiler_version\nprint(get_compiling_cuda_version())\nprint(get_compiler_version())\n\n# Check MMDetection installation\nfrom mmdet.apis import set_random_seed\n\n# Imports\nimport mmdet\nfrom mmdet.apis import set_random_seed\nfrom mmdet.datasets import build_dataset\nfrom mmdet.models import build_detector\nfrom mmdet.apis import train_detector\n\nimport random\nimport numpy as np\nfrom pathlib import Path\nimport mmcv\nfrom mmdet.models import build_detector\nfrom mmcv.runner import load_checkpoint\nfrom mmcv.parallel import MMDataParallel\nfrom mmdet.datasets import build_dataloader, build_dataset\nfrom mmdet.apis import single_gpu_test\nfrom mmdet.apis import init_detector, inference_detector, show_result_pyplot\n\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom pathlib import Path\nimport cv2\nimport json\nfrom tqdm.auto import tqdm\nimport os\nimport warnings\n\nimport mmcv\nimport torch\nfrom mmcv import Config, DictAction\nfrom mmcv.cnn import fuse_conv_bn\nfrom mmcv.parallel import MMDataParallel, MMDistributedDataParallel\nfrom mmcv.runner import (get_dist_info, init_dist, load_checkpoint,\n                         wrap_fp16_model)\nfrom tools.rearrange_weights import rearrange_classes\n\nfrom mmdet.apis import multi_gpu_test, single_gpu_test\nfrom mmdet.datasets import (build_dataloader, build_dataset,\n                            replace_ImageToTensor)\nfrom mmdet.models import build_detector","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:06.399074Z","iopub.execute_input":"2021-07-24T19:18:06.399418Z","iopub.status.idle":"2021-07-24T19:18:08.897534Z","shell.execute_reply.started":"2021-07-24T19:18:06.399385Z","shell.execute_reply":"2021-07-24T19:18:08.896579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from mmcv import Config\nbaseline_cfg_path = \"/kaggle/working/configs/universenet/universenet101_2008d_fp16_4x4_mstrain_480_960_20e_coco.py\"\ncfg = Config.fromfile(baseline_cfg_path)\ncfg.model.bbox_head.num_classes = 2\ncfg.gpu_ids = [0]\ncfg.dataset_type = 'CocoDataset' # Dataset type, this will be used to define the dataset\ncfg.classes = (\"Lung\",\"Covid_Abnormality\")\ncfg.test_pipeline = [\n    dict(type='LoadImageFromFile'),\n    dict(\n        type='MultiScaleFlipAug',\n        img_scale=(1600, 1400),\n        flip=True,\n        transforms=[\n            dict(type='Resize', keep_ratio=True),\n            dict(type='RandomFlip'),\n            dict(\n                type='Normalize',\n                mean=[123.675, 116.28, 103.53],\n                std=[58.395, 57.12, 57.375],\n                to_rgb=True),\n            dict(type='Pad', size_divisor=32),\n            dict(type='ImageToTensor', keys=['img']),\n            dict(type='Collect', keys=['img'])\n        ])\n]\ncfg.model.pretrained = None\n# cfg.load_from = '../input/result-uni-siim-01jul/result_uni/fold1_epoch_13_map736.pth'\ncfg.model.backbone.norm_cfg = dict(type='BN', requires_grad=True)\ncfg.data.test.test_mode = True\ncfg.model.train_cfg = None\ncfg.data.samples_per_gpu=1\ncfg.data.test.img_prefix=\"./tmp/\"\ncfg.model.test_cfg.score_thr=0.01\ncfg.model.test_cfg.nms.iou_threshold = 0.4\ncfg.data.test.ann_file = 'test.json'\n\ncfg_path = f'infer.py'\nprint(cfg_path)\ncfg.dump(cfg_path)\ncfg = Config.fromfile(cfg_path)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:10.307985Z","iopub.execute_input":"2021-07-24T19:18:10.308339Z","iopub.status.idle":"2021-07-24T19:18:10.605251Z","shell.execute_reply.started":"2021-07-24T19:18:10.308307Z","shell.execute_reply":"2021-07-24T19:18:10.604522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del model\ntorch.cuda.empty_cache()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:11.719357Z","iopub.execute_input":"2021-07-24T19:18:11.71976Z","iopub.status.idle":"2021-07-24T19:18:12.197254Z","shell.execute_reply.started":"2021-07-24T19:18:11.719725Z","shell.execute_reply":"2021-07-24T19:18:12.196384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !ls ../input/fold4-siim-mmdetection-uni20-08-101/job4_uni_r101_fold4/epoch_7.pth","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:13.606995Z","iopub.execute_input":"2021-07-24T19:18:13.607337Z","iopub.status.idle":"2021-07-24T19:18:13.612384Z","shell.execute_reply.started":"2021-07-24T19:18:13.607305Z","shell.execute_reply":"2021-07-24T19:18:13.610098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"flip = False\nif flip:\n    print(cfg.data.test.pipeline[-1])\n    print(f\"flip: {cfg.data.test.pipeline[-1].flip}\")\n    cfg.data.test.pipeline[-1].flip_direction = [\"horizontal\"]\n    cfg.data.test.pipeline[-1].flip = flip","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:13.885245Z","iopub.execute_input":"2021-07-24T19:18:13.885586Z","iopub.status.idle":"2021-07-24T19:18:13.890634Z","shell.execute_reply.started":"2021-07-24T19:18:13.885553Z","shell.execute_reply":"2021-07-24T19:18:13.889513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# uni101_pths = glob.glob('../input/18-jul-uni-opacity-bigger/*.pth')\nuni101_pths = ['../input/18-jul-uni-opacity-bigger/fold0_ep9.pth',\n               '../input/18-jul-uni-opacity-bigger/fold4_ep16.pth',\n               '../input/16-jul-uni-clean-bigger/fold1_ep15.pth',\n               '../input/07jul-low-augment-uni101/epoch_17_fold1.pth',\n               '../input/06jul-no-augment-uni101/epoch_18_fold3.pth',\n               '../input/uni-opacity-bigger-extra-aug/fold3_ep13.pth',\n               '../input/uni-opacity-bigger-extra-aug/fold4_ep9.pth']\n\n# uni101_pths.append('../input/16-jul-uni-clean-bigger/fold1_ep15.pth')","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:18:16.095917Z","iopub.execute_input":"2021-07-24T19:18:16.096302Z","iopub.status.idle":"2021-07-24T19:18:16.101584Z","shell.execute_reply.started":"2021-07-24T19:18:16.096263Z","shell.execute_reply":"2021-07-24T19:18:16.100675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"OUTPUTS = []\ndataset = build_dataset(cfg.data.test)\ndata_loader = build_dataloader(\n            dataset,\n            samples_per_gpu=1,\n            workers_per_gpu=4,\n            dist=False,\n            shuffle=False)\nfor pth_uni in uni101_pths:\n    print(\" \")\n    print(pth_uni)\n    model = build_detector(cfg.model, test_cfg=cfg.get('test_cfg'))\n    fp16_cfg = cfg.get('fp16', None)\n    if fp16_cfg is not None:\n        wrap_fp16_model(model)\n    checkpoint = load_checkpoint(model, pth_uni, map_location='cpu')\n    if 'CLASSES' in checkpoint.get('meta', {}):\n        model.CLASSES = checkpoint['meta']['CLASSES']\n    else:\n        model.CLASSES = dataset.CLASSES\n    model = MMDataParallel(model, device_ids=[0])\n    outputs = single_gpu_test(model, data_loader,False, '',0.1)\n    OUTPUTS.append(outputs)\n    del model\n    torch.cuda.empty_cache()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:22:12.475112Z","iopub.execute_input":"2021-07-24T19:22:12.475598Z","iopub.status.idle":"2021-07-24T19:23:10.370286Z","shell.execute_reply.started":"2021-07-24T19:22:12.475554Z","shell.execute_reply":"2021-07-24T19:23:10.369296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"OUTPUTS_np = np.array(OUTPUTS)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:10.37442Z","iopub.execute_input":"2021-07-24T19:23:10.374718Z","iopub.status.idle":"2021-07-24T19:23:10.382686Z","shell.execute_reply.started":"2021-07-24T19:23:10.374687Z","shell.execute_reply":"2021-07-24T19:23:10.381823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"OUTPUTS_np = OUTPUTS_np.transpose(1,0,2)\nOUTPUTS_np.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:10.384837Z","iopub.execute_input":"2021-07-24T19:23:10.385352Z","iopub.status.idle":"2021-07-24T19:23:10.392849Z","shell.execute_reply.started":"2021-07-24T19:23:10.385207Z","shell.execute_reply":"2021-07-24T19:23:10.391715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#OUTPUTS = models,image,class,N bbox,[bbox,p]\n#OUTPUTS_np = image,models,class,N bbox,[bbox,p]","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:10.394749Z","iopub.execute_input":"2021-07-24T19:23:10.395296Z","iopub.status.idle":"2021-07-24T19:23:10.400794Z","shell.execute_reply.started":"2021-07-24T19:23:10.39526Z","shell.execute_reply":"2021-07-24T19:23:10.399907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# prob1.shape,bbox1.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:10.401916Z","iopub.execute_input":"2021-07-24T19:23:10.402551Z","iopub.status.idle":"2021-07-24T19:23:10.410065Z","shell.execute_reply.started":"2021-07-24T19:23:10.402511Z","shell.execute_reply":"2021-07-24T19:23:10.409176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# results = []\n# for img_bbox in OUTPUTS_np:\n#     bbox0,prob0 = img_bbox[0,1][:,0:4],img_bbox[0,1][:,4]\n#     bbox1,prob1 = img_bbox[1,1][:,0:4],img_bbox[1,1][:,4]\n#     bbox2,prob2 = img_bbox[2,1][:,0:4],img_bbox[2,1][:,4]\n#     bbox3,prob3 = img_bbox[3,1][:,0:4],img_bbox[3,1][:,4]\n#     classes0 =np.zeros([len(bbox0)])\n#     classes1 =np.zeros([len(bbox1)])\n#     classes2 =np.zeros([len(bbox2)])\n#     classes3 =np.zeros([len(bbox3)])\n#     max0 = bbox0.max()\n#     max1 = bbox1.max()\n#     max2 = bbox2.max()\n#     max3 = bbox3.max()\n#     m = max(max0,max1,max2,max3)\n#     bbox0 = bbox0 / m\n#     bbox1 = bbox1 / m\n#     bbox2 = bbox2 / m\n#     bbox3 = bbox3 / m\n#     bboxes, scores, labels = weighted_boxes_fusion(\n#         [bbox0,bbox1,bbox2,bbox3],\n#         [prob0,prob1,prob2,prob3],\n#         [classes0,classes1,classes2,classes3],\n#         iou_thr=0.4,\n#         skip_box_thr=0.05,\n#     )\n#     bboxes = bboxes*m\n#     results.append([bboxes,scores])\n#     break","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:10.411239Z","iopub.execute_input":"2021-07-24T19:23:10.411837Z","iopub.status.idle":"2021-07-24T19:23:10.420281Z","shell.execute_reply.started":"2021-07-24T19:23:10.411801Z","shell.execute_reply":"2021-07-24T19:23:10.419333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study_res.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:10.421771Z","iopub.execute_input":"2021-07-24T19:23:10.422237Z","iopub.status.idle":"2021-07-24T19:23:10.444296Z","shell.execute_reply.started":"2021-07-24T19:23:10.422183Z","shell.execute_reply":"2021-07-24T19:23:10.443324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from ensemble_boxes import weighted_boxes_fusion, nms\ndef format_results(self, results, output_path=None, **kwargs):\n    prediction_results = []\n    for idx in range(len(self)):\n        filename = self.data_infos[idx][\"filename\"]\n        image_id = os.path.splitext(os.path.basename(filename))[0]\n        prediction_strs = []\n#         print(df_study_res[df_study_res.image_id==f\"{image_id}_image\"]['Negative for Pneumonia'].max())\n        p_c = df_study_res[df_study_res.image_id==f\"{image_id}_image\"]['Negative for Pneumonia'].max()\n            \n        img_bbox = results[idx]\n#             print(img_bbox)\n        bbox0,prob0 = img_bbox[0,1][:,0:4],img_bbox[0,1][:,4]\n        bbox1,prob1 = img_bbox[1,1][:,0:4],img_bbox[1,1][:,4]\n        bbox2,prob2 = img_bbox[2,1][:,0:4],img_bbox[2,1][:,4]\n        bbox3,prob3 = img_bbox[3,1][:,0:4],img_bbox[3,1][:,4]\n        bbox4,prob4 = img_bbox[4,1][:,0:4],img_bbox[4,1][:,4]\n        bbox5,prob5 = img_bbox[5,1][:,0:4],img_bbox[5,1][:,4]\n        bbox6,prob6 = img_bbox[6,1][:,0:4],img_bbox[6,1][:,4]\n\n        #             print(bbox0, bbox1, bbox2, bbox3)\n        classes0 =np.zeros([len(bbox0)])\n        classes1 =np.zeros([len(bbox1)])\n        classes2 =np.zeros([len(bbox2)])\n        classes3 =np.zeros([len(bbox3)])\n        classes4 =np.zeros([len(bbox4)])\n        classes5 =np.zeros([len(bbox5)])\n        classes6 =np.zeros([len(bbox6)])\n\n        max0 = bbox0.max()\n        max1 = bbox1.max()\n        max2 = bbox2.max()\n        max3 = bbox3.max()\n        max4 = bbox4.max()\n        max5 = bbox5.max()\n        max6 = bbox6.max()\n\n        m = max(max0,max1,max2,max3,max4,max5,max6)\n        bbox0 = bbox0 / m\n        bbox1 = bbox1 / m\n        bbox2 = bbox2 / m\n        bbox3 = bbox3 / m\n        bbox4 = bbox4 / m\n        bbox5 = bbox5 / m\n        bbox6 = bbox6 / m\n\n        bboxes, scores, labels = weighted_boxes_fusion(\n            [bbox0,bbox1,bbox2,bbox3,bbox4,bbox5,bbox6],\n            [prob0,prob1,prob2,prob3,prob4,prob5,prob6],\n            [classes0,classes1,classes2,classes3,classes4,classes5,classes6],\n            iou_thr=0.5,\n            skip_box_thr=0.001,\n        )\n#         max_prob = max(scores)\n#         p_none = 1-max_prob\n#         p_c = 0.75*p_c + 0.25*p_none\n        if p_c>0.9:\n            prediction_strs.append(f'none {p_c} 0 0 1 1')\n        else:\n            prediction_strs.append(f'none {p_c} 0 0 1 1')\n            bboxes = bboxes*m\n            for b,s in zip(bboxes,scores):\n                prediction_strs.append(f\"opacity {s:.4f} {float(b[0])} {float(b[1])} {float(b[2])} {float(b[3])}\")\n#         if len(prediction_strs)==0:\n#             prediction_strs.append('none 1 0 0 1 1')\n        prediction_results.append({\"image_id\": image_id, \"PredictionString\": \" \".join(prediction_strs)})\n    predictions = pd.DataFrame(prediction_results)\n#     if output_path is not None:\n#         predictions.to_csv(output_path, index=False)\n    return predictions","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:42.375828Z","iopub.execute_input":"2021-07-24T19:23:42.37616Z","iopub.status.idle":"2021-07-24T19:23:42.395771Z","shell.execute_reply.started":"2021-07-24T19:23:42.376122Z","shell.execute_reply":"2021-07-24T19:23:42.394835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_image = format_results(data_loader.dataset,OUTPUTS_np)\ndf_image['image_id'] = df_image['image_id'] +\"_image\"\ndf_image.columns = ['id','PredictionString']\ndf_image","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:43.014378Z","iopub.execute_input":"2021-07-24T19:23:43.014752Z","iopub.status.idle":"2021-07-24T19:23:51.567943Z","shell.execute_reply.started":"2021-07-24T19:23:43.01472Z","shell.execute_reply":"2021-07-24T19:23:51.567093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_image.PredictionString[0]","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.570932Z","iopub.execute_input":"2021-07-24T19:23:51.571239Z","iopub.status.idle":"2021-07-24T19:23:51.579731Z","shell.execute_reply.started":"2021-07-24T19:23:51.57121Z","shell.execute_reply":"2021-07-24T19:23:51.578338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study = pd.concat([df_image,df_study])","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.582237Z","iopub.execute_input":"2021-07-24T19:23:51.582682Z","iopub.status.idle":"2021-07-24T19:23:51.590876Z","shell.execute_reply.started":"2021-07-24T19:23:51.582641Z","shell.execute_reply":"2021-07-24T19:23:51.589659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_study","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.59334Z","iopub.execute_input":"2021-07-24T19:23:51.59376Z","iopub.status.idle":"2021-07-24T19:23:51.60897Z","shell.execute_reply.started":"2021-07-24T19:23:51.59372Z","shell.execute_reply":"2021-07-24T19:23:51.607831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/siim-covid19-detection/sample_submission.csv\")[['id']]","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.610507Z","iopub.execute_input":"2021-07-24T19:23:51.610902Z","iopub.status.idle":"2021-07-24T19:23:51.638427Z","shell.execute_reply.started":"2021-07-24T19:23:51.610834Z","shell.execute_reply":"2021-07-24T19:23:51.637644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.merge(df_study,on='id',how='outer').fillna('none 1 0 0 1 1')","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.639685Z","iopub.execute_input":"2021-07-24T19:23:51.640059Z","iopub.status.idle":"2021-07-24T19:23:51.654388Z","shell.execute_reply.started":"2021-07-24T19:23:51.640021Z","shell.execute_reply":"2021-07-24T19:23:51.653597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf *","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.65577Z","iopub.execute_input":"2021-07-24T19:23:51.656102Z","iopub.status.idle":"2021-07-24T19:23:51.945016Z","shell.execute_reply.started":"2021-07-24T19:23:51.656068Z","shell.execute_reply":"2021-07-24T19:23:51.943444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:51.949696Z","iopub.execute_input":"2021-07-24T19:23:51.950371Z","iopub.status.idle":"2021-07-24T19:23:52.252077Z","shell.execute_reply.started":"2021-07-24T19:23:51.950326Z","shell.execute_reply":"2021-07-24T19:23:52.251092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:52.254051Z","iopub.execute_input":"2021-07-24T19:23:52.254698Z","iopub.status.idle":"2021-07-24T19:23:52.477129Z","shell.execute_reply.started":"2021-07-24T19:23:52.25466Z","shell.execute_reply":"2021-07-24T19:23:52.476111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-24T19:23:52.478874Z","iopub.execute_input":"2021-07-24T19:23:52.479257Z","iopub.status.idle":"2021-07-24T19:23:52.492586Z","shell.execute_reply.started":"2021-07-24T19:23:52.479216Z","shell.execute_reply":"2021-07-24T19:23:52.491373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}