precise-lite/scripts/convert_h5.py

57 lines
1.7 KiB
Python
Raw Normal View History

2022-12-04 08:37:35 +00:00
#!/usr/bin/env python3
# Copyright 2019 Mycroft AI Inc.
#
# 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.
from prettyparse import Usage
from precise_lite.model import create_model, ModelParams
from precise_lite.scripts.train import BaseScript
class ConvertH5(BaseScript):
usage = Usage('''
Convert a model to h5 format
:model str
Keras model file (.net) to load from
:-s --sensitivity float 0.2
Weighted loss bias. Higher values decrease increase positives
:-nv --no-validation
Disable accuracy and validation calculation
to improve speed during training
:-em --extra-metrics
Add extra metrics during training
...
''') | BaseScript.usage
def __init__(self, args):
super().__init__(args)
params = ModelParams(
skip_acc=self.args.no_validation, extra_metrics=self.args.extra_metrics,
loss_bias=1.0 - self.args.sensitivity
)
self.model = create_model(self.args.model, params)
def run(self):
print('Converting model to h5')
self.model.save(self.args.model + '.h5') # Save with '.h5' file extension to force format
main = ConvertH5.run_main
if __name__ == '__main__':
main()