{"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 numpy as np\nimport torch.nn as nn\nimport torch\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:41:48.987831Z","iopub.execute_input":"2023-01-19T15:41:48.988661Z","iopub.status.idle":"2023-01-19T15:41:51.269434Z","shell.execute_reply.started":"2023-01-19T15:41:48.98852Z","shell.execute_reply":"2023-01-19T15:41:51.268119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Dataset imported ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset= pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:41:51.2719Z","iopub.execute_input":"2023-01-19T15:41:51.273111Z","iopub.status.idle":"2023-01-19T15:41:51.393945Z","shell.execute_reply.started":"2023-01-19T15:41:51.273069Z","shell.execute_reply":"2023-01-19T15:41:51.392671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:41:51.395374Z","iopub.execute_input":"2023-01-19T15:41:51.395775Z","iopub.status.idle":"2023-01-19T15:41:51.421308Z","shell.execute_reply.started":"2023-01-19T15:41:51.395733Z","shell.execute_reply":"2023-01-19T15:41:51.420416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuk= pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:45:12.343512Z","iopub.execute_input":"2023-01-19T13:45:12.343982Z","iopub.status.idle":"2023-01-19T13:45:12.357577Z","shell.execute_reply.started":"2023-01-19T13:45:12.343947Z","shell.execute_reply":"2023-01-19T13:45:12.356324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuk.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:45:19.059589Z","iopub.execute_input":"2023-01-19T13:45:19.060156Z","iopub.status.idle":"2023-01-19T13:45:19.076601Z","shell.execute_reply.started":"2023-01-19T13:45:19.060113Z","shell.execute_reply":"2023-01-19T13:45:19.075065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuk.shape,dataset.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:45:32.99555Z","iopub.execute_input":"2023-01-19T13:45:32.997045Z","iopub.status.idle":"2023-01-19T13:45:33.005789Z","shell.execute_reply.started":"2023-01-19T13:45:32.996991Z","shell.execute_reply":"2023-01-19T13:45:33.004228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset['image_id']","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:47:57.653527Z","iopub.execute_input":"2023-01-19T13:47:57.65398Z","iopub.status.idle":"2023-01-19T13:47:57.665056Z","shell.execute_reply.started":"2023-01-19T13:47:57.653947Z","shell.execute_reply":"2023-01-19T13:47:57.663563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install torchsummary wandb","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:53:57.584807Z","iopub.execute_input":"2023-01-19T13:53:57.585347Z","iopub.status.idle":"2023-01-19T13:54:12.171176Z","shell.execute_reply.started":"2023-01-19T13:53:57.58529Z","shell.execute_reply":"2023-01-19T13:54:12.169589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2 \nimport torch\nimport imghdr\nimport pydicom\nimport plistlib\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\n\nimport torch.nn as nn\nfrom PIL import Image\nimport os, sys, tarfile\nfrom skimage.io import imread\nimport pytorch_lightning as pl\nfrom tqdm.notebook import tqdm\nimport torch.nn.functional as F\nfrom torchsummary import summary\nfrom skimage.draw import polygon\nimport torchvision.transforms as T\nfrom torchvision.io import read_image\nfrom torch.utils.data import DataLoader, Dataset, ConcatDataset\n\n# Data Augmentation for Image Preprocessing\nfrom albumentations.pytorch import ToTensorV2\nfrom albumentations import (ToFloat, Normalize, VerticalFlip, HorizontalFlip, Compose, Resize,\n                            RandomBrightnessContrast, HueSaturationValue, Blur, GaussNoise,\n                            Rotate, RandomResizedCrop, Cutout, ShiftScaleRotate, ToGray)\n\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:54:12.173767Z","iopub.execute_input":"2023-01-19T13:54:12.174141Z","iopub.status.idle":"2023-01-19T13:54:13.187584Z","shell.execute_reply.started":"2023-01-19T13:54:12.174105Z","shell.execute_reply":"2023-01-19T13:54:13.18626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class INBreastDataset(Dataset):\n\n    '''\n    INBreast dataset\n    '''\n    def __init__(self, csv_file: str, \n                 root_dir: str, \n                 transform=None):\n        '''\n            Args:\n            csv_file (string): Path to the csv file with annotations.\n            root_dir (string): Directory with all the images.\n            transform (callable, optional): Optional transform to be applied\n                on a sample.\n        '''\n        self.img_dir = csv_file\n        self.img_data = pd.read_csv(csv_file)\n        self.root = root_dir\n        self.transform = transform\n        \n    def __len__(self):\n        return len(self.img_data['Lesion Annotation Status'])\n\n    def __getitem__(self, idx):\n        img_path = os.path.join(self.root, self.img_data.iloc[idx, -1].replace('dcm', 'png'))\n        img = cv2.imread(img_path, 0)\n        if self.transform != None:\n            image_trans = self.transform(image=img)['image']\n        else:\n            image_trans = img\n        #return\n        final_image = image_trans\n        label = self.img_data['Lesion Annotation Status'][idx]\n        return final_image, label","metadata":{"execution":{"iopub.status.busy":"2023-01-19T13:54:13.189454Z","iopub.execute_input":"2023-01-19T13:54:13.189844Z","iopub.status.idle":"2023-01-19T13:54:13.200429Z","shell.execute_reply.started":"2023-01-19T13:54:13.18981Z","shell.execute_reply":"2023-01-19T13:54:13.199105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vis=INBreastDataset('/kaggle/input/rsna-breast-cancer-detection/train.csv','/kaggle/input/rsna-breast-cancer-detection/train_images')","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:22:34.170978Z","iopub.execute_input":"2023-01-19T14:22:34.171513Z","iopub.status.idle":"2023-01-19T14:22:34.255762Z","shell.execute_reply.started":"2023-01-19T14:22:34.171476Z","shell.execute_reply":"2023-01-19T14:22:34.254497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"root='/kaggle/input/rsna-breast-cancer-detection/train_images'\ncsv=dataset","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:29:39.263344Z","iopub.execute_input":"2023-01-19T14:29:39.263837Z","iopub.status.idle":"2023-01-19T14:29:39.268817Z","shell.execute_reply.started":"2023-01-19T14:29:39.263797Z","shell.execute_reply":"2023-01-19T14:29:39.267885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path=os.path.join(root,str(dataset.iloc[1,1]),str(dataset.iloc[1,2]))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:48:03.290044Z","iopub.execute_input":"2023-01-19T14:48:03.29049Z","iopub.status.idle":"2023-01-19T14:48:03.296159Z","shell.execute_reply.started":"2023-01-19T14:48:03.290456Z","shell.execute_reply":"2023-01-19T14:48:03.295379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img=cv2.imread('/kaggle/input/rsna-mammography-images-as-pngs/images_as_pngs/train_images_processed/10006/1459541791.png',0)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:34:01.028239Z","iopub.execute_input":"2023-01-19T15:34:01.028728Z","iopub.status.idle":"2023-01-19T15:34:01.037794Z","shell.execute_reply.started":"2023-01-19T15:34:01.028689Z","shell.execute_reply":"2023-01-19T15:34:01.036385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cv2.imshow('image',img)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:34:01.988018Z","iopub.execute_input":"2023-01-19T15:34:01.988871Z","iopub.status.idle":"2023-01-19T15:34:02.031857Z","shell.execute_reply.started":"2023-01-19T15:34:01.988837Z","shell.execute_reply":"2023-01-19T15:34:02.030447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install opencv-python --upgrade","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:33:42.515622Z","iopub.execute_input":"2023-01-19T15:33:42.531969Z","iopub.status.idle":"2023-01-19T15:33:54.494077Z","shell.execute_reply.started":"2023-01-19T15:33:42.531885Z","shell.execute_reply":"2023-01-19T15:33:54.492614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}