1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #define EIGEN_USE_THREADS 17 18 #include <functional> 19 #include <memory> 20 #include <vector> 21 22 #include "tensorflow/cc/client/client_session.h" 23 #include "tensorflow/cc/ops/audio_ops.h" 24 #include "tensorflow/cc/ops/const_op.h" 25 #include "tensorflow/cc/ops/math_ops.h" 26 #include "tensorflow/core/framework/tensor_testutil.h" 27 #include "tensorflow/core/framework/types.h" 28 #include "tensorflow/core/framework/types.pb.h" 29 #include "tensorflow/core/kernels/ops_util.h" 30 #include "tensorflow/core/lib/core/status_test_util.h" 31 #include "tensorflow/core/platform/test.h" 32 33 namespace tensorflow { 34 namespace ops { 35 namespace { 36 37 TEST(MfccOpTest, SimpleTest) { 38 Scope root = Scope::DisabledShapeInferenceScope(); 39 40 Tensor spectrogram_tensor(DT_FLOAT, TensorShape({1, 1, 513})); 41 test::FillIota<float>(&spectrogram_tensor, 1.0f); 42 43 Output spectrogram_const_op = Const(root.WithOpName("spectrogram_const_op"), 44 Input::Initializer(spectrogram_tensor)); 45 46 Output sample_rate_const_op = 47 Const(root.WithOpName("sample_rate_const_op"), 22050); 48 49 Mfcc mfcc_op = Mfcc(root.WithOpName("mfcc_op"), spectrogram_const_op, 50 sample_rate_const_op); 51 52 TF_ASSERT_OK(root.status()); 53 54 ClientSession session(root); 55 std::vector<Tensor> outputs; 56 57 TF_EXPECT_OK( 58 session.Run(ClientSession::FeedType(), {mfcc_op.output}, &outputs)); 59 60 const Tensor& mfcc_tensor = outputs[0]; 61 62 EXPECT_EQ(3, mfcc_tensor.dims()); 63 EXPECT_EQ(13, mfcc_tensor.dim_size(2)); 64 EXPECT_EQ(1, mfcc_tensor.dim_size(1)); 65 EXPECT_EQ(1, mfcc_tensor.dim_size(0)); 66 67 test::ExpectTensorNear<float>( 68 mfcc_tensor, 69 test::AsTensor<float>( 70 {29.13970072, -6.41568601, -0.61903012, -0.96778652, -0.26819878, 71 -0.40907028, -0.15614748, -0.23203119, -0.10481487, -0.1543029, 72 -0.0769791, -0.10806114, -0.06047613}, 73 TensorShape({1, 1, 13})), 74 1e-3); 75 } 76 77 } // namespace 78 } // namespace ops 79 } // namespace tensorflow 80