Skip to content
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

fix keras example #1498

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion examples/face_detection_yolov8onnx_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
anyhow.workspace = true
clap = { version = "4.5.9", features = ["derive"] }
image.workspace = true
tract-onnx = {path="../../onnx", vversion="=0.21.7-pre" }
tract-onnx = {path="../../onnx", version="=0.21.7-pre" }
2 changes: 1 addition & 1 deletion examples/keras-tract-tf2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.ipynb_checkpoints/
Anaconda3-2022.10-Linux-x86_64.sh
anaconda/

venv
Binary file modified examples/keras-tract-tf2/example.onnx
Binary file not shown.
7 changes: 2 additions & 5 deletions examples/keras-tract-tf2/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation
import onnxmltools

import tf2onnx
import tract

# Define a simple demo model and training data
Expand All @@ -22,9 +21,7 @@
model.fit(data, labels, epochs=10, batch_size=32)

# Save the model in ONNX format to pass to tract
onnx_model = onnxmltools.convert_keras(model)

onnxmltools.utils.save_model(onnx_model, 'example.onnx')
model_proto, _ = tf2onnx.convert.from_keras(model, output_path="example.onnx")

# Generate a demo input, and run the model in Tensorflow
input = np.random.random((1,100)).astype(np.float32)
Expand Down
Binary file modified examples/keras-tract-tf2/io.npz
Binary file not shown.
13 changes: 9 additions & 4 deletions examples/keras-tract-tf2/no-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

set -e


sudo apt-get update
sudo apt-get install -y libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 python3-virtualenv

virtualenv venv
. venv/bin/activate
# Install required libraries
sudo apt-get install -y libgl1-mesa-glx libegl1-mesa libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 python3.8 python3.8-venv

# Create a Python 3.8 virtual environmen
python3.8 -m venv venv
source venv/bin/activate


pip install -r requirements.txt
python example.py
cargo run
cargo run
10 changes: 4 additions & 6 deletions examples/keras-tract-tf2/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
tensorflow
numpy
tf2onnx
onnxmltools
onnxconverter_common
tract
tensorflow==2.11.0
numpy==1.24.4
tf2onnx==1.13.0
tract==0.21.6