Internal MediaPipe Tasks change
PiperOrigin-RevId: 540083633
This commit is contained in:
committed by
Copybara-Service
parent
6cf7148f3b
commit
b97d11fa76
@@ -117,11 +117,18 @@ class Tensor {
|
||||
Shape() = default;
|
||||
Shape(std::initializer_list<int> dimensions) : dims(dimensions) {}
|
||||
Shape(const std::vector<int>& dimensions) : dims(dimensions) {}
|
||||
Shape(std::initializer_list<int> dimensions, bool is_dynamic)
|
||||
: dims(dimensions), is_dynamic(is_dynamic) {}
|
||||
Shape(const std::vector<int>& dimensions, bool is_dynamic)
|
||||
: dims(dimensions), is_dynamic(is_dynamic) {}
|
||||
int num_elements() const {
|
||||
return std::accumulate(dims.begin(), dims.end(), 1,
|
||||
std::multiplies<int>());
|
||||
}
|
||||
std::vector<int> dims;
|
||||
// The Tensor has dynamic rather than static shape so the TFLite interpreter
|
||||
// needs to be reallocated. Only relevant for CPU.
|
||||
bool is_dynamic = false;
|
||||
};
|
||||
// Quantization parameters corresponding to the zero_point and scale value
|
||||
// made available by TfLite quantized (uint8/int8) tensors.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "mediapipe/framework/port/gmock.h"
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
@@ -34,6 +35,17 @@ TEST(General, TestDataTypes) {
|
||||
EXPECT_EQ(t_bool.bytes(), t_bool.shape().num_elements() * sizeof(bool));
|
||||
}
|
||||
|
||||
TEST(General, TestDynamic) {
|
||||
Tensor t1(Tensor::ElementType::kFloat32, Tensor::Shape({1, 2, 3, 4}, true));
|
||||
EXPECT_EQ(t1.shape().num_elements(), 1 * 2 * 3 * 4);
|
||||
EXPECT_TRUE(t1.shape().is_dynamic);
|
||||
|
||||
std::vector<int> t2_dims = {4, 3, 2, 3};
|
||||
Tensor t2(Tensor::ElementType::kFloat16, Tensor::Shape(t2_dims, true));
|
||||
EXPECT_EQ(t2.shape().num_elements(), 4 * 3 * 2 * 3);
|
||||
EXPECT_TRUE(t2.shape().is_dynamic);
|
||||
}
|
||||
|
||||
TEST(Cpu, TestMemoryAllocation) {
|
||||
Tensor t1(Tensor::ElementType::kFloat32, Tensor::Shape{4, 3, 2, 3});
|
||||
auto v1 = t1.GetCpuWriteView();
|
||||
|
||||
Reference in New Issue
Block a user