Решение состоит в том, чтобы создать tf.Module
с функциями для каждого определения подписи:
class MyModule(tf.Module):
def __init__(self, model, other_variable):
self.model = model
self._other_variable = other_variable
@tf.function(input_signature=[tf.TensorSpec(shape=(None, None, 1), dtype=tf.float32)])
def score(self, waveform):
result = self.model(waveform)
return { "scores": results }
@tf.function(input_signature=[])
def metadata(self):
return { "other_variable": self._other_variable }
, а затем сохранить модуль (не модель):
module = MyModule(model, 1234)
tf.saved_model.save(module, export_path, signatures={ "score": module.score, "metadata": module.metadata })
Протестировано сМодель Keras на TF2.