Make use of GetDataDependencyFilepath and JoinPath to build paths which will

work across operating systems.

The previous implementation doesn't work correctly on Windows.

PiperOrigin-RevId: 296454787
Change-Id: I6e674c379329b31e18eace99e496a1f7bb0cf419
This commit is contained in:
Brian Atkinson 2020-02-21 09:53:59 -08:00 committed by TensorFlower Gardener
parent 1b21715713
commit d8e1504c05
2 changed files with 38 additions and 35 deletions
tensorflow/core/kernels

View File

@ -6109,6 +6109,7 @@ tf_cc_test(
"//tensorflow/core:protos_all_cc",
"//tensorflow/core:test",
"//tensorflow/core:test_main",
"//tensorflow/core/platform:resource_loader",
"//third_party/eigen3",
],
)

View File

@ -23,6 +23,8 @@ limitations under the License.
#include "tensorflow/core/kernels/spectrogram_test_utils.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/platform/path.h"
#include "tensorflow/core/platform/resource_loader.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/types.h"
@ -30,17 +32,24 @@ namespace tensorflow {
using ::std::complex;
const char kInputFilename[] =
"core/kernels/spectrogram_test_data/short_test_segment.wav";
string InputFilename() {
return io::JoinPath("tensorflow", "core", "kernels", "spectrogram_test_data",
"short_test_segment.wav");
}
string ExpectedFilename() {
return io::JoinPath("tensorflow", "core", "kernels", "spectrogram_test_data",
"short_test_segment_spectrogram.csv.bin");
}
const char kExpectedFilename[] =
"core/kernels/spectrogram_test_data/short_test_segment_spectrogram.csv.bin";
const int kDataVectorLength = 257;
const int kNumberOfFramesInTestData = 178;
const char kExpectedNonPowerOfTwoFilename[] =
"core/kernels/spectrogram_test_data/"
"short_test_segment_spectrogram_400_200.csv.bin";
string ExpectedNonPowerOfTwoFilename() {
return io::JoinPath("tensorflow", "core", "kernels", "spectrogram_test_data",
"short_test_segment_spectrogram_400_200.csv.bin");
}
const int kNonPowerOfTwoDataVectorLength = 257;
const int kNumberOfFramesInNonPowerOfTwoTestData = 228;
@ -206,9 +215,8 @@ TEST(SpectrogramTest, ReInitializationWorks) {
Spectrogram sgram;
sgram.Initialize(512, 256);
std::vector<double> input;
CHECK(ReadWaveFileToVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kInputFilename),
&input));
CHECK(
ReadWaveFileToVector(GetDataDependencyFilepath(InputFilename()), &input));
std::vector<std::vector<complex<double>>> first_output;
std::vector<std::vector<complex<double>>> second_output;
sgram.Initialize(512, 256);
@ -233,14 +241,13 @@ TEST(SpectrogramTest, ComputedComplexDataAgreeWithMatlab) {
Spectrogram sgram;
sgram.Initialize(512, 256);
std::vector<double> input;
CHECK(ReadWaveFileToVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kInputFilename),
&input));
CHECK(
ReadWaveFileToVector(GetDataDependencyFilepath(InputFilename()), &input));
EXPECT_EQ(kInputDataLength, input.size());
std::vector<std::vector<complex<double>>> expected_output;
ASSERT_TRUE(ReadRawFloatFileToComplexVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kExpectedFilename),
kDataVectorLength, &expected_output));
GetDataDependencyFilepath(ExpectedFilename()), kDataVectorLength,
&expected_output));
EXPECT_EQ(kNumberOfFramesInTestData, expected_output.size());
EXPECT_EQ(kDataVectorLength, expected_output[0].size());
std::vector<std::vector<complex<double>>> output;
@ -253,16 +260,15 @@ TEST(SpectrogramTest, ComputedFloatComplexDataAgreeWithMatlab) {
Spectrogram sgram;
sgram.Initialize(512, 256);
std::vector<double> double_input;
CHECK(ReadWaveFileToVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kInputFilename),
&double_input));
CHECK(ReadWaveFileToVector(GetDataDependencyFilepath(InputFilename()),
&double_input));
std::vector<float> input;
input.assign(double_input.begin(), double_input.end());
EXPECT_EQ(kInputDataLength, input.size());
std::vector<std::vector<complex<double>>> expected_output;
ASSERT_TRUE(ReadRawFloatFileToComplexVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kExpectedFilename),
kDataVectorLength, &expected_output));
GetDataDependencyFilepath(ExpectedFilename()), kDataVectorLength,
&expected_output));
EXPECT_EQ(kNumberOfFramesInTestData, expected_output.size());
EXPECT_EQ(kDataVectorLength, expected_output[0].size());
std::vector<std::vector<complex<float>>> output;
@ -275,14 +281,13 @@ TEST(SpectrogramTest, ComputedSquaredMagnitudeDataAgreeWithMatlab) {
Spectrogram sgram;
sgram.Initialize(512, 256);
std::vector<double> input;
CHECK(ReadWaveFileToVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kInputFilename),
&input));
CHECK(
ReadWaveFileToVector(GetDataDependencyFilepath(InputFilename()), &input));
EXPECT_EQ(kInputDataLength, input.size());
std::vector<std::vector<complex<double>>> expected_output;
ASSERT_TRUE(ReadRawFloatFileToComplexVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kExpectedFilename),
kDataVectorLength, &expected_output));
GetDataDependencyFilepath(ExpectedFilename()), kDataVectorLength,
&expected_output));
EXPECT_EQ(kNumberOfFramesInTestData, expected_output.size());
EXPECT_EQ(kDataVectorLength, expected_output[0].size());
std::vector<std::vector<double>> output;
@ -295,16 +300,15 @@ TEST(SpectrogramTest, ComputedFloatSquaredMagnitudeDataAgreeWithMatlab) {
Spectrogram sgram;
sgram.Initialize(512, 256);
std::vector<double> double_input;
CHECK(ReadWaveFileToVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kInputFilename),
&double_input));
CHECK(ReadWaveFileToVector(GetDataDependencyFilepath(InputFilename()),
&double_input));
EXPECT_EQ(kInputDataLength, double_input.size());
std::vector<float> input;
input.assign(double_input.begin(), double_input.end());
std::vector<std::vector<complex<double>>> expected_output;
ASSERT_TRUE(ReadRawFloatFileToComplexVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kExpectedFilename),
kDataVectorLength, &expected_output));
GetDataDependencyFilepath(ExpectedFilename()), kDataVectorLength,
&expected_output));
EXPECT_EQ(kNumberOfFramesInTestData, expected_output.size());
EXPECT_EQ(kDataVectorLength, expected_output[0].size());
std::vector<std::vector<float>> output;
@ -321,14 +325,12 @@ TEST(SpectrogramTest, ComputedNonPowerOfTwoComplexDataAgreeWithMatlab) {
Spectrogram sgram;
sgram.Initialize(400, 200);
std::vector<double> input;
CHECK(ReadWaveFileToVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(), kInputFilename),
&input));
CHECK(
ReadWaveFileToVector(GetDataDependencyFilepath(InputFilename()), &input));
EXPECT_EQ(kInputDataLength, input.size());
std::vector<std::vector<complex<double>>> expected_output;
ASSERT_TRUE(ReadRawFloatFileToComplexVector(
tensorflow::io::JoinPath(testing::TensorFlowSrcRoot(),
kExpectedNonPowerOfTwoFilename),
GetDataDependencyFilepath(ExpectedNonPowerOfTwoFilename()),
kNonPowerOfTwoDataVectorLength, &expected_output));
EXPECT_EQ(kNumberOfFramesInNonPowerOfTwoTestData, expected_output.size());
EXPECT_EQ(kNonPowerOfTwoDataVectorLength, expected_output[0].size());