Internal change

PiperOrigin-RevId: 522291640
This commit is contained in:
MediaPipe Team 2023-04-06 03:13:21 -07:00 committed by Copybara-Service
parent 289f51651f
commit e894ae9cf4
30 changed files with 195 additions and 191 deletions

View File

@ -59,7 +59,7 @@ class GraphTensorsPacketGenerator : public PacketGenerator {
for (int i = 0; i < options.tensor_tag_size(); ++i) {
const std::string& tensor_tag = options.tensor_tag(i);
const int32 tensor_num_nodes = options.tensor_num_nodes(i);
const int32_t tensor_num_nodes = options.tensor_num_nodes(i);
(*tensor_map)[tensor_tag] =
tf::Tensor(tf::DT_FLOAT, tf::TensorShape{1, tensor_num_nodes});
(*tensor_map)[tensor_tag].flat<float>().setZero();

View File

@ -40,7 +40,7 @@ std::unique_ptr<tf::Tensor> ImageFrameToNormalizedTensor(
const int cols = image_frame.Width();
const int rows = image_frame.Height();
const int channels = image_frame.NumberOfChannels();
const uint8* pixel = image_frame.PixelData();
const uint8_t* pixel = image_frame.PixelData();
const int width_padding = image_frame.WidthStep() - cols * channels;
auto tensor = ::absl::make_unique<tf::Tensor>(
tf::DT_FLOAT, tf::TensorShape({rows, cols, channels}));
@ -188,10 +188,10 @@ absl::Status ImageFrameToTensorCalculator::Process(CalculatorContext* cc) {
// Copy pixel data from the ImageFrame to the tensor.
if (data_type == tf::DT_UINT8) {
uint8* dst = tensor->flat<uint8>().data();
uint8_t* dst = tensor->flat<uint8_t>().data();
video_frame.CopyToBuffer(dst, num_components);
} else if (data_type == tf::DT_UINT16) {
uint16* dst = tensor->flat<uint16>().data();
uint16_t* dst = tensor->flat<uint16_t>().data();
video_frame.CopyToBuffer(dst, num_components);
} else {
float* dst = tensor->flat<float>().data();

View File

@ -30,8 +30,8 @@ namespace mediapipe {
namespace tf = tensorflow;
using RandomEngine = std::mt19937_64;
const uint8 kGray8 = 42;
const uint16 kGray16 = 4242;
const uint8_t kGray8 = 42;
const uint16_t kGray16 = 4242;
const float kFloat = 42.0;
const uint kRed = 255;
const uint kGreen = 36;
@ -40,7 +40,7 @@ const uint kAlpha = 42;
const int kFixedNoiseWidth = 3;
const int kFixedNoiseHeight = 2;
const uint8 kFixedNoiseData[kFixedNoiseWidth * kFixedNoiseHeight * 3] = {
const uint8_t kFixedNoiseData[kFixedNoiseWidth * kFixedNoiseHeight * 3] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 123, 213, 156, 9, 10, 11, 255, 0, 128};
class ImageFrameToTensorCalculatorTest : public ::testing::Test {
@ -69,8 +69,8 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
void AddRGBFrame(int width, int height) {
auto image_frame =
::absl::make_unique<ImageFrame>(ImageFormat::SRGB, width, height);
const uint8 color[] = {kRed, kGreen, kBlue};
SetToColor<uint8>(color, image_frame.get());
const uint8_t color[] = {kRed, kGreen, kBlue};
SetToColor<uint8_t>(color, image_frame.get());
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(image_frame.release()).At(Timestamp(0)));
}
@ -79,8 +79,8 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
void AddRGBAFrame(int width, int height) {
auto image_frame =
::absl::make_unique<ImageFrame>(ImageFormat::SRGBA, width, height);
const uint8 color[] = {kRed, kGreen, kBlue, kAlpha};
SetToColor<uint8>(color, image_frame.get());
const uint8_t color[] = {kRed, kGreen, kBlue, kAlpha};
SetToColor<uint8_t>(color, image_frame.get());
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(image_frame.release()).At(Timestamp(0)));
}
@ -89,8 +89,8 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
void AddGray8Frame(int width, int height) {
auto image_frame =
::absl::make_unique<ImageFrame>(ImageFormat::GRAY8, width, height);
const uint8 gray[] = {kGray8};
SetToColor<uint8>(gray, image_frame.get());
const uint8_t gray[] = {kGray8};
SetToColor<uint8_t>(gray, image_frame.get());
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(image_frame.release()).At(Timestamp(0)));
}
@ -99,8 +99,8 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
void AddGray16Frame(int width, int height) {
auto image_frame =
::absl::make_unique<ImageFrame>(ImageFormat::GRAY16, width, height, 1);
const uint16 gray[] = {kGray16};
SetToColor<uint16>(gray, image_frame.get());
const uint16_t gray[] = {kGray16};
SetToColor<uint16_t>(gray, image_frame.get());
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(image_frame.release()).At(Timestamp(0)));
}
@ -121,10 +121,10 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
ImageFormat::SRGB, kFixedNoiseWidth, kFixedNoiseHeight);
// Copy fixed noise data into the ImageFrame.
const uint8* src = kFixedNoiseData;
uint8* pixels = image_frame->MutablePixelData();
const uint8_t* src = kFixedNoiseData;
uint8_t* pixels = image_frame->MutablePixelData();
for (int y = 0; y < kFixedNoiseHeight; ++y) {
uint8* row = pixels + y * image_frame->WidthStep();
uint8_t* row = pixels + y * image_frame->WidthStep();
std::memcpy(row, src, kFixedNoiseWidth * 3);
src += kFixedNoiseWidth * 3;
}
@ -134,7 +134,7 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
}
// Adds a packet with an 8-bit RGB ImageFrame containing random noise.
void AddRandomRGBFrame(int width, int height, uint32 seed) {
void AddRandomRGBFrame(int width, int height, uint32_t seed) {
RandomEngine random(seed);
std::uniform_int_distribution<int> uniform_dist{
0, std::numeric_limits<uint8_t>::max()};
@ -143,9 +143,9 @@ class ImageFrameToTensorCalculatorTest : public ::testing::Test {
// Copy "noisy data" into the ImageFrame.
const int num_components_per_row = width * image_frame->NumberOfChannels();
uint8* pixels = image_frame->MutablePixelData();
uint8_t* pixels = image_frame->MutablePixelData();
for (int y = 0; y < kFixedNoiseHeight; ++y) {
uint8* p = pixels + y * image_frame->WidthStep();
uint8_t* p = pixels + y * image_frame->WidthStep();
for (int i = 0; i < num_components_per_row; ++i) {
p[i] = uniform_dist(random);
}
@ -188,8 +188,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, SolidRedRGBFrame) {
ASSERT_EQ(3, shape.dim_size(2));
// Verify that the data in the tensor is correct.
const uint8* pixels =
reinterpret_cast<const uint8*>(tensor.tensor_data().data());
const uint8_t* pixels =
reinterpret_cast<const uint8_t*>(tensor.tensor_data().data());
for (int i = 0; i < num_pixels; ++i) {
ASSERT_EQ(kRed, pixels[0]);
ASSERT_EQ(kGreen, pixels[1]);
@ -229,8 +229,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, SolidRedRGBAFrame) {
ASSERT_EQ(4, shape.dim_size(2));
// Verify that the data in the tensor is correct.
const uint8* pixels =
reinterpret_cast<const uint8*>(tensor.tensor_data().data());
const uint8_t* pixels =
reinterpret_cast<const uint8_t*>(tensor.tensor_data().data());
for (int i = 0; i < num_pixels; ++i) {
ASSERT_EQ(kRed, pixels[0]);
ASSERT_EQ(kGreen, pixels[1]);
@ -271,8 +271,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, SolidGray8Frame) {
ASSERT_EQ(1, shape.dim_size(2));
// Verify that the data in the tensor is correct.
const uint8* pixels =
reinterpret_cast<const uint8*>(tensor.tensor_data().data());
const uint8_t* pixels =
reinterpret_cast<const uint8_t*>(tensor.tensor_data().data());
for (int i = 0; i < num_pixels; ++i) {
ASSERT_EQ(kGray8, pixels[0]);
++pixels;
@ -310,8 +310,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, SolidGray16Frame) {
ASSERT_EQ(1, shape.dim_size(2));
// Verify that the data in the tensor is correct.
const uint16* pixels =
reinterpret_cast<const uint16*>(tensor.tensor_data().data());
const uint16_t* pixels =
reinterpret_cast<const uint16_t*>(tensor.tensor_data().data());
for (int i = 0; i < num_pixels; ++i) {
ASSERT_EQ(kGray16, pixels[0]);
++pixels;
@ -381,8 +381,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, FixedNoiseRGBFrame) {
// Verify that the data in the tensor is correct.
const int num_pixels = kFixedNoiseWidth * kFixedNoiseHeight;
const uint8* pixels =
reinterpret_cast<const uint8*>(tensor.tensor_data().data());
const uint8_t* pixels =
reinterpret_cast<const uint8_t*>(tensor.tensor_data().data());
for (int i = 0; i < num_pixels; ++i) {
ASSERT_EQ(kFixedNoiseData[i], pixels[i]);
}
@ -390,7 +390,7 @@ TEST_F(ImageFrameToTensorCalculatorTest, FixedNoiseRGBFrame) {
TEST_F(ImageFrameToTensorCalculatorTest, RandomRGBFrame) {
// Run the calculator and verify that one output is generated.
const uint32 seed = 1234;
const uint32_t seed = 1234;
const int height = 2;
for (int width = 1; width <= 33; ++width) {
runner_.reset(
@ -417,10 +417,10 @@ TEST_F(ImageFrameToTensorCalculatorTest, RandomRGBFrame) {
std::uniform_int_distribution<int> uniform_dist{
0, std::numeric_limits<uint8_t>::max()};
const int num_pixels = width * height;
const uint8* pixels =
reinterpret_cast<const uint8*>(tensor.tensor_data().data());
const uint8_t* pixels =
reinterpret_cast<const uint8_t*>(tensor.tensor_data().data());
for (int i = 0; i < num_pixels; ++i) {
const uint8 expected = uniform_dist(random);
const uint8_t expected = uniform_dist(random);
ASSERT_EQ(expected, pixels[i]);
}
}
@ -435,8 +435,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, FixedRGBFrameWithMeanAndStddev) {
// Create a single pixel image of fixed color #0080ff.
auto image_frame = ::absl::make_unique<ImageFrame>(ImageFormat::SRGB, 1, 1);
const uint8 color[] = {0, 128, 255};
SetToColor<uint8>(color, image_frame.get());
const uint8_t color[] = {0, 128, 255};
SetToColor<uint8_t>(color, image_frame.get());
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(image_frame.release()).At(Timestamp(0)));
@ -464,8 +464,8 @@ TEST_F(ImageFrameToTensorCalculatorTest, FixedRGBFrameWithRepeatMeanAndStddev) {
// Create a single pixel image of fixed color #0080ff.
auto image_frame = ::absl::make_unique<ImageFrame>(ImageFormat::SRGB, 1, 1);
const uint8 color[] = {0, 128, 255};
SetToColor<uint8>(color, image_frame.get());
const uint8_t color[] = {0, 128, 255};
SetToColor<uint8_t>(color, image_frame.get());
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(image_frame.release()).At(Timestamp(0)));

View File

@ -264,7 +264,7 @@ TEST_F(LappedTensorBufferCalculatorTest, OneToThreeBatchTimestampOffset) {
ASSERT_EQ(num_timesteps - buffer_size + 1, output_packets.size());
for (int i = 0; i < num_timesteps - buffer_size + 1; ++i) {
for (int j = 0; j < buffer_size; ++j) {
int64 value = output_packets[i].Timestamp().Value();
int64_t value = output_packets[i].Timestamp().Value();
ASSERT_EQ(i + timestamp_offset, value);
}
}
@ -294,7 +294,7 @@ TEST_F(LappedTensorBufferCalculatorTest,
runner_->Outputs().Index(0).packets;
ASSERT_EQ(output_size, output_packets.size());
for (int i = 0; i < output_size; ++i) {
int64 value = output_packets[i].Timestamp().Value();
int64_t value = output_packets[i].Timestamp().Value();
ASSERT_EQ(i * overlap + timestamp_offset, value);
}
const std::vector<Packet>& output_timestamps =

View File

@ -39,7 +39,7 @@ constexpr char kAddDimensionOptionsString[] =
namespace tf = tensorflow;
using RandomEngine = std::mt19937_64;
const uint32 kSeed = 1234;
const uint32_t kSeed = 1234;
const int kNumSizes = 8;
const int sizes[kNumSizes][2] = {{1, 1}, {12, 1}, {1, 9}, {2, 2},
{5, 3}, {7, 13}, {16, 32}, {101, 2}};
@ -47,7 +47,7 @@ const int sizes[kNumSizes][2] = {{1, 1}, {12, 1}, {1, 9}, {2, 2},
class MatrixToTensorCalculatorTest : public ::testing::Test {
protected:
// Adds a packet with a matrix filled with random values in [0,1].
void AddRandomMatrix(int num_rows, int num_columns, uint32 seed) {
void AddRandomMatrix(int num_rows, int num_columns, uint32_t seed) {
RandomEngine random(kSeed);
std::uniform_real_distribution<> uniform_dist(0, 1.0);
auto matrix = ::absl::make_unique<Matrix>();

View File

@ -137,7 +137,7 @@ class ObjectDetectionTensorsToDetectionsCalculator : public CalculatorBase {
const auto& tensor_dim_to_squeeze_field =
cc->Options<ObjectDetectionsTensorToDetectionsCalculatorOptions>()
.tensor_dim_to_squeeze();
tensor_dims_to_squeeze_ = std::vector<int32>(
tensor_dims_to_squeeze_ = std::vector<int32_t>(
tensor_dim_to_squeeze_field.begin(), tensor_dim_to_squeeze_field.end());
std::sort(tensor_dims_to_squeeze_.rbegin(), tensor_dims_to_squeeze_.rend());
cc->SetOffset(0);
@ -210,7 +210,7 @@ class ObjectDetectionTensorsToDetectionsCalculator : public CalculatorBase {
private:
std::map<int, std::string>* label_map_;
std::vector<int32> tensor_dims_to_squeeze_;
std::vector<int32_t> tensor_dims_to_squeeze_;
absl::StatusOr<tf::Tensor> MaybeSqueezeDims(const std::string& tensor_tag,
const tf::Tensor& input_tensor) {

View File

@ -89,9 +89,9 @@ namespace mpms = mediapipe::mediasequence;
// }
// }
namespace {
uint8 ConvertFloatToByte(const float float_value) {
uint8_t ConvertFloatToByte(const float float_value) {
float clamped_value = std::clamp(0.0f, 1.0f, float_value);
return static_cast<uint8>(clamped_value * 255.0 + .5f);
return static_cast<uint8_t>(clamped_value * 255.0 + .5f);
}
} // namespace
@ -157,7 +157,7 @@ class PackMediaSequenceCalculator : public CalculatorBase {
cc->Inputs().Tag(tag).Set<std::vector<float>>();
}
if (absl::StartsWith(tag, kIntFeaturePrefixTag)) {
cc->Inputs().Tag(tag).Set<std::vector<int64>>();
cc->Inputs().Tag(tag).Set<std::vector<int64_t>>();
}
if (absl::StartsWith(tag, kBytesFeaturePrefixTag)) {
cc->Inputs().Tag(tag).Set<std::vector<std::string>>();
@ -285,7 +285,7 @@ class PackMediaSequenceCalculator : public CalculatorBase {
}
absl::Status VerifySize() {
const int64 MAX_PROTO_BYTES = 1073741823;
const int64_t MAX_PROTO_BYTES = 1073741823;
std::string id = mpms::HasExampleId(*sequence_)
? mpms::GetExampleId(*sequence_)
: "example";
@ -434,7 +434,7 @@ class PackMediaSequenceCalculator : public CalculatorBase {
mpms::AddFeatureTimestamp(key, cc->InputTimestamp().Value(),
sequence_.get());
mpms::AddFeatureInts(key,
cc->Inputs().Tag(tag).Get<std::vector<int64>>(),
cc->Inputs().Tag(tag).Get<std::vector<int64_t>>(),
sequence_.get());
}
if (absl::StartsWith(tag, kBytesFeaturePrefixTag) &&

View File

@ -227,11 +227,11 @@ TEST_F(PackMediaSequenceCalculatorTest, PacksTwoIntLists) {
int num_timesteps = 2;
for (int i = 0; i < num_timesteps; ++i) {
auto vi_ptr = ::absl::make_unique<std::vector<int64>>(2, 2 << i);
auto vi_ptr = ::absl::make_unique<std::vector<int64_t>>(2, 2 << i);
runner_->MutableInputs()
->Tag(kIntFeatureTestTag)
.packets.push_back(Adopt(vi_ptr.release()).At(Timestamp(i)));
vi_ptr = ::absl::make_unique<std::vector<int64>>(2, 2 << i);
vi_ptr = ::absl::make_unique<std::vector<int64_t>>(2, 2 << i);
runner_->MutableInputs()
->Tag(kIntFeatureOtherTag)
.packets.push_back(Adopt(vi_ptr.release()).At(Timestamp(i)));
@ -257,10 +257,10 @@ TEST_F(PackMediaSequenceCalculatorTest, PacksTwoIntLists) {
for (int i = 0; i < num_timesteps; ++i) {
ASSERT_EQ(i, mpms::GetFeatureTimestampAt("TEST", output_sequence, i));
ASSERT_THAT(mpms::GetFeatureIntsAt("TEST", output_sequence, i),
::testing::ElementsAreArray(std::vector<int64>(2, 2 << i)));
::testing::ElementsAreArray(std::vector<int64_t>(2, 2 << i)));
ASSERT_EQ(i, mpms::GetFeatureTimestampAt("OTHER", output_sequence, i));
ASSERT_THAT(mpms::GetFeatureIntsAt("OTHER", output_sequence, i),
::testing::ElementsAreArray(std::vector<int64>(2, 2 << i)));
::testing::ElementsAreArray(std::vector<int64_t>(2, 2 << i)));
}
}

View File

@ -47,7 +47,7 @@ class TensorSqueezeDimensionsCalculator : public CalculatorBase {
<< options_.DebugString();
if (options_.dim_size() > 0) {
remove_dims_ =
std::vector<int32>(options_.dim().begin(), options_.dim().end());
std::vector<int32_t>(options_.dim().begin(), options_.dim().end());
std::sort(remove_dims_.rbegin(), remove_dims_.rend());
remove_dims_initialized_ = true;
}
@ -87,7 +87,7 @@ class TensorSqueezeDimensionsCalculator : public CalculatorBase {
private:
TensorSqueezeDimensionsCalculatorOptions options_;
std::vector<int32> remove_dims_;
std::vector<int32_t> remove_dims_;
bool remove_dims_initialized_;
void InitializeToRemoveAllSingletonDimensions(

View File

@ -32,7 +32,7 @@ class TensorSqueezeDimensionsCalculatorTest : public ::testing::Test {
// Initialize tensor_ with deterministic values.
tensor_shape_ = tf::TensorShape(std::vector<tf::int64>({1, 3, 1, 3, 1}));
tensor_ = tf::Tensor(tf::DT_INT32, tensor_shape_);
auto tensor_values = tensor_.tensor<int32, 5>();
auto tensor_values = tensor_.tensor<int32_t, 5>();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
tensor_values(0, i, 0, j, 0) = i * (j + 1);
@ -71,7 +71,7 @@ TEST_F(TensorSqueezeDimensionsCalculatorTest, CanSqueezeAllSingleDimensions) {
const tf::Tensor& output_tensor = output_packets[0].Get<tf::Tensor>();
const tf::TensorShape expected_shape(std::vector<tf::int64>({3, 3}));
EXPECT_EQ(expected_shape.DebugString(), output_tensor.shape().DebugString());
const auto tensor_values = output_tensor.tensor<int32, 2>();
const auto tensor_values = output_tensor.tensor<int32_t, 2>();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
const int expected_value = i * (j + 1);
@ -107,7 +107,7 @@ TEST_F(TensorSqueezeDimensionsCalculatorTest, CanSqueezeSpecifiedDimensions) {
const tf::Tensor& output_tensor = output_packets[0].Get<tf::Tensor>();
const tf::TensorShape expected_shape(std::vector<tf::int64>({3, 1, 3}));
EXPECT_EQ(expected_shape.DebugString(), output_tensor.shape().DebugString());
const auto tensor_values = output_tensor.tensor<int32, 3>();
const auto tensor_values = output_tensor.tensor<int32_t, 3>();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
const int expected_value = i * (j + 1);

View File

@ -94,7 +94,7 @@ absl::Status TensorToImageFrameCalculator::Open(CalculatorContext* cc) {
absl::Status TensorToImageFrameCalculator::Process(CalculatorContext* cc) {
const tf::Tensor& input_tensor = cc->Inputs().Tag(kTensor).Get<tf::Tensor>();
int32 depth = 1;
int32_t depth = 1;
if (input_tensor.dims() != 2) { // Depth is 1 for 2D tensors.
CHECK(3 == input_tensor.dims())
<< "Only 2 or 3-D Tensors can be converted to frames. Instead got: "
@ -104,10 +104,10 @@ absl::Status TensorToImageFrameCalculator::Process(CalculatorContext* cc) {
RET_CHECK_EQ(depth, 3) << "Output tensor depth must be 3 or 1.";
}
}
int32 height = input_tensor.dim_size(0);
int32 width = input_tensor.dim_size(1);
int32_t height = input_tensor.dim_size(0);
int32_t width = input_tensor.dim_size(1);
auto format = (depth == 3 ? ImageFormat::SRGB : ImageFormat::GRAY8);
const int32 total_size = height * width * depth;
const int32_t total_size = height * width * depth;
::std::unique_ptr<const ImageFrame> output;
if (input_tensor.dtype() == tensorflow::DT_FLOAT) {
@ -123,7 +123,7 @@ absl::Status TensorToImageFrameCalculator::Process(CalculatorContext* cc) {
}
output = ::absl::make_unique<ImageFrame>(
format, width, height, width * depth, buffer.release(),
[total_size](uint8* ptr) {
[total_size](uint8_t* ptr) {
::operator delete[](ptr, total_size,
std::align_val_t(EIGEN_MAX_ALIGN_BYTES));
});
@ -139,7 +139,7 @@ absl::Status TensorToImageFrameCalculator::Process(CalculatorContext* cc) {
auto copy = new tf::Tensor(input_tensor);
output = ::absl::make_unique<const ImageFrame>(
format, width, height, width * depth, copy->flat<uint8_t>().data(),
[copy](uint8*) { delete copy; });
[copy](uint8_t*) { delete copy; });
} else {
return absl::InvalidArgumentError(
absl::StrCat("Expected float or uint8 tensor, received ",

View File

@ -64,7 +64,7 @@ TYPED_TEST(TensorToImageFrameCalculatorTest, Converts3DTensorToImageFrame) {
tensor_vec[i] = i % 255;
}
const int64 time = 1234;
const int64_t time = 1234;
runner->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -79,7 +79,7 @@ TYPED_TEST(TensorToImageFrameCalculatorTest, Converts3DTensorToImageFrame) {
EXPECT_EQ(kHeight, output_image.Height());
for (int i = 0; i < kWidth * kHeight * 3; ++i) {
const uint8 pixel_value = output_image.PixelData()[i];
const uint8_t pixel_value = output_image.PixelData()[i];
EXPECT_EQ(i % 255, pixel_value);
}
}
@ -100,7 +100,7 @@ TYPED_TEST(TensorToImageFrameCalculatorTest, Converts3DTensorToImageFrameGray) {
tensor_vec[i] = i % 255;
}
const int64 time = 1234;
const int64_t time = 1234;
runner->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -115,7 +115,7 @@ TYPED_TEST(TensorToImageFrameCalculatorTest, Converts3DTensorToImageFrameGray) {
EXPECT_EQ(kHeight, output_image.Height());
for (int i = 0; i < kWidth * kHeight; ++i) {
const uint8 pixel_value = output_image.PixelData()[i];
const uint8_t pixel_value = output_image.PixelData()[i];
EXPECT_EQ(i % 255, pixel_value);
}
}
@ -137,7 +137,7 @@ TYPED_TEST(TensorToImageFrameCalculatorTest,
tensor_vec[i] = i % 255;
}
const int64 time = 1234;
const int64_t time = 1234;
runner->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -152,7 +152,7 @@ TYPED_TEST(TensorToImageFrameCalculatorTest,
EXPECT_EQ(kHeight, output_image.Height());
for (int i = 0; i < kWidth * kHeight; ++i) {
const uint8 pixel_value = output_image.PixelData()[i];
const uint8_t pixel_value = output_image.PixelData()[i];
EXPECT_EQ(i % 255, pixel_value);
}
}

View File

@ -193,8 +193,9 @@ absl::Status TensorToMatrixCalculator::Process(CalculatorContext* cc) {
const tf::Tensor& input_tensor = cc->Inputs().Tag(kTensor).Get<tf::Tensor>();
CHECK(1 == input_tensor.dims() || 2 == input_tensor.dims())
<< "Only 1-D or 2-D Tensors can be converted to matrices.";
const int32 length = input_tensor.dim_size(input_tensor.dims() - 1);
const int32 width = (1 == input_tensor.dims()) ? 1 : input_tensor.dim_size(0);
const int32_t length = input_tensor.dim_size(input_tensor.dims() - 1);
const int32_t width =
(1 == input_tensor.dims()) ? 1 : input_tensor.dim_size(0);
if (header_.has_num_channels()) {
RET_CHECK_EQ(length, header_.num_channels())
<< "The number of channels at runtime does not match the header.";

View File

@ -88,7 +88,7 @@ TEST_F(TensorToMatrixCalculatorTest, Converts1DTensorToMatrix) {
tensor_vec(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -114,7 +114,7 @@ TEST_F(TensorToMatrixCalculatorTest, Converts2DTensorofWidthOneToMatrix) {
for (int i = 0; i < 4; ++i) {
slice(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -143,7 +143,7 @@ TEST_F(TensorToMatrixCalculatorTest, Converts2DTensorToMatrix) {
slice(i * 4 + j) = static_cast<float>(i * j);
}
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -174,7 +174,7 @@ TEST_F(TensorToMatrixCalculatorTest, ConvertsWithReferenceTimeSeriesHeader) {
tensor_vec(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -206,7 +206,7 @@ TEST_F(TensorToMatrixCalculatorTest, TimeSeriesOverridesWork) {
tensor_vec(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Tag(kTensor).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));

View File

@ -53,7 +53,7 @@ TEST_F(TensorToVectorFloatCalculatorTest, ConvertsToVectorFloat) {
tensor_vec(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -82,7 +82,7 @@ TEST_F(TensorToVectorFloatCalculatorTest, ConvertsBatchedToVectorVectorFloat) {
slice(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -112,7 +112,7 @@ TEST_F(TensorToVectorFloatCalculatorTest, FlattenShouldTakeAllDimensions) {
slice(i) = static_cast<float>(1 << i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));

View File

@ -36,8 +36,8 @@ class TensorToVectorIntCalculator : public CalculatorBase {
absl::Status Process(CalculatorContext* cc) override;
private:
void TokenizeVector(std::vector<int64>* vector) const;
void RemoveOverlapVector(std::vector<int64>* vector);
void TokenizeVector(std::vector<int64_t>* vector) const;
void RemoveOverlapVector(std::vector<int64_t>* vector);
TensorToVectorIntCalculatorOptions options_;
int32_t overlapping_values_;
@ -56,10 +56,10 @@ absl::Status TensorToVectorIntCalculator::GetContract(CalculatorContract* cc) {
const auto& options = cc->Options<TensorToVectorIntCalculatorOptions>();
if (options.tensor_is_2d()) {
RET_CHECK(!options.flatten_nd());
cc->Outputs().Index(0).Set<std::vector<std::vector<int64>>>(
cc->Outputs().Index(0).Set<std::vector<std::vector<int64_t>>>(
/* "Output vector<vector<float>>." */);
} else {
cc->Outputs().Index(0).Set<std::vector<int64>>(
cc->Outputs().Index(0).Set<std::vector<int64_t>>(
// Output vector<float>.
);
}
@ -91,19 +91,20 @@ absl::Status TensorToVectorIntCalculator::Process(CalculatorContext* cc) {
RET_CHECK(2 == input_tensor.dims())
<< "Expected 2-dimensional Tensor, but the tensor shape is: "
<< input_tensor.shape().DebugString();
auto output = absl::make_unique<std::vector<std::vector<int64>>>(
input_tensor.dim_size(0), std::vector<int64>(input_tensor.dim_size(1)));
auto output = absl::make_unique<std::vector<std::vector<int64_t>>>(
input_tensor.dim_size(0),
std::vector<int64_t>(input_tensor.dim_size(1)));
for (int i = 0; i < input_tensor.dim_size(0); ++i) {
auto& instance_output = output->at(i);
if (tf::DT_INT32 == input_tensor.dtype()) {
const auto& slice =
input_tensor.Slice(i, i + 1).unaligned_flat<int32>();
input_tensor.Slice(i, i + 1).unaligned_flat<int32_t>();
for (int j = 0; j < input_tensor.dim_size(1); ++j) {
instance_output.at(j) = slice(j);
}
} else {
const auto& slice =
input_tensor.Slice(i, i + 1).unaligned_flat<int64>();
input_tensor.Slice(i, i + 1).unaligned_flat<int64_t>();
for (int j = 0; j < input_tensor.dim_size(1); ++j) {
instance_output.at(j) = slice(j);
}
@ -119,14 +120,14 @@ absl::Status TensorToVectorIntCalculator::Process(CalculatorContext* cc) {
<< "tensor shape is: " << input_tensor.shape().DebugString();
}
auto output =
absl::make_unique<std::vector<int64>>(input_tensor.NumElements());
absl::make_unique<std::vector<int64_t>>(input_tensor.NumElements());
if (tf::DT_INT32 == input_tensor.dtype()) {
const auto& tensor_values = input_tensor.flat<int32>();
const auto& tensor_values = input_tensor.flat<int32_t>();
for (int i = 0; i < input_tensor.NumElements(); ++i) {
output->at(i) = tensor_values(i);
}
} else {
const auto& tensor_values = input_tensor.flat<int64>();
const auto& tensor_values = input_tensor.flat<int64_t>();
for (int i = 0; i < input_tensor.NumElements(); ++i) {
output->at(i) = tensor_values(i);
}
@ -140,7 +141,7 @@ absl::Status TensorToVectorIntCalculator::Process(CalculatorContext* cc) {
}
void TensorToVectorIntCalculator::RemoveOverlapVector(
std::vector<int64>* vector) {
std::vector<int64_t>* vector) {
if (options_.overlap() <= 0) {
return;
}
@ -155,11 +156,11 @@ void TensorToVectorIntCalculator::RemoveOverlapVector(
}
void TensorToVectorIntCalculator::TokenizeVector(
std::vector<int64>* vector) const {
std::vector<int64_t>* vector) const {
if (!options_.tensor_is_token()) {
return;
}
std::vector<int64> tokens;
std::vector<int64_t> tokens;
for (int i = 0; i < vector->size(); ++i) {
if (vector->at(i) > options_.token_threshold()) {
tokens.push_back(i + 1);

View File

@ -51,7 +51,7 @@ TEST_F(TensorToVectorStringCalculatorTest, ConvertsToVectorFloat) {
tensor_vec(i) = absl::StrCat("foo", i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -79,7 +79,7 @@ TEST_F(TensorToVectorStringCalculatorTest, ConvertsBatchedToVectorVectorFloat) {
slice(i) = absl::StrCat("foo", i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));
@ -108,7 +108,7 @@ TEST_F(TensorToVectorStringCalculatorTest, FlattenShouldTakeAllDimensions) {
slice(i) = absl::StrCat("foo", i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(tensor.release()).At(Timestamp(time)));

View File

@ -98,19 +98,19 @@ class TensorflowInferenceCalculatorTest : public ::testing::Test {
output_side_packets.Tag(kSessionTag);
}
Packet CreateTensorPacket(const std::vector<int32>& input, int64 time) {
Packet CreateTensorPacket(const std::vector<int32_t>& input, int64_t time) {
tf::TensorShape tensor_shape;
tensor_shape.AddDim(input.size());
auto tensor = absl::make_unique<tf::Tensor>(tf::DT_INT32, tensor_shape);
for (int i = 0; i < input.size(); ++i) {
tensor->vec<int32>()(i) = input[i];
tensor->vec<int32_t>()(i) = input[i];
}
return Adopt(tensor.release()).At(Timestamp(time));
}
// Create tensor from Vector and add as a Packet to the provided tag as input.
void AddVectorToInputsAsTensor(const std::vector<int32>& input,
const std::string& tag, int64 time) {
void AddVectorToInputsAsTensor(const std::vector<int32_t>& input,
const std::string& tag, int64_t time) {
runner_->MutableInputs()->Tag(tag).packets.push_back(
CreateTensorPacket(input, time));
}
@ -152,15 +152,15 @@ TEST_F(TensorflowInferenceCalculatorTest, GetConstants) {
ASSERT_EQ(output_packets_b.size(), 1);
const tf::Tensor& tensor_b = output_packets_b[0].Get<tf::Tensor>();
tf::TensorShape expected_shape({1, 3});
auto expected_tensor = tf::test::AsTensor<int32>({3, 2, 1}, expected_shape);
tf::test::ExpectTensorEqual<int32>(expected_tensor, tensor_b);
auto expected_tensor = tf::test::AsTensor<int32_t>({3, 2, 1}, expected_shape);
tf::test::ExpectTensorEqual<int32_t>(expected_tensor, tensor_b);
const std::vector<Packet>& output_packets_mult =
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(1, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
expected_tensor = tf::test::AsTensor<int32>({0, 0, 0}, expected_shape);
tf::test::ExpectTensorEqual<int32>(expected_tensor, tensor_mult);
expected_tensor = tf::test::AsTensor<int32_t>({0, 0, 0}, expected_shape);
tf::test::ExpectTensorEqual<int32_t>(expected_tensor, tensor_mult);
EXPECT_EQ(1, runner_
->GetCounter(
@ -193,8 +193,9 @@ TEST_F(TensorflowInferenceCalculatorTest, GetComputed) {
ASSERT_EQ(1, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
tf::TensorShape expected_shape({3});
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10}, expected_shape);
tf::test::ExpectTensorEqual<int32>(expected_tensor, tensor_mult);
auto expected_tensor =
tf::test::AsTensor<int32_t>({6, 8, 10}, expected_shape);
tf::test::ExpectTensorEqual<int32_t>(expected_tensor, tensor_mult);
// Add only one of the two expected tensors at the next timestamp, expect
// useful failure message.
@ -232,8 +233,9 @@ TEST_F(TensorflowInferenceCalculatorTest, GetComputed_MaxInFlight) {
ASSERT_EQ(1, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
tf::TensorShape expected_shape({3});
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10}, expected_shape);
tf::test::ExpectTensorEqual<int32>(expected_tensor, tensor_mult);
auto expected_tensor =
tf::test::AsTensor<int32_t>({6, 8, 10}, expected_shape);
tf::test::ExpectTensorEqual<int32_t>(expected_tensor, tensor_mult);
// Add only one of the two expected tensors at the next timestamp, expect
// useful failure message.
@ -290,11 +292,11 @@ TEST_F(TensorflowInferenceCalculatorTest, GetMultiBatchComputed) {
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -327,11 +329,11 @@ TEST_F(TensorflowInferenceCalculatorTest, GetMultiBatchComputed_MaxInFlight) {
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -367,14 +369,14 @@ TEST_F(TensorflowInferenceCalculatorTest,
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(3, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
const tf::Tensor& tensor_mult2 = output_packets_mult[2].Get<tf::Tensor>();
auto expected_tensor2 = tf::test::AsTensor<int32>({12, 16, 20});
tf::test::ExpectTensorEqual<int32>(tensor_mult2, expected_tensor2);
auto expected_tensor2 = tf::test::AsTensor<int32_t>({12, 16, 20});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult2, expected_tensor2);
EXPECT_EQ(3, runner_
->GetCounter(
@ -408,11 +410,11 @@ TEST_F(TensorflowInferenceCalculatorTest, GetSingleBatchComputed) {
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -446,11 +448,11 @@ TEST_F(TensorflowInferenceCalculatorTest, GetCloseBatchComputed) {
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -486,11 +488,11 @@ TEST_F(TensorflowInferenceCalculatorTest, GetCloseBatchComputedNoPadding) {
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -537,20 +539,20 @@ TEST_F(TensorflowInferenceCalculatorTest, GetBatchComputed_MaxInFlight) {
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(5, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({6, 8, 10});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({6, 8, 10});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
const tf::Tensor& tensor_mult2 = output_packets_mult[2].Get<tf::Tensor>();
auto expected_tensor2 = tf::test::AsTensor<int32>({12, 16, 20});
tf::test::ExpectTensorEqual<int32>(tensor_mult2, expected_tensor2);
auto expected_tensor2 = tf::test::AsTensor<int32_t>({12, 16, 20});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult2, expected_tensor2);
const tf::Tensor& tensor_mult3 = output_packets_mult[3].Get<tf::Tensor>();
auto expected_tensor3 = tf::test::AsTensor<int32>({15, 20, 25});
tf::test::ExpectTensorEqual<int32>(tensor_mult3, expected_tensor3);
auto expected_tensor3 = tf::test::AsTensor<int32_t>({15, 20, 25});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult3, expected_tensor3);
const tf::Tensor& tensor_mult4 = output_packets_mult[4].Get<tf::Tensor>();
auto expected_tensor4 = tf::test::AsTensor<int32>({18, 24, 30});
tf::test::ExpectTensorEqual<int32>(tensor_mult4, expected_tensor4);
auto expected_tensor4 = tf::test::AsTensor<int32_t>({18, 24, 30});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult4, expected_tensor4);
EXPECT_EQ(5, runner_
->GetCounter(
@ -585,12 +587,12 @@ TEST_F(TensorflowInferenceCalculatorTest, TestRecurrentStates) {
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
LOG(INFO) << "timestamp: " << 0;
auto expected_tensor = tf::test::AsTensor<int32>({3, 8, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({3, 8, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({9, 32, 75});
auto expected_tensor1 = tf::test::AsTensor<int32_t>({9, 32, 75});
LOG(INFO) << "timestamp: " << 1;
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -626,12 +628,12 @@ TEST_F(TensorflowInferenceCalculatorTest, TestRecurrentStateOverride) {
ASSERT_EQ(2, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
LOG(INFO) << "timestamp: " << 0;
auto expected_tensor = tf::test::AsTensor<int32>({3, 4, 5});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({3, 4, 5});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
const tf::Tensor& tensor_mult1 = output_packets_mult[1].Get<tf::Tensor>();
auto expected_tensor1 = tf::test::AsTensor<int32>({3, 4, 5});
auto expected_tensor1 = tf::test::AsTensor<int32_t>({3, 4, 5});
LOG(INFO) << "timestamp: " << 1;
tf::test::ExpectTensorEqual<int32>(tensor_mult1, expected_tensor1);
tf::test::ExpectTensorEqual<int32_t>(tensor_mult1, expected_tensor1);
EXPECT_EQ(2, runner_
->GetCounter(
@ -747,8 +749,8 @@ TEST_F(TensorflowInferenceCalculatorTest,
runner_->Outputs().Tag(kMultipliedTag).packets;
ASSERT_EQ(1, output_packets_mult.size());
const tf::Tensor& tensor_mult = output_packets_mult[0].Get<tf::Tensor>();
auto expected_tensor = tf::test::AsTensor<int32>({9, 12, 15});
tf::test::ExpectTensorEqual<int32>(tensor_mult, expected_tensor);
auto expected_tensor = tf::test::AsTensor<int32_t>({9, 12, 15});
tf::test::ExpectTensorEqual<int32_t>(tensor_mult, expected_tensor);
EXPECT_EQ(1, runner_
->GetCounter(

View File

@ -102,7 +102,7 @@ class TensorFlowSessionFromFrozenGraphCalculator : public CalculatorBase {
absl::Status Open(CalculatorContext* cc) override {
auto clock = std::unique_ptr<mediapipe::Clock>(
mediapipe::MonotonicClock::CreateSynchronizedMonotonicClock());
const uint64 start_time = absl::ToUnixMicros(clock->TimeNow());
const uint64_t start_time = absl::ToUnixMicros(clock->TimeNow());
const auto& options =
cc->Options<TensorFlowSessionFromFrozenGraphCalculatorOptions>();
// Output bundle packet.
@ -155,7 +155,7 @@ class TensorFlowSessionFromFrozenGraphCalculator : public CalculatorBase {
}
cc->OutputSidePackets().Tag(kSessionTag).Set(Adopt(session.release()));
const uint64 end_time = absl::ToUnixMicros(clock->TimeNow());
const uint64_t end_time = absl::ToUnixMicros(clock->TimeNow());
LOG(INFO) << "Loaded frozen model in: " << end_time - start_time
<< " microseconds.";
return absl::OkStatus();

View File

@ -51,7 +51,7 @@ std::string GetGraphDefPath() {
tf::Tensor TensorMatrix1x3(const int v1, const int v2, const int v3) {
tf::Tensor tensor(tf::DT_INT32,
tf::TensorShape(std::vector<tf::int64>({1, 3})));
auto matrix = tensor.matrix<int32>();
auto matrix = tensor.matrix<int32_t>();
matrix(0, 0) = v1;
matrix(0, 1) = v2;
matrix(0, 2) = v3;

View File

@ -101,7 +101,7 @@ class TensorFlowSessionFromFrozenGraphGenerator : public PacketGenerator {
const PacketSet& input_side_packets, PacketSet* output_side_packets) {
auto clock = std::unique_ptr<mediapipe::Clock>(
mediapipe::MonotonicClock::CreateSynchronizedMonotonicClock());
const uint64 start_time = absl::ToUnixMicros(clock->TimeNow());
const uint64_t start_time = absl::ToUnixMicros(clock->TimeNow());
const TensorFlowSessionFromFrozenGraphGeneratorOptions& options =
packet_generator_options.GetExtension(
TensorFlowSessionFromFrozenGraphGeneratorOptions::ext);
@ -154,7 +154,7 @@ class TensorFlowSessionFromFrozenGraphGenerator : public PacketGenerator {
}
output_side_packets->Tag(kSessionTag) = Adopt(session.release());
const uint64 end_time = absl::ToUnixMicros(clock->TimeNow());
const uint64_t end_time = absl::ToUnixMicros(clock->TimeNow());
LOG(INFO) << "Loaded frozen model in: " << end_time - start_time
<< " microseconds.";
return absl::OkStatus();

View File

@ -51,7 +51,7 @@ std::string GetGraphDefPath() {
tf::Tensor TensorMatrix1x3(const int v1, const int v2, const int v3) {
tf::Tensor tensor(tf::DT_INT32,
tf::TensorShape(std::vector<tf::int64>({1, 3})));
auto matrix = tensor.matrix<int32>();
auto matrix = tensor.matrix<int32_t>();
matrix(0, 0) = v1;
matrix(0, 1) = v2;
matrix(0, 2) = v3;

View File

@ -49,7 +49,7 @@ std::string GetSavedModelDir() {
tf::Tensor TensorMatrix1x3(const int v1, const int v2, const int v3) {
tf::Tensor tensor(tf::DT_INT32,
tf::TensorShape(std::vector<tf::int64>({1, 3})));
auto matrix = tensor.matrix<int32>();
auto matrix = tensor.matrix<int32_t>();
matrix(0, 0) = v1;
matrix(0, 1) = v2;
matrix(0, 2) = v3;

View File

@ -50,7 +50,7 @@ std::string GetSavedModelDir() {
tf::Tensor TensorMatrix1x3(const int v1, const int v2, const int v3) {
tf::Tensor tensor(tf::DT_INT32,
tf::TensorShape(std::vector<tf::int64>({1, 3})));
auto matrix = tensor.matrix<int32>();
auto matrix = tensor.matrix<int32_t>();
matrix(0, 0) = v1;
matrix(0, 1) = v2;
matrix(0, 2) = v3;

View File

@ -101,10 +101,10 @@ class UnpackMediaSequenceCalculatorTest : public ::testing::Test {
std::unique_ptr<CalculatorRunner> runner_;
const std::string video_id_ = "test_video_id";
const std::string data_path_ = "test_directory";
const int64 start_time_ = 3000000;
const int64 end_time_ = 5000000;
const int64_t start_time_ = 3000000;
const int64_t end_time_ = 5000000;
const std::string encoded_video_data_ = "encoded_video_data";
const int64 encoded_video_start_timestamp_ = 1000000;
const int64_t encoded_video_start_timestamp_ = 1000000;
const double image_frame_rate_ = 1.0;
};
@ -220,7 +220,7 @@ TEST_F(UnpackMediaSequenceCalculatorTest, UnpacksOneForwardFlowImage) {
for (int i = 0; i < num_forward_flow_images; ++i) {
const std::string& output_image = output_packets[i].Get<std::string>();
ASSERT_EQ(output_image, test_image_string);
ASSERT_EQ(output_packets[i].Timestamp().Value(), static_cast<int64>(i));
ASSERT_EQ(output_packets[i].Timestamp().Value(), static_cast<int64_t>(i));
}
}
@ -249,7 +249,7 @@ TEST_F(UnpackMediaSequenceCalculatorTest, UnpacksTwoForwardFlowImages) {
for (int i = 0; i < num_forward_flow_images; ++i) {
const std::string& output_image = output_packets[i].Get<std::string>();
ASSERT_EQ(output_image, test_image_strings[i]);
ASSERT_EQ(output_packets[i].Timestamp().Value(), static_cast<int64>(i));
ASSERT_EQ(output_packets[i].Timestamp().Value(), static_cast<int64_t>(i));
}
}

View File

@ -90,9 +90,9 @@ absl::Status VectorFloatToTensorCalculator::Process(CalculatorContext* cc) {
const std::vector<std::vector<float>>& input =
cc->Inputs().Index(0).Value().Get<std::vector<std::vector<float>>>();
const int32 rows = input.size();
const int32_t rows = input.size();
RET_CHECK_GE(rows, 1);
const int32 cols = input[0].size();
const int32_t cols = input[0].size();
RET_CHECK_GE(cols, 1);
for (int i = 1; i < rows; ++i) {
RET_CHECK_EQ(input[i].size(), cols);
@ -117,7 +117,7 @@ absl::Status VectorFloatToTensorCalculator::Process(CalculatorContext* cc) {
const std::vector<float>& input =
cc->Inputs().Index(0).Value().Get<std::vector<float>>();
RET_CHECK_GE(input.size(), 1);
const int32 length = input.size();
const int32_t length = input.size();
tensor_shape = tf::TensorShape({length});
auto output = ::absl::make_unique<tf::Tensor>(tf::DT_FLOAT, tensor_shape);
for (int i = 0; i < length; ++i) {

View File

@ -112,9 +112,9 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) {
.Value()
.Get<std::vector<std::vector<int>>>();
const int32 rows = input.size();
const int32_t rows = input.size();
CHECK_GE(rows, 1);
const int32 cols = input[0].size();
const int32_t cols = input[0].size();
CHECK_GE(cols, 1);
for (int i = 1; i < rows; ++i) {
CHECK_EQ(input[i].size(), cols);
@ -134,7 +134,7 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) {
AssignMatrixValue<tf::int64>(c, r, input[r][c], output.get());
break;
case tf::DT_UINT8:
AssignMatrixValue<uint8>(c, r, input[r][c], output.get());
AssignMatrixValue<uint8_t>(c, r, input[r][c], output.get());
break;
case tf::DT_INT32:
AssignMatrixValue<int>(c, r, input[r][c], output.get());
@ -152,7 +152,7 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) {
AssignMatrixValue<tf::int64>(r, c, input[r][c], output.get());
break;
case tf::DT_UINT8:
AssignMatrixValue<uint8>(r, c, input[r][c], output.get());
AssignMatrixValue<uint8_t>(r, c, input[r][c], output.get());
break;
case tf::DT_INT32:
AssignMatrixValue<int>(r, c, input[r][c], output.get());
@ -172,7 +172,7 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) {
input = cc->Inputs().Tag(kVectorInt).Value().Get<std::vector<int>>();
}
CHECK_GE(input.size(), 1);
const int32 length = input.size();
const int32_t length = input.size();
tensor_shape = tf::TensorShape({length});
auto output = ::absl::make_unique<tf::Tensor>(options_.tensor_data_type(),
tensor_shape);
@ -182,7 +182,7 @@ absl::Status VectorIntToTensorCalculator::Process(CalculatorContext* cc) {
output->tensor<tf::int64, 1>()(i) = input.at(i);
break;
case tf::DT_UINT8:
output->tensor<uint8, 1>()(i) = input.at(i);
output->tensor<uint8_t, 1>()(i) = input.at(i);
break;
case tf::DT_INT32:
output->tensor<int, 1>()(i) = input.at(i);

View File

@ -63,7 +63,7 @@ class VectorIntToTensorCalculatorTest : public ::testing::Test {
}
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()
->Tag(kVectorIntTag)
.packets.push_back(Adopt(input.release()).At(Timestamp(time)));
@ -97,7 +97,7 @@ class VectorIntToTensorCalculatorTest : public ::testing::Test {
TEST_F(VectorIntToTensorCalculatorTest, TestSingleValue) {
SetUpRunner(VectorIntToTensorCalculatorOptions::INPUT_1D,
tensorflow::DT_INT32, false, true);
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()
->Tag(kSingleIntTag)
.packets.push_back(MakePacket<int>(1).At(Timestamp(time)));
@ -112,7 +112,7 @@ TEST_F(VectorIntToTensorCalculatorTest, TestSingleValue) {
EXPECT_EQ(1, output_tensor.dims());
EXPECT_EQ(tf::DT_INT32, output_tensor.dtype());
const auto vec = output_tensor.vec<int32>();
const auto vec = output_tensor.vec<int32_t>();
EXPECT_EQ(1, vec(0));
}
@ -123,7 +123,7 @@ TEST_F(VectorIntToTensorCalculatorTest, TesOneDim) {
for (int i = 0; i < 5; ++i) {
input->at(i) = i;
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()
->Tag(kVectorIntTag)
.packets.push_back(Adopt(input.release()).At(Timestamp(time)));
@ -138,7 +138,7 @@ TEST_F(VectorIntToTensorCalculatorTest, TesOneDim) {
EXPECT_EQ(1, output_tensor.dims());
EXPECT_EQ(tf::DT_INT32, output_tensor.dtype());
const auto vec = output_tensor.vec<int32>();
const auto vec = output_tensor.vec<int32_t>();
for (int i = 0; i < 5; ++i) {
EXPECT_EQ(i, vec(i));
@ -154,7 +154,7 @@ TEST_F(VectorIntToTensorCalculatorTest, TestTwoDims) {
TEST_F(VectorIntToTensorCalculatorTest, TestInt64) {
SetUpRunner(VectorIntToTensorCalculatorOptions::INPUT_1D,
tensorflow::DT_INT64, false, true);
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()
->Tag(kSingleIntTag)
.packets.push_back(MakePacket<int>(1LL << 31).At(Timestamp(time)));
@ -181,7 +181,7 @@ TEST_F(VectorIntToTensorCalculatorTest, TestUint8) {
for (int i = 0; i < 5; ++i) {
input->at(i) = i;
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()
->Tag(kVectorIntTag)
.packets.push_back(Adopt(input.release()).At(Timestamp(time)));
@ -196,7 +196,7 @@ TEST_F(VectorIntToTensorCalculatorTest, TestUint8) {
EXPECT_EQ(1, output_tensor.dims());
EXPECT_EQ(tf::DT_UINT8, output_tensor.dtype());
const auto vec = output_tensor.vec<uint8>();
const auto vec = output_tensor.vec<uint8_t>();
for (int i = 0; i < 5; ++i) {
EXPECT_EQ(i, vec(i));

View File

@ -94,9 +94,9 @@ absl::Status VectorStringToTensorCalculator::Process(CalculatorContext* cc) {
.Value()
.Get<std::vector<std::vector<std::string>>>();
const int32 rows = input.size();
const int32_t rows = input.size();
RET_CHECK_GE(rows, 1);
const int32 cols = input[0].size();
const int32_t cols = input[0].size();
RET_CHECK_GE(cols, 1);
for (int i = 1; i < rows; ++i) {
RET_CHECK_EQ(input[i].size(), cols);
@ -121,7 +121,7 @@ absl::Status VectorStringToTensorCalculator::Process(CalculatorContext* cc) {
const std::vector<std::string>& input =
cc->Inputs().Index(0).Value().Get<std::vector<std::string>>();
RET_CHECK_GE(input.size(), 1);
const int32 length = input.size();
const int32_t length = input.size();
tensor_shape = tf::TensorShape({length});
auto output = ::absl::make_unique<tf::Tensor>(tf::DT_STRING, tensor_shape);
for (int i = 0; i < length; ++i) {

View File

@ -53,7 +53,7 @@ class VectorStringToTensorCalculatorTest : public ::testing::Test {
}
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(input.release()).At(Timestamp(time)));
@ -89,7 +89,7 @@ TEST_F(VectorStringToTensorCalculatorTest, ConvertsFromVectorString) {
for (int i = 0; i < 5; ++i) {
input->at(i) = absl::StrCat(i);
}
const int64 time = 1234;
const int64_t time = 1234;
runner_->MutableInputs()->Index(0).packets.push_back(
Adopt(input.release()).At(Timestamp(time)));