{"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":"from __future__ import print_function, division\n\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.optim import lr_scheduler\nimport numpy as np\nimport torchvision\nfrom torchvision import datasets, models, transforms\nimport matplotlib.pyplot as plt\nimport time\nimport os\nimport copy","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-11T19:25:24.564238Z","iopub.execute_input":"2021-06-11T19:25:24.564761Z","iopub.status.idle":"2021-06-11T19:25:26.065599Z","shell.execute_reply.started":"2021-06-11T19:25:24.564644Z","shell.execute_reply":"2021-06-11T19:25:26.064442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport json\nimport os\nimport cv2\nimport itertools\nimport glob, pylab\nimport random","metadata":{"execution":{"iopub.status.busy":"2021-06-11T19:25:26.070048Z","iopub.execute_input":"2021-06-11T19:25:26.070402Z","iopub.status.idle":"2021-06-11T19:25:26.296534Z","shell.execute_reply.started":"2021-06-11T19:25:26.070357Z","shell.execute_reply":"2021-06-11T19:25:26.295390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\nimport torch.optim as optim\nimport torch.nn.functional as F\nfrom torch.optim.lr_scheduler import StepLR   \nfrom torch.utils.data import DataLoader, Dataset\nfrom torchvision import datasets, transforms\nimport torchvision.transforms as transforms\n\n\nimport pydicom\nfrom pydicom import read_file\nfrom PIL import Image\n\n# import timm\n# from linformer import Linformer\nfrom itertools import chain\n# from vit_pytorch.efficient import ViT\nfrom tqdm.notebook import tqdm\n\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2021-06-11T19:25:33.084583Z","iopub.execute_input":"2021-06-11T19:25:33.085301Z","iopub.status.idle":"2021-06-11T19:25:34.483653Z","shell.execute_reply.started":"2021-06-11T19:25:33.085241Z","shell.execute_reply":"2021-06-11T19:25:34.482508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom as dicom\nimport os\nimport cv2\nimport PIL # optional\n# make it True if you want in PNG format\nPNG = False\n# Specify the .dcm folder path\n# folder_path = \"stage_1_test_images\"\nfolder_path = '/kaggle/input/rsna-pneumonia-detection-challenge/stage_2_train_images/'\n# Specify the output jpg/png folder path\njpg_folder_path = \"/kaggle/working/\"\nimages_path = os.listdir(folder_path)\nfor n, image in enumerate(images_path):\n    ds = dicom.dcmread(os.path.join(folder_path, image))\n    pixel_array_numpy = ds.pixel_array\n    \n    # resize image\n    # can be (256, 256)\n    resized = cv2.resize(pixel_array_numpy, (256, 256), interpolation = cv2.INTER_AREA)\n    \n    if PNG == False:\n        image = image.replace('.dcm', '.jpg')\n    else:\n        image = image.replace('.dcm', '.png')\n    cv2.imwrite(os.path.join(jpg_folder_path, image), resized)\n    if n % 2000 == 0:\n        print('{} image converted'.format(n))","metadata":{},"execution_count":null,"outputs":[]}]}