Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TfLite one_hot int8 and unit8 feature support #27422

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions tensorflow/lite/kernels/one_hot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
case kTfLiteInt16:
case kTfLiteInt32:
case kTfLiteInt64:
case kTfLiteInt8:
case kTfLiteUInt8:
case kTfLiteBool:
op_context.output->type = op_context.dtype;
break;
Expand Down Expand Up @@ -172,6 +174,12 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
case kTfLiteInt64:
OneHotCompute<int64_t>(op_context);
break;
case kTfLiteInt8:
OneHotCompute<int8_t>(op_context);
break;
case kTfLiteUInt8:
OneHotCompute<uint8_t>(op_context);
break;
case kTfLiteBool:
OneHotCompute<bool>(op_context);
break;
Expand Down
20 changes: 20 additions & 0 deletions tensorflow/lite/kernels/one_hot_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ TEST(OneHotOpTest, BasicInt) {
EXPECT_THAT(model.GetOutput(), ElementsAreArray({1, 0, 0, 0, 1, 0, 0, 0, 1}));
}

TEST(OneHotOpTest, BasicInt8) {
const int depth = 3;
OneHotOpModel<int8_t> model({3}, depth, TensorType_INT8);
model.SetIndices({0, 1, 2});
model.Invoke();

EXPECT_THAT(model.GetOutputShape(), ElementsAreArray({3, 3}));
EXPECT_THAT(model.GetOutput(), ElementsAreArray({1, 0, 0, 0, 1, 0, 0, 0, 1}));
}

TEST(OneHotOpTest, BasicUint8) {
const int depth = 3;
OneHotOpModel<uint8_t> model({3}, depth, TensorType_UINT8);
model.SetIndices({0, 1, 2});
model.Invoke();

EXPECT_THAT(model.GetOutputShape(), ElementsAreArray({3, 3}));
EXPECT_THAT(model.GetOutput(), ElementsAreArray({1, 0, 0, 0, 1, 0, 0, 0, 1}));
}

TEST(OneHotOpTest, BasicBool) {
const int depth = 3;
OneHotOpModel<bool> model({3}, depth, TensorType_BOOL);
Expand Down