blob: 35c53448c25cbeda4750929e9e3ea0ef17b2ecb9 [file] [log] [blame]
#!/usr/bin/env python
# coding=utf-8
# Copyright [2020] [Apache Software Foundation]
#
# 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
from ...common.log import get_logger
logger = get_logger('engine_base_data_handler')
__all__ = ['KerasSerializer']
class KerasSerializer(object):
def _serializer_load(self, object_file_path):
if object_file_path.split(os.sep)[-1] == 'model':
from tensorflow.keras.models import load_model
logger.info("Loading model {} using keras serializer.".format(object_file_path))
return load_model(object_file_path)
else:
return super(KerasSerializer, self)._serializer_load(object_file_path)
def _serializer_dump(self, obj, object_file_path):
if object_file_path.split(os.sep)[-1] == 'model':
logger.info("Saving model {} using keras serializer.".format(object_file_path))
obj.save(object_file_path)
else:
super(KerasSerializer, self)._serializer_dump(obj, object_file_path)