|
12 | 12 | "metadata": {}, |
13 | 13 | "source": [ |
14 | 14 | "<div>\n", |
15 | | - "<img src=\"https://raw.githubusercontent.com/illinois-mlp/MachineLearningForPhysics/main/img/Project_Radiotherapy-overview.jpg\" width=600></img>\n", |
| 15 | + "<img src=\"..\\img\\Radiotherapy-overview.jpg\" width=600>\n", |
16 | 16 | "</div>" |
17 | 17 | ] |
18 | 18 | }, |
|
53 | 53 | "* https://github.com/ababier/open-kbp" |
54 | 54 | ] |
55 | 55 | }, |
| 56 | + { |
| 57 | + "cell_type": "markdown", |
| 58 | + "metadata": {}, |
| 59 | + "source": [ |
| 60 | + "Link to data\n", |
| 61 | + "* https://github.com/ababier/open-kbp" |
| 62 | + ] |
| 63 | + }, |
56 | 64 | { |
57 | 65 | "cell_type": "markdown", |
58 | 66 | "metadata": {}, |
|
74 | 82 | "X-rays attenuate exponentially upon entering the body by the Beer-Lambert Law. \n", |
75 | 83 | "\n", |
76 | 84 | "$$\n", |
77 | | - "\n", |
78 | | - "I(x) = I_0 \\, e^{-\\mu x}\n", |
79 | | - "\n", |
| 85 | + "I(x) = I_0 e^{-\\mu x}\n", |
80 | 86 | "$$\n", |
| 87 | + "\n", |
81 | 88 | "$$\n", |
82 | 89 | "\\begin{aligned}\n", |
83 | 90 | "x & : \\text{Depth in the body} \\\\\n", |
|
140 | 147 | "cell_type": "markdown", |
141 | 148 | "metadata": {}, |
142 | 149 | "source": [ |
143 | | - "Download `openkbp_patient_data.zip` from File URLS above. Unzip it and upload the folder to your Google Colab (`/content/..`) or local directory. Note that you will need to adjust `base_path` to lead to your uploaded folder.\n", |
| 150 | + "Run the cell below and unzip the contents of `openkbp_patient_data` into a folder. It should be present in Colab's (`/content/..`) or local directory. Note that you will need to adjust `base_path` to lead to this folder.\n", |
144 | 151 | "\n", |
145 | 152 | "Each patient hosts the following three files: \n", |
146 | 153 | "`ct.csv` - 3D grayscale CT scan of patient anatomy composed of 2D slices. Each voxel represents how much X-ray is absorbed by the tissue in Hounsfield Units (HU) \n", |
|
150 | 157 | "These are currently flattened 1D rows. The cell below converts the csv files into 3D volumes [64, 128, 128] where each point represents an intensity (for the ct scan) or binary value (for ptv & spinal cord). Add a line to the for loop that stacks `ct`, `ptv`, and `spine` into a single tensor. What's the final shape of this tensor? Draw an analogy to an RGB image." |
151 | 158 | ] |
152 | 159 | }, |
| 160 | + { |
| 161 | + "cell_type": "code", |
| 162 | + "execution_count": null, |
| 163 | + "metadata": {}, |
| 164 | + "outputs": [], |
| 165 | + "source": [ |
| 166 | + "!wget https://github.com/florilegium7/Physics-informed-DQN-Radiotherapy/releases/download/v1.0/openkbp_patient_data.zip\n", |
| 167 | + "!unzip patient_data.zip" |
| 168 | + ] |
| 169 | + }, |
153 | 170 | { |
154 | 171 | "cell_type": "code", |
155 | 172 | "execution_count": null, |
|
160 | 177 | "import pandas as pd\n", |
161 | 178 | "import os\n", |
162 | 179 | "\n", |
163 | | - "base_path = 'openkbp_patient_data' #adjust this (e.g. /content/openkbp_patient_data)\n", |
| 180 | + "base_path = 'openkbp_patient_data' #you may adjust this (e.g. /content/openkbp_patient_data)\n", |
164 | 181 | "\n", |
165 | 182 | "patient_ids = [\"patient_1\", \"patient_2\", \"patient_3\",\"patient_5\",\"patient_7\",\"patient_9\", \"patient_10\", \"patient_12\" , \"patient_14\", \"patient_16\"]\n", |
166 | 183 | "patient_tensors = []\n", |
|
368 | 385 | "source": [ |
369 | 386 | "We'd like to inject a physics loss that encodes the actual attenuation and radiation dose delivery of the beam, rewarding correct dose distribution between the spine and tumor. We need to upgrade our simple Q-learning method into a Deep-Q Network (DQN). This should only require simple structural changes (refer to our reinforcement learning [notebook](https://illinois-mlp.github.io/MachineLearningForPhysics/_sources/lectures/ReinforcementLearning.html)). Typically, these would use a Bellman loss. With our new physics-loss it should resemble:\n", |
370 | 387 | "$$\n", |
371 | | - "\\mathcal{L}_{\\text{Total}} = \\mathcal{L}_{\\text{Bellman}} + \\lambda_{\\text{Physics}} \\mathcal{L}_{\\text{Physics}}\n", |
| 388 | + "L_{\\text{Total}} = L_{\\text{Bellman}} + \\lambda_{\\text{Physics}} L_{\\text{Physics}}\n", |
372 | 389 | "$$\n", |
373 | 390 | "\n", |
374 | 391 | "The physics loss takes the following form: \n", |
375 | 392 | "$$\n", |
376 | | - "\\mathcal{L}_{\\text{Physics}} =\n", |
| 393 | + "L_{\\text{Physics}} =\n", |
377 | 394 | "\\lambda_{\\text{PTV}} \\cdot \\text{Underdose}_{\\text{PTV}} +\n", |
378 | 395 | "\\lambda_{\\text{Spine}} \\cdot \\text{Overdose}_{\\text{Spine}}\n", |
379 | 396 | "$$\n", |
|
0 commit comments