Skip to content

471 Update CSV datasets tutorial #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions modules/csv_datasets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
}
],
"source": [
"dataset = CSVDataset(filename=filepath1)\n",
"dataset = CSVDataset(src=filepath1)\n",
"# construct pandas table to show the data, `CSVDataset` inherits from PyTorch Dataset\n",
"print(pd.DataFrame(dataset.data))"
]
Expand Down Expand Up @@ -308,7 +308,7 @@
}
],
"source": [
"dataset = CSVDataset([filepath1, filepath2, filepath3], on=\"subject_id\")\n",
"dataset = CSVDataset(src=[filepath1, filepath2, filepath3], on=\"subject_id\")\n",
"# construct pandas table to show the joined data of 3 tables\n",
"print(pd.DataFrame(dataset.data))"
]
Expand Down Expand Up @@ -339,7 +339,7 @@
],
"source": [
"dataset = CSVDataset(\n",
" filename=[filepath1, filepath2, filepath3],\n",
" src=[filepath1, filepath2, filepath3],\n",
" row_indices=[[0, 2], 3], # load row: 0, 1, 3\n",
" col_names=[\"subject_id\", \"label\", \"ehr_1\", \"ehr_7\", \"meta_1\"],\n",
")\n",
Expand Down Expand Up @@ -396,7 +396,7 @@
],
"source": [
"dataset = CSVDataset(\n",
" filename=[filepath1, filepath2, filepath3],\n",
" src=[filepath1, filepath2, filepath3],\n",
" col_names=[\"subject_id\", \"image\", *[f\"ehr_{i}\" for i in range(11)], \"meta_0\", \"meta_1\", \"meta_2\"],\n",
" col_groups={\"ehr\": [f\"ehr_{i}\" for i in range(11)], \"meta\": [\"meta_0\", \"meta_1\", \"meta_2\"]},\n",
")\n",
Expand Down Expand Up @@ -433,7 +433,7 @@
],
"source": [
"dataset = CSVDataset(\n",
" filename=[filepath1, filepath2, filepath3],\n",
" src=[filepath1, filepath2, filepath3],\n",
" col_names=[\"subject_id\", \"label\", \"ehr_0\", \"ehr_1\", \"ehr_9\", \"meta_1\"],\n",
" col_types={\"label\": {\"default\": \"No label\"}, \"ehr_1\": {\"type\": int, \"default\": 0}},\n",
" how=\"outer\", # will load the NaN values in this merge mode\n",
Expand Down Expand Up @@ -481,7 +481,7 @@
],
"source": [
"dataset = CSVDataset(\n",
" filename=[filepath1, filepath2, filepath3],\n",
" src=[filepath1, filepath2, filepath3],\n",
" col_groups={\"ehr\": [f\"ehr_{i}\" for i in range(5)]},\n",
" transform=Compose([LoadImaged(keys=\"image\"), ToNumpyd(keys=\"ehr\")]),\n",
")\n",
Expand Down Expand Up @@ -527,7 +527,7 @@
}
],
"source": [
"dataset = CSVIterableDataset(filename=[filepath1, filepath2, filepath3], shuffle=False)\n",
"dataset = CSVIterableDataset(src=[filepath1, filepath2, filepath3], shuffle=False)\n",
"# set num workers = 0 for mac / win\n",
"num_workers = 2 if sys.platform == \"linux\" else 0\n",
"dataloader = DataLoader(dataset=dataset, num_workers=num_workers, batch_size=2)\n",
Expand All @@ -546,7 +546,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -563,7 +563,7 @@
"dataset = CSVIterableDataset(\n",
" chunksize=2,\n",
" buffer_size=4,\n",
" filename=[filepath1, filepath2, filepath3],\n",
" src=[filepath1, filepath2, filepath3],\n",
" col_names=[\"subject_id\", \"label\", \"ehr_1\", \"ehr_7\", \"meta_1\"],\n",
" transform=ToNumpyd(keys=\"ehr_1\"),\n",
" shuffle=True,\n",
Expand Down
2 changes: 1 addition & 1 deletion modules/tcia_csv_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
" download_url(url=u, filepath=f)\n",
"\n",
" super().__init__(\n",
" filename=filename,\n",
" src=filename,\n",
" row_indices=row_indices,\n",
" col_names=col_names,\n",
" col_types=col_types,\n",
Expand Down