Internal change
PiperOrigin-RevId: 522255287
This commit is contained in:
parent
56b3cd4350
commit
12ecc8139f
|
@ -92,13 +92,14 @@ class OpenCvProcessor : public ImageToTensorConverter {
|
||||||
const int dst_data_type = output_channels == 1 ? mat_gray_type_ : mat_type_;
|
const int dst_data_type = output_channels == 1 ? mat_gray_type_ : mat_type_;
|
||||||
switch (tensor_type_) {
|
switch (tensor_type_) {
|
||||||
case Tensor::ElementType::kInt8:
|
case Tensor::ElementType::kInt8:
|
||||||
RET_CHECK_GE(output_shape.num_elements(),
|
RET_CHECK_GE(
|
||||||
tensor_buffer_offset / sizeof(int8) + num_elements_per_img)
|
output_shape.num_elements(),
|
||||||
|
tensor_buffer_offset / sizeof(int8_t) + num_elements_per_img)
|
||||||
<< "The buffer offset + the input image size is larger than the "
|
<< "The buffer offset + the input image size is larger than the "
|
||||||
"allocated tensor buffer.";
|
"allocated tensor buffer.";
|
||||||
dst = cv::Mat(
|
dst = cv::Mat(output_height, output_width, dst_data_type,
|
||||||
output_height, output_width, dst_data_type,
|
buffer_view.buffer<int8_t>() +
|
||||||
buffer_view.buffer<int8>() + tensor_buffer_offset / sizeof(int8));
|
tensor_buffer_offset / sizeof(int8_t));
|
||||||
break;
|
break;
|
||||||
case Tensor::ElementType::kFloat32:
|
case Tensor::ElementType::kFloat32:
|
||||||
RET_CHECK_GE(
|
RET_CHECK_GE(
|
||||||
|
@ -113,12 +114,12 @@ class OpenCvProcessor : public ImageToTensorConverter {
|
||||||
case Tensor::ElementType::kUInt8:
|
case Tensor::ElementType::kUInt8:
|
||||||
RET_CHECK_GE(
|
RET_CHECK_GE(
|
||||||
output_shape.num_elements(),
|
output_shape.num_elements(),
|
||||||
tensor_buffer_offset / sizeof(uint8) + num_elements_per_img)
|
tensor_buffer_offset / sizeof(uint8_t) + num_elements_per_img)
|
||||||
<< "The buffer offset + the input image size is larger than the "
|
<< "The buffer offset + the input image size is larger than the "
|
||||||
"allocated tensor buffer.";
|
"allocated tensor buffer.";
|
||||||
dst = cv::Mat(
|
dst = cv::Mat(output_height, output_width, dst_data_type,
|
||||||
output_height, output_width, dst_data_type,
|
buffer_view.buffer<uint8_t>() +
|
||||||
buffer_view.buffer<uint8>() + tensor_buffer_offset / sizeof(uint8));
|
tensor_buffer_offset / sizeof(uint8_t));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return InvalidArgumentError(
|
return InvalidArgumentError(
|
||||||
|
|
|
@ -41,7 +41,7 @@ constexpr char kTransposeOptionsString[] =
|
||||||
|
|
||||||
using RandomEngine = std::mt19937_64;
|
using RandomEngine = std::mt19937_64;
|
||||||
using testing::Eq;
|
using testing::Eq;
|
||||||
const uint32 kSeed = 1234;
|
const uint32_t kSeed = 1234;
|
||||||
const int kNumSizes = 8;
|
const int kNumSizes = 8;
|
||||||
const int sizes[kNumSizes][2] = {{1, 1}, {12, 1}, {1, 9}, {2, 2},
|
const int sizes[kNumSizes][2] = {{1, 1}, {12, 1}, {1, 9}, {2, 2},
|
||||||
{5, 3}, {7, 13}, {16, 32}, {101, 2}};
|
{5, 3}, {7, 13}, {16, 32}, {101, 2}};
|
||||||
|
@ -49,7 +49,7 @@ const int sizes[kNumSizes][2] = {{1, 1}, {12, 1}, {1, 9}, {2, 2},
|
||||||
class TensorConverterCalculatorTest : public ::testing::Test {
|
class TensorConverterCalculatorTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
// Adds a packet with a matrix filled with random values in [0,1].
|
// 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,
|
||||||
bool row_major_matrix = false) {
|
bool row_major_matrix = false) {
|
||||||
RandomEngine random(kSeed);
|
RandomEngine random(kSeed);
|
||||||
std::uniform_real_distribution<> uniform_dist(0, 1.0);
|
std::uniform_real_distribution<> uniform_dist(0, 1.0);
|
||||||
|
@ -229,7 +229,7 @@ TEST_F(TensorConverterCalculatorTest, CustomDivAndSub) {
|
||||||
MP_ASSERT_OK(graph.StartRun({}));
|
MP_ASSERT_OK(graph.StartRun({}));
|
||||||
auto input_image = absl::make_unique<ImageFrame>(ImageFormat::GRAY8, 1, 1);
|
auto input_image = absl::make_unique<ImageFrame>(ImageFormat::GRAY8, 1, 1);
|
||||||
cv::Mat mat = mediapipe::formats::MatView(input_image.get());
|
cv::Mat mat = mediapipe::formats::MatView(input_image.get());
|
||||||
mat.at<uint8>(0, 0) = 200;
|
mat.at<uint8_t>(0, 0) = 200;
|
||||||
MP_ASSERT_OK(graph.AddPacketToInputStream(
|
MP_ASSERT_OK(graph.AddPacketToInputStream(
|
||||||
"input_image", Adopt(input_image.release()).At(Timestamp(0))));
|
"input_image", Adopt(input_image.release()).At(Timestamp(0))));
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ TEST_F(TensorConverterCalculatorTest, SetOutputRange) {
|
||||||
MP_ASSERT_OK(graph.StartRun({}));
|
MP_ASSERT_OK(graph.StartRun({}));
|
||||||
auto input_image = absl::make_unique<ImageFrame>(ImageFormat::GRAY8, 1, 1);
|
auto input_image = absl::make_unique<ImageFrame>(ImageFormat::GRAY8, 1, 1);
|
||||||
cv::Mat mat = mediapipe::formats::MatView(input_image.get());
|
cv::Mat mat = mediapipe::formats::MatView(input_image.get());
|
||||||
mat.at<uint8>(0, 0) = 200;
|
mat.at<uint8_t>(0, 0) = 200;
|
||||||
MP_ASSERT_OK(graph.AddPacketToInputStream(
|
MP_ASSERT_OK(graph.AddPacketToInputStream(
|
||||||
"input_image", Adopt(input_image.release()).At(Timestamp(0))));
|
"input_image", Adopt(input_image.release()).At(Timestamp(0))));
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ class TensorsToClassificationCalculator : public Node {
|
||||||
private:
|
private:
|
||||||
int top_k_ = 0;
|
int top_k_ = 0;
|
||||||
bool sort_by_descending_score_ = false;
|
bool sort_by_descending_score_ = false;
|
||||||
proto_ns::Map<int64, LabelMapItem> local_label_map_;
|
proto_ns::Map<int64_t, LabelMapItem> local_label_map_;
|
||||||
bool label_map_loaded_ = false;
|
bool label_map_loaded_ = false;
|
||||||
bool is_binary_classification_ = false;
|
bool is_binary_classification_ = false;
|
||||||
float min_score_threshold_ = std::numeric_limits<float>::lowest();
|
float min_score_threshold_ = std::numeric_limits<float>::lowest();
|
||||||
|
@ -98,7 +98,8 @@ class TensorsToClassificationCalculator : public Node {
|
||||||
// These are used to filter out the output classification results.
|
// These are used to filter out the output classification results.
|
||||||
ClassIndexSet class_index_set_;
|
ClassIndexSet class_index_set_;
|
||||||
bool IsClassIndexAllowed(int class_index);
|
bool IsClassIndexAllowed(int class_index);
|
||||||
const proto_ns::Map<int64, LabelMapItem>& GetLabelMap(CalculatorContext* cc);
|
const proto_ns::Map<int64_t, LabelMapItem>& GetLabelMap(
|
||||||
|
CalculatorContext* cc);
|
||||||
};
|
};
|
||||||
MEDIAPIPE_REGISTER_NODE(TensorsToClassificationCalculator);
|
MEDIAPIPE_REGISTER_NODE(TensorsToClassificationCalculator);
|
||||||
|
|
||||||
|
@ -252,7 +253,7 @@ bool TensorsToClassificationCalculator::IsClassIndexAllowed(int class_index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const proto_ns::Map<int64, LabelMapItem>&
|
const proto_ns::Map<int64_t, LabelMapItem>&
|
||||||
TensorsToClassificationCalculator::GetLabelMap(CalculatorContext* cc) {
|
TensorsToClassificationCalculator::GetLabelMap(CalculatorContext* cc) {
|
||||||
return !local_label_map_.empty()
|
return !local_label_map_.empty()
|
||||||
? local_label_map_
|
? local_label_map_
|
||||||
|
|
Loading…
Reference in New Issue
Block a user