{"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":"markdown","source":"[Nvidia Dali ](http://https://docs.nvidia.com/deeplearning/dali/user-guide/docs/index.html) is a GPU based library for very fast data loading and preprocessing.  It contains GPU based image decoders which can be used for fast and parallel decoding of jpeg2000 images.  This notebook contains a minimal example of extracting the jpeg2000 encoded images conatained in a dicom container and decoding them on GPU.","metadata":{}},{"cell_type":"markdown","source":"![](https://arcwiki.rs.gsu.edu/nvidia_dali_pipeline.png)","metadata":{}},{"cell_type":"markdown","source":"**Note:** Need to use a nightly build of DALI because UINT16 support was recently added and is not in the main prod wheel","metadata":{}},{"cell_type":"code","source":"!pip install -qU python-gdcm pydicom pylibjpeg\n!pip install --extra-index-url https://developer.download.nvidia.com/compute/redist/nightly --upgrade nvidia-dali-nightly-cuda110","metadata":{"execution":{"iopub.status.busy":"2023-03-08T10:56:05.130133Z","iopub.execute_input":"2023-03-08T10:56:05.130647Z","iopub.status.idle":"2023-03-08T10:56:53.631587Z","shell.execute_reply.started":"2023-03-08T10:56:05.130535Z","shell.execute_reply":"2023-03-08T10:56:53.62997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pydicom\nimport glob, os\nimport pydicom\nfrom pydicom.filebase import DicomBytesIO\nfrom tqdm.notebook import tqdm\nfrom joblib import Parallel, delayed\n\nfrom nvidia.dali import pipeline_def\nimport nvidia.dali.fn as fn\nimport nvidia.dali.types as types\nfrom nvidia.dali.types import DALIDataType","metadata":{"execution":{"iopub.status.busy":"2023-03-08T10:57:26.565119Z","iopub.execute_input":"2023-03-08T10:57:26.566672Z","iopub.status.idle":"2023-03-08T10:57:26.573202Z","shell.execute_reply.started":"2023-03-08T10:57:26.566624Z","shell.execute_reply":"2023-03-08T10:57:26.572088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport pydicom\ndicom = pydicom.dcmread(\"/kaggle/input/unifesp-x-ray-body-part-classifier/train/train/795/1.2.826.0.1.3680043.8.498.36618053271731677022984232332359700190/1.2.826.0.1.3680043.8.498.19359435471299630033044253346016903332/1.2.826.0.1.3680043.8.498.10556319298083910064601519571738133683-c.dcm\",force=True)\ndicom.pixel_array.shape","metadata":{"execution":{"iopub.status.busy":"2023-03-08T10:57:29.603642Z","iopub.execute_input":"2023-03-08T10:57:29.604276Z","iopub.status.idle":"2023-03-08T10:57:32.034578Z","shell.execute_reply.started":"2023-03-08T10:57:29.604138Z","shell.execute_reply":"2023-03-08T10:57:32.033275Z"},"trusted":true},"execution_count":null,"outputs":[]}]}