本文整理汇总了Python中vggish_input.wavfile_to_examples方法的典型用法代码示例。如果您正苦于以下问题:Python vggish_input.wavfile_to_examples方法的具体用法?Python vggish_input.wavfile_to_examples怎么用?Python vggish_input.wavfile_to_examples使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vggish_input
的用法示例。
在下文中一共展示了vggish_input.wavfile_to_examples方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_vggish_features
# 需要导入模块: import vggish_input [as 别名]
# 或者: from vggish_input import wavfile_to_examples [as 别名]
def extract_vggish_features(paths, path2gt, model):
"""Extracts VGGish features and their corresponding ground_truth and identifiers (the path).
VGGish features are extracted from non-overlapping audio patches of 0.96 seconds,
where each audio patch covers 64 mel bands and 96 frames of 10 ms each.
We repeat ground_truth and identifiers to fit the number of extracted VGGish features.
"""
# 1) Extract log-mel spectrograms
first_audio = True
for p in paths:
if first_audio:
input_data = vggish_input.wavfile_to_examples(config['audio_folder'] + p)
ground_truth = np.repeat(path2gt[p], input_data.shape[0], axis=0)
identifiers = np.repeat(p, input_data.shape[0], axis=0)
first_audio = False
else:
tmp_in = vggish_input.wavfile_to_examples(config['audio_folder'] + p)
input_data = np.concatenate((input_data, tmp_in), axis=0)
tmp_gt = np.repeat(path2gt[p], tmp_in.shape[0], axis=0)
ground_truth = np.concatenate((ground_truth, tmp_gt), axis=0)
tmp_id = np.repeat(p, tmp_in.shape[0], axis=0)
identifiers = np.concatenate((identifiers, tmp_id), axis=0)
# 2) Load Tensorflow model to extract VGGish features
with tf.Graph().as_default(), tf.Session() as sess:
vggish_slim.define_vggish_slim(training=False)
vggish_slim.load_vggish_slim_checkpoint(sess, 'vggish_model.ckpt')
features_tensor = sess.graph.get_tensor_by_name(vggish_params.INPUT_TENSOR_NAME)
embedding_tensor = sess.graph.get_tensor_by_name(vggish_params.OUTPUT_TENSOR_NAME)
extracted_feat = sess.run([embedding_tensor], feed_dict={features_tensor: input_data})
feature = np.squeeze(np.asarray(extracted_feat))
return [feature, ground_truth, identifiers]
示例2: wavfile_to_features
# 需要导入模块: import vggish_input [as 别名]
# 或者: from vggish_input import wavfile_to_examples [as 别名]
def wavfile_to_features(wav_file):
assert os.path.exists(wav_file), '{} not exists!'.format(wav_file)
mel_features = vggish_input.wavfile_to_examples(wav_file)
return mel_features