在不重新训练模型的情况下更改 SavedModel 的签名

Change signature of a SavedModel without retraining a model

提问人:Claydson Assis 提问时间:11/18/2023 更新时间:11/18/2023 访问量:5

问:

我有一个包含以下元数据的模型:

model.metadata()
{'codec': \<tf.Tensor: shape=(), dtype=string, numpy=b'pcm_s16le'\>,
'input_sample_rate': \<tf.Tensor: shape=(), dtype=int32, numpy=16000\>,
'context_width_samples': \<tf.Tensor: shape=(), dtype=int32, numpy=48000\>}
model.signatures
\_SignatureMap({'score': \<ConcreteFunction (\*, context_step_samples: TensorSpec(shape=(), dtype=tf.int64, name='context_step_samples'), waveform: TensorSpec(shape=(None, None, 1), dtype=tf.float32, name='waveform')) -\> Dict\[\['scores', TensorSpec(shape=(1, None, 115), dtype=tf.float32, name='scores')\]\] at 0x7F34E571A790\>, 'metadata': \<ConcreteFunction () -\> Dict\[\['codec', TensorSpec(shape=(), dtype=tf.string, name='codec')\], \['input_sample_rate', TensorSpec(shape=(), dtype=tf.int32, name='input_sample_rate')\], \['class_names', TensorSpec(shape=(115,), dtype=tf.string, name='class_names')\], \['context_width_samples', TensorSpec(shape=(), dtype=tf.int32, name='context_width_samples')\]\] at 0x7F34E51F2610\>})

如何在不重新训练模型的情况下将“input_sample_rate”更改为浮动?

我尝试了以下方法,但它以 int32 格式保存模型,也就是说,它没有改变:

@tf.function
def metadata_function():
    metadata = model.metadata()

    if 'input_sample_rate' in metadata:
        current_sample_rate = metadata['input_sample_rate']
        new_sample_rate = tf.cast(current_sample_rate, tf.float32)
        metadata['input_sample_rate'] = new_sample_rate

    return metadata

tf.saved_model.save(model, new_model_path, signatures={'metadata': metadata_function})
TensorFlow

评论


答: 暂无答案