-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert script from old tensorflow model to onnx (#482)
* tf2onnx convert approach * add ml_model integrity check * description added * Python3.10 checked * move script to experiment * removed extra file * Delete credsweeper/ml_model/ml_model.onnx.md5
- Loading branch information
Showing
6 changed files
with
28 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
h5py==3.10.0 | ||
keras==2.13.1 | ||
numpy==1.23.5 | ||
onnx==1.15.0 | ||
protobuf==3.20.3 | ||
tensorflow==2.13.1 | ||
tf2onnx==1.16.0 | ||
wrapt==1.14.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# tensorflow model may be obtained like this: git restore -s be06d6059f0def4f0fdb50444c08db4ce542173e -- ml_model.h5 | ||
# use virtual environment and the requirements.txt - there are very specific luke combination of packages verions | ||
# python -m venv .venv | ||
# . .venv/bin/activate | ||
# python -m pip install --upgrade pip | ||
# python -m pip install --requirement requirements.txt | ||
|
||
# [optional] thransform model form h5 to saved directory | ||
python -c 'import tensorflow as tf;model=tf.keras.models.load_model("ml_model.h5");model.save("ml_model")' | ||
# transform the model | ||
python -m tf2onnx.convert --saved-model ml_model --output ml_model.onnx --verbose --rename-inputs feature_input,line_input | ||
# md5sum for integrity | ||
md5sum --binary ml_model.onnx |