forked from kserve/modelmesh-runtime-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation We don't currently support Keras .h5 format models. Modifications - Detect .h5 models in triton adapter logic and spawn a python process to convert to TF SavedModel - Limit how many such conversion processes can run concurrently, to avoid causing OOM of adapter container or impacting other adapter/puller operation Result HDF5 format files can be served with Triton via conversion to TF SavedModel format. Co-authored-by: nickhill <[email protected]>
- Loading branch information
Showing
9 changed files
with
148 additions
and
13 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 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
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,34 @@ | ||
# Copyright 2021 IBM Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
import sys | ||
import tensorflow as tf | ||
from tensorflow import keras | ||
|
||
def export_h5_to_pb(path_to_h5, export_path): | ||
try: | ||
model = tf.keras.models.load_model(path_to_h5) | ||
os.makedirs(export_path, exist_ok = True) | ||
model.save(export_path) | ||
except (ImportError, IOError) as e: | ||
print('Error raised when converting keras model: \n', e, file=sys.stderr) | ||
exit(e.errno) | ||
|
||
print('Converting keras model to tensorflow model. Argument(s) passed: {}'.format(str(sys.argv))) | ||
source_path = sys.argv[1] | ||
target_path = sys.argv[2] | ||
|
||
export_h5_to_pb(source_path, target_path) | ||
os.remove(source_path) | ||
print('Successfully converted keras model to tensorflow model.') |
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 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