Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
17 changes: 12 additions & 5 deletions docs/source/notebooks/data/zea_data_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"1. Loading data from single file with `zea.File`\n",
"2. Loading data from a group of files with `zea.Dataset`\n",
"3. Loading data in batches with dataloading utilities with `zea.backend.tensorflow.make_dataloader`"
"3. Loading data in batches with dataloading utilities via `zea.backend.tensorflow.make_dataloader`. This requires a working TensorFlow installation!"
]
},
{
Expand Down Expand Up @@ -86,12 +86,12 @@
}
],
"source": [
"import keras\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import zea\n",
"from zea import init_device, load_file\n",
"from zea.visualize import set_mpl_style\n",
"from zea.backend.tensorflow import make_dataloader"
"from zea.visualize import set_mpl_style"
]
},
{
Expand Down Expand Up @@ -380,7 +380,11 @@
"source": [
"## Loading data with `make_dataloader`\n",
"\n",
"In machine and deep learning workflows, we often want more features like batching, shuffling, and parallel data loading. The `zea.backend.tensorflow.make_dataloader` function provides a convenient way to create a TensorFlow data loader from a zea dataset. This does require a working TensorFlow installation, but does work in combination with any other backend as well. This dataloader is particularly useful for training models. It is important that there is some consistency in the dataset, which is not the case for [PICMUS](https://www.creatis.insa-lyon.fr/Challenge/IEEE_IUS_2016/home). Therefore in this example we will use a small part of the [CAMUS](https://www.creatis.insa-lyon.fr/Challenge/camus/) dataset."
"In machine and deep learning workflows, we often want more features like batching, shuffling, and parallel data loading. The `zea.backend.tensorflow.make_dataloader` function provides a convenient way to create a TensorFlow data loader from a zea dataset. \n",
"\n",
"🚨 Note! This does require a working TensorFlow installation, but does work in combination with any other backend as well. We are [working on migrating](https://github.com/tue-bmd/zea/pull/256) to [Grain](https://github.com/google/grain), which will provide a backend-agnostic dataloader in the near future.\n",
"\n",
"This dataloader is particularly useful for training models. It is important that there is some consistency in the dataset, which is not the case for [PICMUS](https://www.creatis.insa-lyon.fr/Challenge/IEEE_IUS_2016/home). Therefore in this example we will use a small part of the [CAMUS](https://www.creatis.insa-lyon.fr/Challenge/camus/) dataset."
Comment on lines +383 to +387
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Polish wording in the dataloader section for readability.

There’s a small double-space typo and slightly awkward phrasing in the warning line.

✏️ Suggested doc text cleanup
- In machine and deep learning workflows, we often want more features like batching, shuffling, and parallel data loading. The `zea.backend.tensorflow.make_dataloader` function provides a convenient way to create a TensorFlow data loader from a zea  dataset. 
+ In machine and deep learning workflows, we often want more features like batching, shuffling, and parallel data loading. The `zea.backend.tensorflow.make_dataloader` function provides a convenient way to create a TensorFlow data loader from a zea dataset.

- 🚨 Note! This does require a working TensorFlow installation, but does work in combination with any other backend as well. We are [working on migrating](https://github.com/tue-bmd/zea/pull/256) to [Grain](https://github.com/google/grain), which will provide a backend-agnostic dataloader in the near future.
+ 🚨 Note: This requires a working TensorFlow installation, but it can be used in combination with other backends. We are [working on migrating](https://github.com/tue-bmd/zea/pull/256) to [Grain](https://github.com/google/grain), which will provide a backend-agnostic dataloader in the near future.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/source/notebooks/data/zea_data_example.ipynb` around lines 383 - 387,
Edit the dataloader documentation paragraph (around the
zea.backend.tensorflow.make_dataloader mention) to fix the double-space and
rephrase the warning for clarity: change "🚨 Note! This does require a working
TensorFlow installation, but does work in combination with any other backend as
well. We are [working on migrating]..." to a concise sentence like "Note: a
working TensorFlow installation is required, though the dataloader can be used
alongside other backends; we are migrating to Grain for a backend-agnostic
dataloader (see PR link)." Ensure the double space is removed and the text
references zea.backend.tensorflow.make_dataloader and the Grain migration link.

]
},
{
Expand Down Expand Up @@ -459,6 +463,8 @@
}
],
"source": [
"from zea.backend.tensorflow import make_dataloader # needs TensorFlow to be installed\n",
"\n",
"dataset_path = \"hf://zeahub/camus-sample/val\"\n",
"dataloader = make_dataloader(\n",
" dataset_path,\n",
Expand Down Expand Up @@ -556,7 +562,8 @@
"pipeline = zea.Pipeline.from_config(config)\n",
"parameters = pipeline.prepare_parameters(probe=probe, scan=scan)\n",
"\n",
"images = pipeline(data=data, **parameters)[\"data\"]"
"images = pipeline(data=data, **parameters)[\"data\"]\n",
"images = keras.ops.convert_to_numpy(images)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions zea/data/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def load_data(
self,
data_type,
indices: Tuple[Union[list, slice, int], ...] | List[int] | int | None = None,
):
) -> np.ndarray:
"""Load data from the file.

.. include:: ../common/file_indexing.rst
Expand Down Expand Up @@ -537,7 +537,7 @@ def load_file(
data_type="raw_data",
indices: Tuple[Union[list, slice, int], ...] | List[int] | int | None = None,
scan_kwargs: dict = None,
):
) -> Tuple[np.ndarray, Scan, Probe]:
"""Loads a zea data files (h5py file).

Returns the data together with a scan object containing the parameters
Expand Down
6 changes: 3 additions & 3 deletions zea/ops/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Dict, List, Union
from typing import Any, Dict, List, Union

import keras
import numpy as np
Expand Down Expand Up @@ -303,7 +303,7 @@ def _get_timed_operations(self):
self.timer = FunctionTimer()
return [self.timer(op, name=op.__class__.__name__) for op in self._pipeline_layers]

def call(self, **inputs):
def call(self, **inputs) -> Dict[str, Any]:
"""Process input data through the pipeline."""
for operation in self._callable_layers:
try:
Expand All @@ -325,7 +325,7 @@ def call(self, **inputs):
inputs = outputs
return outputs

def __call__(self, return_numpy=False, **inputs):
def __call__(self, return_numpy=False, **inputs) -> Dict[str, Any]:
"""Process input data through the pipeline."""

if any(key in inputs for key in ["probe", "scan", "config"]) or any(
Expand Down
Loading