Skip to content

Commit 59a8a0e

Browse files
committed
downgrade onnx and tf2onnx, that don't work with newest tensorflow
1 parent 18cd120 commit 59a8a0e

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.0.11] - 2022-06-07
2+
### Changed
3+
- Downgrade `tf2onnx` and `onnx` versions, they don't work with newest TensorFlow version
4+
15
## [1.0.10] - 2022-06-06
26
### Changed
37
- Updated `BaseModelConfigs` in `mltu.configs.py` to include instance_attributes

mltu/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.0.10"
1+
__version__ = "1.0.11"
22

33
from .annotations.images import Image
44
from .annotations.images import CVImage

mltu/tensorflow/callbacks.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import os
2-
import tf2onnx
3-
import onnx
42
from keras.callbacks import Callback
53

64
import logging
@@ -22,22 +20,29 @@ def __init__(
2220
self.metadata = metadata
2321

2422
def on_train_end(self, logs=None):
25-
self.model.load_weights(self.saved_model_path)
26-
self.onnx_model_path = self.saved_model_path.replace(".h5", ".onnx")
27-
tf2onnx.convert.from_keras(self.model, output_path=self.onnx_model_path)
28-
29-
if self.metadata and isinstance(self.metadata, dict):
30-
# Load the ONNX model
31-
onnx_model = onnx.load(self.onnx_model_path)
32-
33-
# Add the metadata dictionary to the model's metadata_props attribute
34-
for key, value in self.metadata.items():
35-
meta = onnx_model.metadata_props.add()
36-
meta.key = key
37-
meta.value = value
38-
39-
# Save the modified ONNX model
40-
onnx.save(onnx_model, self.onnx_model_path)
23+
""" Converts the model to onnx format after training is finished. """
24+
try:
25+
import onnx
26+
import tf2onnx
27+
self.model.load_weights(self.saved_model_path)
28+
self.onnx_model_path = self.saved_model_path.replace(".h5", ".onnx")
29+
tf2onnx.convert.from_keras(self.model, output_path=self.onnx_model_path)
30+
31+
if self.metadata and isinstance(self.metadata, dict):
32+
# Load the ONNX model
33+
onnx_model = onnx.load(self.onnx_model_path)
34+
35+
# Add the metadata dictionary to the model's metadata_props attribute
36+
for key, value in self.metadata.items():
37+
meta = onnx_model.metadata_props.add()
38+
meta.key = key
39+
meta.value = value
40+
41+
# Save the modified ONNX model
42+
onnx.save(onnx_model, self.onnx_model_path)
43+
44+
except Exception as e:
45+
print(e)
4146

4247

4348
class TrainLogger(Callback):

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Pillow>=9.4.0
77
onnxruntime>=1.15.0 # onnxruntime-gpu for GPU support
88
librosa>=0.9.2
99
matplotlib
10-
onnx>=1.14.0
11-
tf2onnx>=1.14.0
10+
onnx==1.12.0
11+
tf2onnx==1.12.0

0 commit comments

Comments
 (0)