{"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":"! pip install -U pylibjpeg pylibjpeg-openjpeg pylibjpeg-libjpeg pydicom python-gdcm\n! pip install --upgrade pydicom","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:16:52.166938Z","iopub.execute_input":"2023-02-13T20:16:52.167927Z","iopub.status.idle":"2023-02-13T20:17:12.838566Z","shell.execute_reply.started":"2023-02-13T20:16:52.167876Z","shell.execute_reply":"2023-02-13T20:17:12.83725Z"},"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 torch\nfrom torchvision.io import read_image\nfrom sklearn.model_selection import train_test_split\nimport pydicom\nfrom pydicom.data import get_testdata_file\nimport re\nimport gc\nimport cv2\nimport wandb\nimport random\nimport math\nfrom glob import glob\nfrom tqdm import tqdm\nfrom pprint import pprint\nfrom time import time\nimport datetime as dtime\nfrom datetime import datetime\nimport itertools\nimport warnings\nimport pydicom # for DICOM images\nfrom skimage.transform import resize\nfrom sklearn.preprocessing import LabelEncoder, normalize\n\n# For the Visuals\nimport seaborn as sns\nimport matplotlib as mpl\nfrom matplotlib import cm\nimport matplotlib.patches as patches\nimport matplotlib.pyplot as plt\n\nfrom skimage.color import gray2rgb\n","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:12.842328Z","iopub.execute_input":"2023-02-13T20:17:12.842685Z","iopub.status.idle":"2023-02-13T20:17:12.851385Z","shell.execute_reply.started":"2023-02-13T20:17:12.842652Z","shell.execute_reply":"2023-02-13T20:17:12.849972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torchvision.models import resnet34, resnet50","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:12.852861Z","iopub.execute_input":"2023-02-13T20:17:12.853253Z","iopub.status.idle":"2023-02-13T20:17:12.868727Z","shell.execute_reply.started":"2023-02-13T20:17:12.853213Z","shell.execute_reply":"2023-02-13T20:17:12.867558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:12.873139Z","iopub.execute_input":"2023-02-13T20:17:12.873506Z","iopub.status.idle":"2023-02-13T20:17:12.962378Z","shell.execute_reply.started":"2023-02-13T20:17:12.873473Z","shell.execute_reply":"2023-02-13T20:17:12.961362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/test.csv')\ntest_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:12.963841Z","iopub.execute_input":"2023-02-13T20:17:12.964759Z","iopub.status.idle":"2023-02-13T20:17:12.983917Z","shell.execute_reply.started":"2023-02-13T20:17:12.964714Z","shell.execute_reply":"2023-02-13T20:17:12.98268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#os.listdir('/kaggle/input/rsna-breast-cancer-detection/train_images')[:10]","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:12.985434Z","iopub.execute_input":"2023-02-13T20:17:12.985906Z","iopub.status.idle":"2023-02-13T20:17:12.990846Z","shell.execute_reply.started":"2023-02-13T20:17:12.985867Z","shell.execute_reply":"2023-02-13T20:17:12.989716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id = '63745'\n\nos.listdir(f'/kaggle/input/rsna-breast-cancer-detection/train_images/{patient_id}')","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:12.992716Z","iopub.execute_input":"2023-02-13T20:17:12.993142Z","iopub.status.idle":"2023-02-13T20:17:13.004656Z","shell.execute_reply.started":"2023-02-13T20:17:12.993104Z","shell.execute_reply":"2023-02-13T20:17:13.003495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''''idx = 0 # 0\n\nbase_img_dir = '/kaggle/input/rsna-breast-cancer-detection/train_images'\n\nimg_id = str(train_df['image_id'].iloc[idx])\nfull_img_id = img_id + '.dcm'\npat_id = str(train_df['patient_id'].iloc[idx])\n\nlabel = train_df['cancer'].iloc[idx]\n\nos.path.join(base_img_dir, pat_id, full_img_id)'''","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.006754Z","iopub.execute_input":"2023-02-13T20:17:13.007341Z","iopub.status.idle":"2023-02-13T20:17:13.015799Z","shell.execute_reply.started":"2023-02-13T20:17:13.007304Z","shell.execute_reply":"2023-02-13T20:17:13.014664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#img_path = os.path.join(base_img_dir, pat_id, full_img_id)","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.017803Z","iopub.execute_input":"2023-02-13T20:17:13.018291Z","iopub.status.idle":"2023-02-13T20:17:13.025471Z","shell.execute_reply.started":"2023-02-13T20:17:13.018251Z","shell.execute_reply":"2023-02-13T20:17:13.024362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dcm_img = pydicom.dcmread(img_path, force=True)\n#dcm_img","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.03028Z","iopub.execute_input":"2023-02-13T20:17:13.031027Z","iopub.status.idle":"2023-02-13T20:17:13.036944Z","shell.execute_reply.started":"2023-02-13T20:17:13.030966Z","shell.execute_reply":"2023-02-13T20:17:13.036168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''''img_array = dcm_img.pixel_array\n\nplt.imshow(img_array)\nif label == 0:\n    category = \"doesn't have cancer\"\nelif label == 1:\n    category = \"has cancer\"\n\nplt.title(f'Patient {pat_id} {category} in image: {img_id}');'''","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.038289Z","iopub.execute_input":"2023-02-13T20:17:13.039291Z","iopub.status.idle":"2023-02-13T20:17:13.050433Z","shell.execute_reply.started":"2023-02-13T20:17:13.03925Z","shell.execute_reply":"2023-02-13T20:17:13.04948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''''train = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/train.csv\")\n\n# Get image path\n# Example path: '/kaggle/input/rsna-breast-cancer-detection/train_images/10706/763186195.dcm'\nbase_path = \"/kaggle/input/rsna-breast-cancer-detection/train_images/\"\nall_paths = []\nlabels=[]\nfor i in tqdm(range(len(train))):\n    row = train.iloc[i, :]\n    all_paths.append(base_path + str(row.patient_id) + \"/\" + str(row.image_id) + \".dcm\")\n    labels.append(train['cancer'].iloc[i])\n    \ntrain[\"path\"] = all_paths'''","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.05185Z","iopub.execute_input":"2023-02-13T20:17:13.052928Z","iopub.status.idle":"2023-02-13T20:17:13.062883Z","shell.execute_reply.started":"2023-02-13T20:17:13.052875Z","shell.execute_reply":"2023-02-13T20:17:13.062028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20,6))\nplt.subplot(1,2,1)\nax1 = sns.countplot(data=train_df, x='cancer')\nfor container in ax1.containers:\n    ax1.bar_label(container)\nplt.title('Distribution of targets');","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.064268Z","iopub.execute_input":"2023-02-13T20:17:13.065446Z","iopub.status.idle":"2023-02-13T20:17:13.260683Z","shell.execute_reply.started":"2023-02-13T20:17:13.065402Z","shell.execute_reply":"2023-02-13T20:17:13.259719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"root_dir=\"/kaggle/input/rsna-breast-cancer-detection/\"\nsplit = 'train'\n\nassert split in ['train', 'test'], \"Split must be train, val, or test\"\n\ndata_csv = pd.read_csv(root_dir + \"{}.csv\".format(split))\n\nx = pydicom.dcmread(root_dir + 'train_images/' + '10011' + '/270344397.dcm').pixel_array.astype(float)\n\n# plt.imshow(x)\n\nidx = 100\npatient_id = data_csv['patient_id'][idx]\nimg_id = data_csv['image_id'][idx]\npatient_id, img_id","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.264214Z","iopub.execute_input":"2023-02-13T20:17:13.264526Z","iopub.status.idle":"2023-02-13T20:17:13.704057Z","shell.execute_reply.started":"2023-02-13T20:17:13.264498Z","shell.execute_reply":"2023-02-13T20:17:13.702991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#resized = cv2.resize(train_dataset[5][0],(512,512))","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.705461Z","iopub.execute_input":"2023-02-13T20:17:13.705943Z","iopub.status.idle":"2023-02-13T20:17:13.711591Z","shell.execute_reply.started":"2023-02-13T20:17:13.705886Z","shell.execute_reply":"2023-02-13T20:17:13.709955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#train_dataset[5][0].shape","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.712857Z","iopub.execute_input":"2023-02-13T20:17:13.714255Z","iopub.status.idle":"2023-02-13T20:17:13.721859Z","shell.execute_reply.started":"2023-02-13T20:17:13.714224Z","shell.execute_reply":"2023-02-13T20:17:13.720669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''''plt.subplot(121)\nplt.imshow(train_dataset[5][0])\nplt.subplot(122)\nplt.imshow(resized)'''","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.723748Z","iopub.execute_input":"2023-02-13T20:17:13.724206Z","iopub.status.idle":"2023-02-13T20:17:13.733871Z","shell.execute_reply.started":"2023-02-13T20:17:13.72417Z","shell.execute_reply":"2023-02-13T20:17:13.732793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# data loader class in pytorch\nfrom torch.utils.data import Dataset\nimport torch\n\nclass BreastCancerData(Dataset):\n    def __init__(self, root_dir=\"/kaggle/input/rsna-breast-cancer-detection/\", split=\"train\", target_size=(512,512)):\n        # root_dir: directory of csv file\n        # split: train, or test\n        self.target_size = target_size\n        self.root_dir = root_dir\n        self.split = split\n        assert split in ['train', 'val', 'test'], \"Split must be train, val, or test\"\n        if split in ['train','test']:\n            self.data_csv = pd.read_csv(root_dir + \"{}.csv\".format(split))\n        else:\n            print(\"Validation not implemented\")\n            assert False       \n    \n    def __len__(self):\n        # returns the size of the dataset\n        return len(self.data_csv)\n    \n    def __getitem__(self, idx):\n        # returns the image and label of the sample number idx\n        patient_id = self.data_csv['patient_id'][idx]\n        img_id = self.data_csv['image_id'][idx]\n        x = pydicom.dcmread(self.root_dir + '{}_images/'.format(self.split) + str(patient_id) + '/' + str(img_id) + '.dcm').pixel_array.astype(float)\n        x = gray2rgb(x)\n        # resize img\n        x = cv2.resize(x,self.target_size)\n        # normalize\n        x = (x - x.min()) / (x.max() - x.min())\n        # convert to tensor -- pytorch requires images to be in the size (C,H,W) where C: number of channels, H: hight, W:Width\n        # convert to rgb\n        x = np.transpose(x,(2,0,1))\n        x = torch.from_numpy(x).type(torch.FloatTensor)\n        if self.split == 'test':\n            return x\n        else:\n            label = self.data_csv['cancer'][idx]\n            label = np.array([label])\n            label = torch.from_numpy(label).type(torch.FloatTensor)\n            return x, label","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.735301Z","iopub.execute_input":"2023-02-13T20:17:13.736371Z","iopub.status.idle":"2023-02-13T20:17:13.749795Z","shell.execute_reply.started":"2023-02-13T20:17:13.736334Z","shell.execute_reply":"2023-02-13T20:17:13.748803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\ndevice","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.751886Z","iopub.execute_input":"2023-02-13T20:17:13.752735Z","iopub.status.idle":"2023-02-13T20:17:13.764447Z","shell.execute_reply.started":"2023-02-13T20:17:13.752697Z","shell.execute_reply":"2023-02-13T20:17:13.763512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dataset = BreastCancerData(split='train', target_size=(128,128))","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.766266Z","iopub.execute_input":"2023-02-13T20:17:13.766675Z","iopub.status.idle":"2023-02-13T20:17:13.772137Z","shell.execute_reply.started":"2023-02-13T20:17:13.766639Z","shell.execute_reply":"2023-02-13T20:17:13.771152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plt.imshow(dataset[5][0][0])","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.77412Z","iopub.execute_input":"2023-02-13T20:17:13.774552Z","iopub.status.idle":"2023-02-13T20:17:13.782379Z","shell.execute_reply.started":"2023-02-13T20:17:13.774517Z","shell.execute_reply":"2023-02-13T20:17:13.781711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dataset[5][0].shape","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.783651Z","iopub.execute_input":"2023-02-13T20:17:13.78507Z","iopub.status.idle":"2023-02-13T20:17:13.794434Z","shell.execute_reply.started":"2023-02-13T20:17:13.78497Z","shell.execute_reply":"2023-02-13T20:17:13.793501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset = BreastCancerData()\ntest_dataset = BreastCancerData(split='test')","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.797581Z","iopub.execute_input":"2023-02-13T20:17:13.797875Z","iopub.status.idle":"2023-02-13T20:17:13.865756Z","shell.execute_reply.started":"2023-02-13T20:17:13.79785Z","shell.execute_reply":"2023-02-13T20:17:13.864766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch.nn as nn\nclass ResNet50Network(nn.Module):\n    def __init__(self, output_size):\n        super().__init__()\n        self.output_size = output_size\n        \n        # Define Feature part (IMAGE)\n        self.features = resnet50(pretrained=True) # 1000 neurons out\n      \n        # Define Classification part\n        self.classification = nn.Linear(1000 , output_size)\n        \n        \n    def forward(self, image, prints=False):\n        if prints: print('Input Image shape:', image.shape)\n        \n        # Image CNN\n        image = self.features(image)\n        if prints: print('Features Image shape:', image.shape)\n        \n        \n        # CLASSIF\n        out = self.classification(image)\n        if prints: print('Out shape:', out.shape)\n        \n        return out","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.869346Z","iopub.execute_input":"2023-02-13T20:17:13.869656Z","iopub.status.idle":"2023-02-13T20:17:13.876639Z","shell.execute_reply.started":"2023-02-13T20:17:13.869627Z","shell.execute_reply":"2023-02-13T20:17:13.875594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = ResNet50Network(1).to(device)","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:13.878162Z","iopub.execute_input":"2023-02-13T20:17:13.879101Z","iopub.status.idle":"2023-02-13T20:17:14.398551Z","shell.execute_reply.started":"2023-02-13T20:17:13.87906Z","shell.execute_reply":"2023-02-13T20:17:14.397448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch.nn as nn\nimport torch.nn.functional as F\nimport torch.optim as optim\nimport torchvision\nimport torchvision.transforms as transforms","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:14.400366Z","iopub.execute_input":"2023-02-13T20:17:14.401152Z","iopub.status.idle":"2023-02-13T20:17:14.406831Z","shell.execute_reply.started":"2023-02-13T20:17:14.401102Z","shell.execute_reply":"2023-02-13T20:17:14.405748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install pylibjpeg pylibjpeg-libjpeg pydicom","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:14.408272Z","iopub.execute_input":"2023-02-13T20:17:14.409282Z","iopub.status.idle":"2023-02-13T20:17:24.241556Z","shell.execute_reply.started":"2023-02-13T20:17:14.409251Z","shell.execute_reply":"2023-02-13T20:17:24.240251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install python-gdcm","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:24.248357Z","iopub.execute_input":"2023-02-13T20:17:24.248692Z","iopub.status.idle":"2023-02-13T20:17:34.643933Z","shell.execute_reply.started":"2023-02-13T20:17:24.24866Z","shell.execute_reply":"2023-02-13T20:17:34.642393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_dataset)","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.647528Z","iopub.execute_input":"2023-02-13T20:17:34.647906Z","iopub.status.idle":"2023-02-13T20:17:34.656954Z","shell.execute_reply.started":"2023-02-13T20:17:34.647867Z","shell.execute_reply":"2023-02-13T20:17:34.65578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#train_dataset=train_dataset[:1000]","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.659042Z","iopub.execute_input":"2023-02-13T20:17:34.659462Z","iopub.status.idle":"2023-02-13T20:17:34.666903Z","shell.execute_reply.started":"2023-02-13T20:17:34.659419Z","shell.execute_reply":"2023-02-13T20:17:34.665796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_dataset)","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.668925Z","iopub.execute_input":"2023-02-13T20:17:34.669376Z","iopub.status.idle":"2023-02-13T20:17:34.68208Z","shell.execute_reply.started":"2023-02-13T20:17:34.669338Z","shell.execute_reply":"2023-02-13T20:17:34.680932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torch.utils.data import DataLoader\nbatch_size = 2\ntrain_dataset = BreastCancerData(split='train')\ntrain_dataloader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.683787Z","iopub.execute_input":"2023-02-13T20:17:34.684868Z","iopub.status.idle":"2023-02-13T20:17:34.75988Z","shell.execute_reply.started":"2023-02-13T20:17:34.684828Z","shell.execute_reply":"2023-02-13T20:17:34.758845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"criterion = nn.CrossEntropyLoss()\noptimizer = torch.optim.Adam(model.parameters())","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.762052Z","iopub.execute_input":"2023-02-13T20:17:34.762747Z","iopub.status.idle":"2023-02-13T20:17:34.770454Z","shell.execute_reply.started":"2023-02-13T20:17:34.762709Z","shell.execute_reply":"2023-02-13T20:17:34.76944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''''# input size nin pytorch is N*C*H*W, N: batch size\nx = dataset[5][0]\nx = x[None]\ny = model(x)'''","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.771883Z","iopub.execute_input":"2023-02-13T20:17:34.772303Z","iopub.status.idle":"2023-02-13T20:17:34.784907Z","shell.execute_reply.started":"2023-02-13T20:17:34.772265Z","shell.execute_reply":"2023-02-13T20:17:34.783816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\n\nloss = nn.L1Loss()","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:17:34.786507Z","iopub.execute_input":"2023-02-13T20:17:34.786914Z","iopub.status.idle":"2023-02-13T20:17:34.794468Z","shell.execute_reply.started":"2023-02-13T20:17:34.786875Z","shell.execute_reply":"2023-02-13T20:17:34.792929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 1\nfor e in range(epochs):\n    running_loss = 0.0\n\n    for img, label in train_dataloader:\n        \n        img = img.to(device)\n        label = label.to(device)\n        out = model(img)\n         \n        loss_value = loss(out, label)\n        loss_value.backward()\n\n        optimizer.zero_grad()\n        optimizer.step()\n        \n       # running_loss += loss_value.item()\n        \n        #print('Loss:'+ loss.item())\n       # acc = accuracy(out,label)\n       # epoch_acc += acc\n    ","metadata":{"execution":{"iopub.status.busy":"2023-02-13T20:19:40.231396Z","iopub.execute_input":"2023-02-13T20:19:40.231828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}