def predict(self, filename=None, y=None, sr=None, outputs=None):
'''Predict annotations
Parameters
----------
filename : str (optional)
Path to audio file
y, sr : (optional)
Audio buffer and sample rate
outputs : (optional)
Pre-computed model outputs as produced by `CremaModel.outputs`.
If provided, then predictions are derived from these instead of
`filename` or `(y, sr)`.
.. note:: At least one of `filename`, `y, sr` must be provided.
Returns
-------
jams.Annotation
The predicted annotation
'''
# Pump the input features
output_key = self.model.output_names[0]
if outputs is None:
outputs = self.outputs(filename=filename, y=y, sr=sr)
# Invert the prediction. This is always the first output layer.
ann = self.pump[output_key].inverse(outputs[output_key])
# Populate the metadata
ann.annotation_metadata.version = self.version
ann.annotation_metadata.annotation_tools = 'CREMA {}'.format(version)
ann.annotation_metadata.data_source = 'program'
ann.duration = librosa.get_duration(y=y, sr=sr, filename=filename)
return ann
评论列表
文章目录