Skip to content

feat: add support for Tensorflow dataset - #729

Merged
luisremis merged 6 commits into
developfrom
fix/issue-2
May 21, 2026
Merged

feat: add support for Tensorflow dataset#729
luisremis merged 6 commits into
developfrom
fix/issue-2

Conversation

@ad-claw000

Copy link
Copy Markdown
Contributor

Summary

Adds data loading support from Tensorflow as a replacement for load/preprocess/prepare for training, completing issue #2. This implements an ApertureDBTensorFlowDataset mirroring the design of ApertureDBDataset for PyTorch, allowing users to easily load image and label batches from ApertureDB directly into a tf.data.Dataset with dynamic label type inference.

Verification

Created a unit test test_tf_connector.py that creates an ApertureDBTensorFlowDataset and validates it retrieves the correct number of images with both native constraints and simulated multiprocessing environments. Verified that syntax validation and data generation match the dataset structure.

Fixes #2

Copilot AI review requested due to automatic review settings May 21, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a TensorFlow-facing data-loading path so ApertureDB query results can be consumed as a tf.data.Dataset, intended to mirror the existing PyTorch dataset wrapper and address issue #2.

Changes:

  • Introduces ApertureDBTensorFlowDataset to stream batched FindImage results into a tf.data.Dataset via from_generator.
  • Adds a TensorFlow connector test that validates end-to-end iteration and batching/prefetch behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
aperturedb/TensorFlowDataset.py New TensorFlow dataset wrapper that fetches images in server-side batches and exposes them as a tf.data.Dataset with inferred label dtype.
test/test_tf_connector.py New integration-style test that iterates through the TensorFlow dataset and validates total item counts, including a batched/prefetched pipeline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_tf_connector.py Outdated
Comment on lines +20 to +22
if tf.shape(img)[0] < 0:
logger.error("Empty image?")
assert True == False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed the tensor condition in 113772e

Comment thread test/test_tf_connector.py Outdated
Comment on lines +2 to +4
import os
import logging
from typing import Union

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed unused imports in 113772e

Comment thread aperturedb/TensorFlowDataset.py
ad-claw000 and others added 2 commits May 21, 2026 12:58
- Remove unused imports
- Fix tensor shape check condition
- Add test for dynamic label dtype
Copilot AI review requested due to automatic review settings May 21, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread aperturedb/TensorFlowDataset.py Outdated

if self.label_prop:
entities = r[self.find_image_idx]["FindImage"]["entities"]
self.batch_labels = [l[self.label_prop] for l in entities]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f8f8754

Comment thread test/test_tf_connector.py Outdated
if time_taken != 0:
logger.info(f"Throughput (imgs/s): {expected_length / time_taken}")

def test_nativeContraints(self, db, utils, images):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f8f8754

Comment thread test/test_tf_connector.py
Comment thread test/test_tf_connector.py Outdated
Comment on lines +57 to +85
def test_datasetWithMultiprocessing(self, db, utils, images):
len_limit = utils.count_images()
# This is a hack against a bug in batch API.
dim = 224 if isinstance(db, ConnectorRest) else 225
query = [{
"FindImage": {
"constraints": {
"age": [">=", 0]
},
"operations": [
{
"type": "resize",
"width": dim,
"height": dim
}
],
"results": {
"list": ["license"],
"limit": len_limit
}
}
}]

dataset_wrapper = ApertureDBTensorFlowDataset(
db, query, label_prop="license")
dataset = dataset_wrapper.get_dataset()
# Test batched dataset
batched_dataset = dataset.batch(10).prefetch(tf.data.AUTOTUNE)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f8f8754

Copilot AI review requested due to automatic review settings May 21, 2026 15:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread aperturedb/TensorFlowDataset.py
Comment thread aperturedb/TensorFlowDataset.py Outdated
Comment on lines +55 to +61
self.query[self.find_image_idx]["FindImage"]["blobs"] = True

try:
_, r, b = execute_query(
client=self.client, query=self.query, blobs=[])
batch = r[self.find_image_idx]["FindImage"]["batch"]
self.total_elements = batch["total_elements"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6a5ed2a

Comment thread test/test_tf_connector.py Outdated
start = time.time()
count = 0
for imgs, labels in batched_dataset:
count += imgs.shape[0]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6a5ed2a

@luisremis
luisremis merged commit e672d7b into develop May 21, 2026
2 checks passed
@luisremis
luisremis deleted the fix/issue-2 branch May 21, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Tensorflow

3 participants