Skip to content
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
81 changes: 81 additions & 0 deletions notebooks/functions.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "a4a784f3-7130-4c1d-aa11-eb02d614ee76",
"metadata": {},
"source": [
"# Functions for other notebooks to use"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "405f62a3-f187-436b-a94c-1658014c9aae",
"metadata": {},
"outputs": [],
"source": [
"def predict_on_array(\n",
" dataset: MapDataset,\n",
" model: torch.nn.Module,\n",
" output_tensor_dim: dict[str, int],\n",
" new_dim: list[str],\n",
" resample_dim: list[str],\n",
" batch_size: int=16\n",
"):\n",
" # TODO set up output array\n",
" output_size = {}\n",
" for key, size in output_tensor_dim.items():\n",
" if key in new_dim:\n",
" # This is a new axis, size is determined\n",
" # by the tensor size.\n",
" output_size[key] = output_tensor_dim[key]\n",
" else:\n",
" # This is a resampled axis, determine the new size\n",
" # by the ratio of the batchgen window to the tensor size.\n",
" window_size = ds.X_generator.input_dims[key]\n",
" tensor_size = output_tensor_dim[key]\n",
" resample_ratio = tensor_size / window_size\n",
"\n",
" temp_output_size = ds.X_generator.ds.sizes[key] * resample_ratio\n",
" assert temp_output_size.is_integer()\n",
" output_size[key] = int(temp_output_size)\n",
" \n",
" output_array = np.zeros(tuple(output_size.values()))\n",
" output_n = np.zeros(output_array.shape)\n",
"\n",
" '''\n",
" # Prepare data laoder\n",
" loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size)\n",
" for batch in loader:\n",
" out_batch = model(batch).detach().numpy()\n",
" # TODO write each example to the output array\n",
" '''\n",
"\n",
" # TODO aggregate output\n",
" return output_array"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading