Skip to content

Upgrade to TensorFlow 2.18.0+ and Python 3.12, add TensorFlow support to pipeline models #561

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

jetkan-yk
Copy link
Collaborator

@jetkan-yk jetkan-yk commented May 18, 2025

Description

Upgrade to TensorFlow 2.18.0+ and Python 3.12, add TensorFlow support to pipeline models. Fixes: #326

Motivation and Context

This PR adds TensorFlow support to pipeline models and upgrades the TensorFlow version to 2.18.0+, which relaxes the Python version to 3.12. As discussed in #326 this is a breaking change because TensorFlow >=2.18 requires Keras 3 while TensorFlow < 2.18 requires Keras 2 with a different set of Keras APIs.

If the user wishes to run older versions of TensorFlow, they should run it as a pipeline and implement the predict function to call the appropriate Keras API, e.g. line 31 below:

def predict(self, image_paths: Iterable[str]) -> np.ndarray:
processed_images = []
for img_path in image_paths:
img = tf.keras.utils.load_img(img_path, target_size=(28, 28), color_mode="grayscale")
img_array = tf.keras.utils.img_to_array(img)
img_array /= 255.0
processed_images.append(img_array)
image_batch = np.stack(processed_images, axis=0)
predictions = self.model.predict(image_batch)
predicted_classes = np.argmax(predictions, axis=1)
return predicted_classes

Type of Change

  • feat: A new feature

How to Test

Tested:

  • Complete unit tests with Python 3.10 (without aiverify-apigw)
  • Complete unit tests with Python 3.11
  • Complete unit tests with Python 3.12
  • End-to-end tests with aiverify-portal
SCR-20250518-ppbv

Note:

  1. aiverify-apigw requires Python>=3.11 therefore is not tested in Python 3.10
  2. One test in aiverify-test-engine/tests/io/test_tensorflowpipeline.py is failing because the required asset is not available until this PR is merged into main branch

Checklist

Please check all the boxes that apply to this pull request using "x":

  • I have tested the changes locally and verified that they work as expected.
  • I have added or updated the necessary documentation (README, API docs, etc.).
  • I have added appropriate unit tests or functional tests for the changes made.
  • I have followed the project's coding conventions and style guidelines.
  • I have rebased my branch onto the latest commit of the main branch.
  • I have squashed or reorganized my commits into logical units.
  • I have added any necessary dependencies or packages to the project's build configuration.
  • I have performed a self-review of my own code.
  • I have read, understood and agree to the Developer Certificate of Origin below, which this project utilises.

Screenshots (if applicable)

[If the changes involve visual modifications, include screenshots or GIFs that demonstrate the changes.]

Additional Notes

[Add any additional information or context that might be relevant to reviewers.]

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
   have the right to submit it under the open source license
   indicated in the file; or

(b) The contribution is based upon previous work that, to the best
   of my knowledge, is covered under an appropriate open source
   license and I have the right under that license to submit that
   work with modifications, whether created in whole or in part
   by me, under the same open source license (unless I am
   permitted to submit under a different license), as indicated
   in the file; or

(c) The contribution was provided directly to me by some other
   person who certified (a), (b) or (c) and I have not modified
   it.

(d) I understand and agree that this project and the contribution
   are public and that a record of the contribution (including all
   personal information I submit with it, including my sign-off) is
   maintained indefinitely and may be redistributed consistent with
   this project or the open source license(s) involved.

@jetkan-yk jetkan-yk requested a review from timlrx May 18, 2025 10:21
@jetkan-yk jetkan-yk self-assigned this May 18, 2025
@jetkan-yk jetkan-yk added the feature Should build this label May 18, 2025
@jetkan-yk jetkan-yk requested a review from imda-peckyoke May 19, 2025 04:03
@imda-peckyoke
Copy link
Contributor

As this is a breaking change, we may need to bump up the aiverify-test-engine as major release, e.g. v2.1.0. Also requires QA to tests through all the plugins with algorithms. @imda-benedictlee @HanFai-IMDA

@jetkan-yk
Copy link
Collaborator Author

As this is a breaking change, we may need to bump up the aiverify-test-engine as major release, e.g. v2.1.0. Also requires QA to tests through all the plugins with algorithms. @imda-benedictlee @HanFai-IMDA

Done

@imda-benedictlee
Copy link
Contributor

Technical Test Working in UI:

Screenshot 2025-05-21 at 7 42 35 PM Screenshot 2025-05-21 at 7 42 39 PM Screenshot 2025-05-21 at 7 42 43 PM Screenshot 2025-05-21 at 7 42 47 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Should build this
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dependencies] Update tensorflow and numpy
3 participants