File size: 15,985 Bytes
b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc b67f297 a10a7fc d908fd7 a10a7fc d908fd7 a10a7fc b67f297 d908fd7 b67f297 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exploring Code for Data"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"metadata = pd.read_csv(\"../data/focus/metadata.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unnamed: 0</th>\n",
" <th>image_path</th>\n",
" <th>original_filename</th>\n",
" <th>study_id</th>\n",
" <th>scan_uuid</th>\n",
" <th>focus_value</th>\n",
" <th>stack_id</th>\n",
" <th>obj_name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01631...</td>\n",
" <td>I01631_X013_Y012_Z5107.jpg</td>\n",
" <td>31</td>\n",
" <td>fba56d57-656e-4b6f-ba63-e4ba3ad083f5</td>\n",
" <td>-2.82953</td>\n",
" <td>1658220</td>\n",
" <td>133</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01632...</td>\n",
" <td>I01632_X013_Y012_Z5175.jpg</td>\n",
" <td>31</td>\n",
" <td>fba56d57-656e-4b6f-ba63-e4ba3ad083f5</td>\n",
" <td>-2.70408</td>\n",
" <td>1658220</td>\n",
" <td>133</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01633...</td>\n",
" <td>I01633_X013_Y012_Z5722.jpg</td>\n",
" <td>31</td>\n",
" <td>fba56d57-656e-4b6f-ba63-e4ba3ad083f5</td>\n",
" <td>-2.69918</td>\n",
" <td>1658220</td>\n",
" <td>133</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01634...</td>\n",
" <td>I01634_X013_Y012_Z5244.jpg</td>\n",
" <td>31</td>\n",
" <td>fba56d57-656e-4b6f-ba63-e4ba3ad083f5</td>\n",
" <td>-2.50266</td>\n",
" <td>1658220</td>\n",
" <td>133</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01635...</td>\n",
" <td>I01635_X013_Y012_Z5654.jpg</td>\n",
" <td>31</td>\n",
" <td>fba56d57-656e-4b6f-ba63-e4ba3ad083f5</td>\n",
" <td>-2.36450</td>\n",
" <td>1658220</td>\n",
" <td>133</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>565</th>\n",
" <td>565</td>\n",
" <td>31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01406...</td>\n",
" <td>I01406_X016_Y009_Z5361.jpg</td>\n",
" <td>31</td>\n",
" <td>4c7e9e66-61a1-47ca-aa4e-340b0eef8db1</td>\n",
" <td>-3.41147</td>\n",
" <td>1674918</td>\n",
" <td>217</td>\n",
" </tr>\n",
" <tr>\n",
" <th>566</th>\n",
" <td>566</td>\n",
" <td>31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01407...</td>\n",
" <td>I01407_X016_Y009_Z5087.jpg</td>\n",
" <td>31</td>\n",
" <td>4c7e9e66-61a1-47ca-aa4e-340b0eef8db1</td>\n",
" <td>-3.05424</td>\n",
" <td>1674918</td>\n",
" <td>217</td>\n",
" </tr>\n",
" <tr>\n",
" <th>567</th>\n",
" <td>567</td>\n",
" <td>31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01408...</td>\n",
" <td>I01408_X016_Y009_Z5292.jpg</td>\n",
" <td>31</td>\n",
" <td>4c7e9e66-61a1-47ca-aa4e-340b0eef8db1</td>\n",
" <td>-1.48608</td>\n",
" <td>1674918</td>\n",
" <td>217</td>\n",
" </tr>\n",
" <tr>\n",
" <th>568</th>\n",
" <td>568</td>\n",
" <td>31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01409...</td>\n",
" <td>I01409_X016_Y009_Z5156.jpg</td>\n",
" <td>31</td>\n",
" <td>4c7e9e66-61a1-47ca-aa4e-340b0eef8db1</td>\n",
" <td>-0.52804</td>\n",
" <td>1674918</td>\n",
" <td>217</td>\n",
" </tr>\n",
" <tr>\n",
" <th>569</th>\n",
" <td>569</td>\n",
" <td>31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01410...</td>\n",
" <td>I01410_X016_Y009_Z5224.jpg</td>\n",
" <td>31</td>\n",
" <td>4c7e9e66-61a1-47ca-aa4e-340b0eef8db1</td>\n",
" <td>0.00000</td>\n",
" <td>1674918</td>\n",
" <td>217</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>570 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 image_path \\\n",
"0 0 31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01631... \n",
"1 1 31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01632... \n",
"2 2 31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01633... \n",
"3 3 31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01634... \n",
"4 4 31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01635... \n",
".. ... ... \n",
"565 565 31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01406... \n",
"566 566 31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01407... \n",
"567 567 31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01408... \n",
"568 568 31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01409... \n",
"569 569 31/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01410... \n",
"\n",
" original_filename study_id \\\n",
"0 I01631_X013_Y012_Z5107.jpg 31 \n",
"1 I01632_X013_Y012_Z5175.jpg 31 \n",
"2 I01633_X013_Y012_Z5722.jpg 31 \n",
"3 I01634_X013_Y012_Z5244.jpg 31 \n",
"4 I01635_X013_Y012_Z5654.jpg 31 \n",
".. ... ... \n",
"565 I01406_X016_Y009_Z5361.jpg 31 \n",
"566 I01407_X016_Y009_Z5087.jpg 31 \n",
"567 I01408_X016_Y009_Z5292.jpg 31 \n",
"568 I01409_X016_Y009_Z5156.jpg 31 \n",
"569 I01410_X016_Y009_Z5224.jpg 31 \n",
"\n",
" scan_uuid focus_value stack_id obj_name \n",
"0 fba56d57-656e-4b6f-ba63-e4ba3ad083f5 -2.82953 1658220 133 \n",
"1 fba56d57-656e-4b6f-ba63-e4ba3ad083f5 -2.70408 1658220 133 \n",
"2 fba56d57-656e-4b6f-ba63-e4ba3ad083f5 -2.69918 1658220 133 \n",
"3 fba56d57-656e-4b6f-ba63-e4ba3ad083f5 -2.50266 1658220 133 \n",
"4 fba56d57-656e-4b6f-ba63-e4ba3ad083f5 -2.36450 1658220 133 \n",
".. ... ... ... ... \n",
"565 4c7e9e66-61a1-47ca-aa4e-340b0eef8db1 -3.41147 1674918 217 \n",
"566 4c7e9e66-61a1-47ca-aa4e-340b0eef8db1 -3.05424 1674918 217 \n",
"567 4c7e9e66-61a1-47ca-aa4e-340b0eef8db1 -1.48608 1674918 217 \n",
"568 4c7e9e66-61a1-47ca-aa4e-340b0eef8db1 -0.52804 1674918 217 \n",
"569 4c7e9e66-61a1-47ca-aa4e-340b0eef8db1 0.00000 1674918 217 \n",
"\n",
"[570 rows x 8 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"metadata"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'31/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01631_X013_Y012_Z5107_600_375.jpg'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"idx = 0\n",
"# File Path\n",
"metadata.iloc[idx, 1]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-2.82953"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Focus Value\n",
"metadata.iloc[idx, 5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Testing FocusDataSet"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"570\n"
]
},
{
"data": {
"text/plain": [
"{'image': array([[[172, 173, 159],\n",
" [166, 167, 153],\n",
" [171, 173, 160],\n",
" ...,\n",
" [199, 202, 173],\n",
" [199, 202, 173],\n",
" [200, 201, 170]],\n",
" \n",
" [[167, 169, 155],\n",
" [164, 166, 152],\n",
" [171, 175, 160],\n",
" ...,\n",
" [194, 197, 168],\n",
" [195, 198, 169],\n",
" [199, 200, 169]],\n",
" \n",
" [[146, 153, 135],\n",
" [149, 156, 138],\n",
" [163, 172, 153],\n",
" ...,\n",
" [189, 192, 163],\n",
" [191, 194, 165],\n",
" [197, 198, 167]],\n",
" \n",
" ...,\n",
" \n",
" [[ 57, 62, 68],\n",
" [ 41, 46, 52],\n",
" [ 24, 31, 39],\n",
" ...,\n",
" [198, 189, 180],\n",
" [188, 179, 170],\n",
" [180, 171, 164]],\n",
" \n",
" [[ 46, 51, 57],\n",
" [ 34, 39, 45],\n",
" [ 21, 28, 36],\n",
" ...,\n",
" [208, 200, 189],\n",
" [197, 190, 180],\n",
" [188, 181, 173]],\n",
" \n",
" [[ 31, 39, 42],\n",
" [ 23, 31, 34],\n",
" [ 18, 25, 31],\n",
" ...,\n",
" [215, 209, 197],\n",
" [205, 199, 187],\n",
" [197, 190, 180]]], dtype=uint8),\n",
" 'focus_value': 0.0}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from importlib.machinery import SourceFileLoader\n",
"\n",
"focus_datamodule = SourceFileLoader(\"focus_datamodule\", \"../src/datamodules/focus_datamodule.py\").load_module()\n",
"from focus_datamodule import FocusDataSet\n",
"\n",
"ds = FocusDataSet(\"../data/focus/metadata.csv\", \"../data/focus/\")\n",
"\n",
"counter = 0\n",
"for d in ds:\n",
" counter += 1\n",
"\n",
"print(counter)\n",
"\n",
"d"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from focus_datamodule import FocusDataModule\n",
"\n",
"datamodule = FocusDataModule(data_dir=\"../data/focus\", csv_file=\"../data/focus/metadata.csv\")\n",
"datamodule.setup()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"64"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for data in datamodule.test_dataloader():\n",
" break\n",
"\n",
"len(data[\"focus_value\"])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/hku/.local/lib/python3.8/site-packages/torch/nn/modules/loss.py:96: UserWarning: Using a target size (torch.Size([64])) that is different to the input size (torch.Size([64, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.\n",
" return F.l1_loss(input, target, reduction=self.reduction)\n"
]
},
{
"data": {
"text/plain": [
"(tensor(2.5787, grad_fn=<L1LossBackward0>),\n",
" tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),\n",
" tensor([-1.2805, -0.0943, -2.3645, 0.8542, -0.8047, -6.0020, 0.0000, -4.3352,\n",
" -1.8066, -2.7189, -6.4697, -3.2557, -4.2778, -5.0264, -3.4891, 0.0000,\n",
" -1.7181, -2.7314, 0.3324, -0.0943, -0.8991, 0.0000, -4.4178, 1.9723,\n",
" -3.0026, -5.5685, 3.8374, 3.8625, -0.4125, -4.1936, -1.5781, -1.6393,\n",
" -2.9583, -5.4933, -1.7807, -3.3135, -5.3423, -0.7978, -5.3971, -4.9412,\n",
" 0.0000, -4.4128, -5.7744, -5.2755, -1.0996, -5.7482, 0.0000, -0.1737,\n",
" -3.5851, -6.1429, -6.3642, -3.9653, -0.2081, -0.9539, -0.4159, -0.5388,\n",
" -1.3643, -4.4441, -1.5161, 0.6395, -5.4710, -2.6482, 0.0000, -2.6257],\n",
" dtype=torch.float64))"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import types\n",
"import importlib.machinery\n",
"focus_module = SourceFileLoader('focus_module', '../src/models/focus_module.py').load_module()\n",
"from focus_module import FocusLitModule\n",
"\n",
"model = FocusLitModule()\n",
"\n",
"model.step(data)"
]
}
],
"metadata": {
"interpreter": {
"hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac"
},
"kernelspec": {
"display_name": "Python 3.9.7 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|