{ "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0image_pathoriginal_filenamestudy_idscan_uuidfocus_valuestack_idobj_name
0031/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01631...I01631_X013_Y012_Z5107.jpg31fba56d57-656e-4b6f-ba63-e4ba3ad083f5-2.829531658220133
1131/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01632...I01632_X013_Y012_Z5175.jpg31fba56d57-656e-4b6f-ba63-e4ba3ad083f5-2.704081658220133
2231/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01633...I01633_X013_Y012_Z5722.jpg31fba56d57-656e-4b6f-ba63-e4ba3ad083f5-2.699181658220133
3331/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01634...I01634_X013_Y012_Z5244.jpg31fba56d57-656e-4b6f-ba63-e4ba3ad083f5-2.502661658220133
4431/fba56d57-656e-4b6f-ba63-e4ba3ad083f5/I01635...I01635_X013_Y012_Z5654.jpg31fba56d57-656e-4b6f-ba63-e4ba3ad083f5-2.364501658220133
...........................
56556531/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01406...I01406_X016_Y009_Z5361.jpg314c7e9e66-61a1-47ca-aa4e-340b0eef8db1-3.411471674918217
56656631/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01407...I01407_X016_Y009_Z5087.jpg314c7e9e66-61a1-47ca-aa4e-340b0eef8db1-3.054241674918217
56756731/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01408...I01408_X016_Y009_Z5292.jpg314c7e9e66-61a1-47ca-aa4e-340b0eef8db1-1.486081674918217
56856831/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01409...I01409_X016_Y009_Z5156.jpg314c7e9e66-61a1-47ca-aa4e-340b0eef8db1-0.528041674918217
56956931/4c7e9e66-61a1-47ca-aa4e-340b0eef8db1/I01410...I01410_X016_Y009_Z5224.jpg314c7e9e66-61a1-47ca-aa4e-340b0eef8db10.000001674918217
\n", "

570 rows × 8 columns

\n", "
" ], "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=),\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 }