* Change `reduce_logsumexp` to internally use `reshape` rather than `squeeze` since the latter requires the `axis` arg to be a Python `list`. PiperOrigin-RevId: 183396533 * Kernel utils to support broadcast add and mul. PiperOrigin-RevId: 183397494 * Updating sparsify_gather. PiperOrigin-RevId: 183402917 * [tf.data] Move slow-path-related code into the slow path in IteratorHandleOp::Compute(). This slightly reduces the amount of work performed when an iterator is accessed (after the first access), and potentially reduces contention if concurrent steps are accessing the same iterator. PiperOrigin-RevId: 183406221 * Cleanup: Ran clang-format on all *.{cc,h} in under grappler. PiperOrigin-RevId: 183406440 * Increase shard count of //third_party/tensorflow/python:nn_batchnorm_test to avoid timeouts When run under asan, the test runs for about 5 minutes, and sometimes longer, causing frequent timeouts. This change increases the shard count of the test to 4, which brings the run time of the longest running shard under asan to about 2 minutes. PiperOrigin-RevId: 183414888 * Add available choices to toco flags and fix minor formatting issues. PiperOrigin-RevId: 183415713 * Performance improvements to some GPU code to use shared locks instead of unique locks for some hotspot cases. PiperOrigin-RevId: 183418559 * [XLA] Improve error message for bad slices. PiperOrigin-RevId: 183420038 * Fix py3 build rules for all py tests under py2tf. PiperOrigin-RevId: 183422144 * Fix bug with Operation._control_inputs setter. PiperOrigin-RevId: 183422192 * Make softmax_op_test.py work with C API enabled. PiperOrigin-RevId: 183422829 * Cleanup: Ran clang-format on all *.{cc,h} files in tensorflow/core/kernels. PiperOrigin-RevId: 183423961 * Fix the documentation for the dense layer for how rank > 2 inputs are handled. PiperOrigin-RevId: 183425868 * Cleanup: Ran clang-format on all *.{cc,h} in tensorflow/core/ops. PiperOrigin-RevId: 183429339
66 lines
2.2 KiB
C++
66 lines
2.2 KiB
C++
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
|
|
|
|
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.
|
|
==============================================================================*/
|
|
|
|
#include <math.h>
|
|
|
|
#include "tensorflow/core/kernels/mfcc.h"
|
|
|
|
#include "tensorflow/core/platform/logging.h"
|
|
|
|
namespace tensorflow {
|
|
|
|
const double kDefaultUpperFrequencyLimit = 4000;
|
|
const double kDefaultLowerFrequencyLimit = 20;
|
|
const double kFilterbankFloor = 1e-12;
|
|
const int kDefaultFilterbankChannelCount = 40;
|
|
const int kDefaultDCTCoefficientCount = 13;
|
|
|
|
Mfcc::Mfcc()
|
|
: initialized_(false),
|
|
lower_frequency_limit_(kDefaultLowerFrequencyLimit),
|
|
upper_frequency_limit_(kDefaultUpperFrequencyLimit),
|
|
filterbank_channel_count_(kDefaultFilterbankChannelCount),
|
|
dct_coefficient_count_(kDefaultDCTCoefficientCount) {}
|
|
|
|
bool Mfcc::Initialize(int input_length, double input_sample_rate) {
|
|
bool initialized = mel_filterbank_.Initialize(
|
|
input_length, input_sample_rate, filterbank_channel_count_,
|
|
lower_frequency_limit_, upper_frequency_limit_);
|
|
initialized &=
|
|
dct_.Initialize(filterbank_channel_count_, dct_coefficient_count_);
|
|
initialized_ = initialized;
|
|
return initialized;
|
|
}
|
|
|
|
void Mfcc::Compute(const std::vector<double>& spectrogram_frame,
|
|
std::vector<double>* output) const {
|
|
if (!initialized_) {
|
|
LOG(ERROR) << "Mfcc not initialized.";
|
|
return;
|
|
}
|
|
std::vector<double> working;
|
|
mel_filterbank_.Compute(spectrogram_frame, &working);
|
|
for (int i = 0; i < working.size(); ++i) {
|
|
double val = working[i];
|
|
if (val < kFilterbankFloor) {
|
|
val = kFilterbankFloor;
|
|
}
|
|
working[i] = log(val);
|
|
}
|
|
dct_.Compute(working, output);
|
|
}
|
|
|
|
} // namespace tensorflow
|