Add unpack to schema.

PiperOrigin-RevId: 209528032
This commit is contained in:
A. Unique TensorFlower 2018-08-20 19:38:25 -07:00 committed by TensorFlower Gardener
parent a2a561e7e8
commit debd8b6b4e
5 changed files with 160 additions and 6 deletions

View File

@ -113,6 +113,7 @@ typedef enum {
kTfLiteBuiltinOneHot = 85, kTfLiteBuiltinOneHot = 85,
kTfLiteBuiltinLogicalAnd = 86, kTfLiteBuiltinLogicalAnd = 86,
kTfLiteBuiltinLogicalNot = 87, kTfLiteBuiltinLogicalNot = 87,
kTfLiteBuiltinUnpack = 88,
} TfLiteBuiltinOperator; } TfLiteBuiltinOperator;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -789,6 +789,7 @@ TfLiteStatus ParseOpData(const Operator* op, BuiltinOperator op_type,
case BuiltinOperator_LOGICAL_OR: case BuiltinOperator_LOGICAL_OR:
case BuiltinOperator_LOGICAL_AND: case BuiltinOperator_LOGICAL_AND:
case BuiltinOperator_LOGICAL_NOT: case BuiltinOperator_LOGICAL_NOT:
case BuiltinOperator_UNPACK:
break; break;
} }
return kTfLiteOk; return kTfLiteOk;

View File

@ -647,6 +647,7 @@ TfLiteStatus AddOpsAndParams(
case tflite::BuiltinOperator_ONE_HOT: case tflite::BuiltinOperator_ONE_HOT:
case tflite::BuiltinOperator_LOGICAL_AND: case tflite::BuiltinOperator_LOGICAL_AND:
case tflite::BuiltinOperator_LOGICAL_NOT: case tflite::BuiltinOperator_LOGICAL_NOT:
case tflite::BuiltinOperator_UNPACK:
logError("Op code %d is currently not delegated to NNAPI", builtin); logError("Op code %d is currently not delegated to NNAPI", builtin);
return kTfLiteError; return kTfLiteError;
break; break;

View File

@ -169,6 +169,7 @@ enum BuiltinOperator : byte {
ONE_HOT = 85, ONE_HOT = 85,
LOGICAL_AND = 86, LOGICAL_AND = 86,
LOGICAL_NOT = 87, LOGICAL_NOT = 87,
UNPACK = 88,
} }
// Options for the builtin operators. // Options for the builtin operators.
@ -236,6 +237,7 @@ union BuiltinOptions {
OneHotOptions, OneHotOptions,
LogicalAndOptions, LogicalAndOptions,
LogicalNotOptions, LogicalNotOptions,
UnpackOptions,
} }
enum Padding : byte { SAME, VALID } enum Padding : byte { SAME, VALID }
@ -565,6 +567,11 @@ table LogicalAndOptions {
table LogicalNotOptions { table LogicalNotOptions {
} }
table UnpackOptions {
num:int;
axis:int;
}
// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a // An OperatorCode can be an enum value (BuiltinOperator) if the operator is a
// builtin, or a string if the operator is custom. // builtin, or a string if the operator is custom.
table OperatorCode { table OperatorCode {

View File

@ -220,6 +220,9 @@ struct LogicalAndOptionsT;
struct LogicalNotOptions; struct LogicalNotOptions;
struct LogicalNotOptionsT; struct LogicalNotOptionsT;
struct UnpackOptions;
struct UnpackOptionsT;
struct OperatorCode; struct OperatorCode;
struct OperatorCodeT; struct OperatorCodeT;
@ -373,11 +376,12 @@ enum BuiltinOperator {
BuiltinOperator_ONE_HOT = 85, BuiltinOperator_ONE_HOT = 85,
BuiltinOperator_LOGICAL_AND = 86, BuiltinOperator_LOGICAL_AND = 86,
BuiltinOperator_LOGICAL_NOT = 87, BuiltinOperator_LOGICAL_NOT = 87,
BuiltinOperator_UNPACK = 88,
BuiltinOperator_MIN = BuiltinOperator_ADD, BuiltinOperator_MIN = BuiltinOperator_ADD,
BuiltinOperator_MAX = BuiltinOperator_LOGICAL_NOT BuiltinOperator_MAX = BuiltinOperator_UNPACK
}; };
inline BuiltinOperator (&EnumValuesBuiltinOperator())[87] { inline BuiltinOperator (&EnumValuesBuiltinOperator())[88] {
static BuiltinOperator values[] = { static BuiltinOperator values[] = {
BuiltinOperator_ADD, BuiltinOperator_ADD,
BuiltinOperator_AVERAGE_POOL_2D, BuiltinOperator_AVERAGE_POOL_2D,
@ -465,7 +469,8 @@ inline BuiltinOperator (&EnumValuesBuiltinOperator())[87] {
BuiltinOperator_LOGICAL_OR, BuiltinOperator_LOGICAL_OR,
BuiltinOperator_ONE_HOT, BuiltinOperator_ONE_HOT,
BuiltinOperator_LOGICAL_AND, BuiltinOperator_LOGICAL_AND,
BuiltinOperator_LOGICAL_NOT BuiltinOperator_LOGICAL_NOT,
BuiltinOperator_UNPACK
}; };
return values; return values;
} }
@ -560,6 +565,7 @@ inline const char **EnumNamesBuiltinOperator() {
"ONE_HOT", "ONE_HOT",
"LOGICAL_AND", "LOGICAL_AND",
"LOGICAL_NOT", "LOGICAL_NOT",
"UNPACK",
nullptr nullptr
}; };
return names; return names;
@ -635,11 +641,12 @@ enum BuiltinOptions {
BuiltinOptions_OneHotOptions = 61, BuiltinOptions_OneHotOptions = 61,
BuiltinOptions_LogicalAndOptions = 62, BuiltinOptions_LogicalAndOptions = 62,
BuiltinOptions_LogicalNotOptions = 63, BuiltinOptions_LogicalNotOptions = 63,
BuiltinOptions_UnpackOptions = 64,
BuiltinOptions_MIN = BuiltinOptions_NONE, BuiltinOptions_MIN = BuiltinOptions_NONE,
BuiltinOptions_MAX = BuiltinOptions_LogicalNotOptions BuiltinOptions_MAX = BuiltinOptions_UnpackOptions
}; };
inline BuiltinOptions (&EnumValuesBuiltinOptions())[64] { inline BuiltinOptions (&EnumValuesBuiltinOptions())[65] {
static BuiltinOptions values[] = { static BuiltinOptions values[] = {
BuiltinOptions_NONE, BuiltinOptions_NONE,
BuiltinOptions_Conv2DOptions, BuiltinOptions_Conv2DOptions,
@ -704,7 +711,8 @@ inline BuiltinOptions (&EnumValuesBuiltinOptions())[64] {
BuiltinOptions_LogicalOrOptions, BuiltinOptions_LogicalOrOptions,
BuiltinOptions_OneHotOptions, BuiltinOptions_OneHotOptions,
BuiltinOptions_LogicalAndOptions, BuiltinOptions_LogicalAndOptions,
BuiltinOptions_LogicalNotOptions BuiltinOptions_LogicalNotOptions,
BuiltinOptions_UnpackOptions
}; };
return values; return values;
} }
@ -775,6 +783,7 @@ inline const char **EnumNamesBuiltinOptions() {
"OneHotOptions", "OneHotOptions",
"LogicalAndOptions", "LogicalAndOptions",
"LogicalNotOptions", "LogicalNotOptions",
"UnpackOptions",
nullptr nullptr
}; };
return names; return names;
@ -1041,6 +1050,10 @@ template<> struct BuiltinOptionsTraits<LogicalNotOptions> {
static const BuiltinOptions enum_value = BuiltinOptions_LogicalNotOptions; static const BuiltinOptions enum_value = BuiltinOptions_LogicalNotOptions;
}; };
template<> struct BuiltinOptionsTraits<UnpackOptions> {
static const BuiltinOptions enum_value = BuiltinOptions_UnpackOptions;
};
struct BuiltinOptionsUnion { struct BuiltinOptionsUnion {
BuiltinOptions type; BuiltinOptions type;
void *value; void *value;
@ -1576,6 +1589,14 @@ struct BuiltinOptionsUnion {
return type == BuiltinOptions_LogicalNotOptions ? return type == BuiltinOptions_LogicalNotOptions ?
reinterpret_cast<const LogicalNotOptionsT *>(value) : nullptr; reinterpret_cast<const LogicalNotOptionsT *>(value) : nullptr;
} }
UnpackOptionsT *AsUnpackOptions() {
return type == BuiltinOptions_UnpackOptions ?
reinterpret_cast<UnpackOptionsT *>(value) : nullptr;
}
const UnpackOptionsT *AsUnpackOptions() const {
return type == BuiltinOptions_UnpackOptions ?
reinterpret_cast<const UnpackOptionsT *>(value) : nullptr;
}
}; };
bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type); bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type);
@ -5649,6 +5670,72 @@ inline flatbuffers::Offset<LogicalNotOptions> CreateLogicalNotOptions(
flatbuffers::Offset<LogicalNotOptions> CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalNotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); flatbuffers::Offset<LogicalNotOptions> CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalNotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
struct UnpackOptionsT : public flatbuffers::NativeTable {
typedef UnpackOptions TableType;
int32_t num;
int32_t axis;
UnpackOptionsT()
: num(0),
axis(0) {
}
};
struct UnpackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef UnpackOptionsT NativeTableType;
enum {
VT_NUM = 4,
VT_AXIS = 6
};
int32_t num() const {
return GetField<int32_t>(VT_NUM, 0);
}
int32_t axis() const {
return GetField<int32_t>(VT_AXIS, 0);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, VT_NUM) &&
VerifyField<int32_t>(verifier, VT_AXIS) &&
verifier.EndTable();
}
UnpackOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
void UnPackTo(UnpackOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
static flatbuffers::Offset<UnpackOptions> Pack(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
};
struct UnpackOptionsBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_num(int32_t num) {
fbb_.AddElement<int32_t>(UnpackOptions::VT_NUM, num, 0);
}
void add_axis(int32_t axis) {
fbb_.AddElement<int32_t>(UnpackOptions::VT_AXIS, axis, 0);
}
explicit UnpackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
UnpackOptionsBuilder &operator=(const UnpackOptionsBuilder &);
flatbuffers::Offset<UnpackOptions> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<UnpackOptions>(end);
return o;
}
};
inline flatbuffers::Offset<UnpackOptions> CreateUnpackOptions(
flatbuffers::FlatBufferBuilder &_fbb,
int32_t num = 0,
int32_t axis = 0) {
UnpackOptionsBuilder builder_(_fbb);
builder_.add_axis(axis);
builder_.add_num(num);
return builder_.Finish();
}
flatbuffers::Offset<UnpackOptions> CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
struct OperatorCodeT : public flatbuffers::NativeTable { struct OperatorCodeT : public flatbuffers::NativeTable {
typedef OperatorCode TableType; typedef OperatorCode TableType;
BuiltinOperator builtin_code; BuiltinOperator builtin_code;
@ -5971,6 +6058,9 @@ struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const LogicalNotOptions *builtin_options_as_LogicalNotOptions() const { const LogicalNotOptions *builtin_options_as_LogicalNotOptions() const {
return builtin_options_type() == BuiltinOptions_LogicalNotOptions ? static_cast<const LogicalNotOptions *>(builtin_options()) : nullptr; return builtin_options_type() == BuiltinOptions_LogicalNotOptions ? static_cast<const LogicalNotOptions *>(builtin_options()) : nullptr;
} }
const UnpackOptions *builtin_options_as_UnpackOptions() const {
return builtin_options_type() == BuiltinOptions_UnpackOptions ? static_cast<const UnpackOptions *>(builtin_options()) : nullptr;
}
const flatbuffers::Vector<uint8_t> *custom_options() const { const flatbuffers::Vector<uint8_t> *custom_options() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_CUSTOM_OPTIONS); return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_CUSTOM_OPTIONS);
} }
@ -6254,6 +6344,10 @@ template<> inline const LogicalNotOptions *Operator::builtin_options_as<LogicalN
return builtin_options_as_LogicalNotOptions(); return builtin_options_as_LogicalNotOptions();
} }
template<> inline const UnpackOptions *Operator::builtin_options_as<UnpackOptions>() const {
return builtin_options_as_UnpackOptions();
}
struct OperatorBuilder { struct OperatorBuilder {
flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_; flatbuffers::uoffset_t start_;
@ -8441,6 +8535,35 @@ inline flatbuffers::Offset<LogicalNotOptions> CreateLogicalNotOptions(flatbuffer
_fbb); _fbb);
} }
inline UnpackOptionsT *UnpackOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = new UnpackOptionsT();
UnPackTo(_o, _resolver);
return _o;
}
inline void UnpackOptions::UnPackTo(UnpackOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const {
(void)_o;
(void)_resolver;
{ auto _e = num(); _o->num = _e; };
{ auto _e = axis(); _o->axis = _e; };
}
inline flatbuffers::Offset<UnpackOptions> UnpackOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
return CreateUnpackOptions(_fbb, _o, _rehasher);
}
inline flatbuffers::Offset<UnpackOptions> CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
(void)_rehasher;
(void)_o;
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const UnpackOptionsT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
auto _num = _o->num;
auto _axis = _o->axis;
return tflite::CreateUnpackOptions(
_fbb,
_num,
_axis);
}
inline OperatorCodeT *OperatorCode::UnPack(const flatbuffers::resolver_function_t *_resolver) const { inline OperatorCodeT *OperatorCode::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = new OperatorCodeT(); auto _o = new OperatorCodeT();
UnPackTo(_o, _resolver); UnPackTo(_o, _resolver);
@ -8882,6 +9005,10 @@ inline bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *ob
auto ptr = reinterpret_cast<const LogicalNotOptions *>(obj); auto ptr = reinterpret_cast<const LogicalNotOptions *>(obj);
return verifier.VerifyTable(ptr); return verifier.VerifyTable(ptr);
} }
case BuiltinOptions_UnpackOptions: {
auto ptr = reinterpret_cast<const UnpackOptions *>(obj);
return verifier.VerifyTable(ptr);
}
default: return false; default: return false;
} }
} }
@ -9152,6 +9279,10 @@ inline void *BuiltinOptionsUnion::UnPack(const void *obj, BuiltinOptions type, c
auto ptr = reinterpret_cast<const LogicalNotOptions *>(obj); auto ptr = reinterpret_cast<const LogicalNotOptions *>(obj);
return ptr->UnPack(resolver); return ptr->UnPack(resolver);
} }
case BuiltinOptions_UnpackOptions: {
auto ptr = reinterpret_cast<const UnpackOptions *>(obj);
return ptr->UnPack(resolver);
}
default: return nullptr; default: return nullptr;
} }
} }
@ -9410,6 +9541,10 @@ inline flatbuffers::Offset<void> BuiltinOptionsUnion::Pack(flatbuffers::FlatBuff
auto ptr = reinterpret_cast<const LogicalNotOptionsT *>(value); auto ptr = reinterpret_cast<const LogicalNotOptionsT *>(value);
return CreateLogicalNotOptions(_fbb, ptr, _rehasher).Union(); return CreateLogicalNotOptions(_fbb, ptr, _rehasher).Union();
} }
case BuiltinOptions_UnpackOptions: {
auto ptr = reinterpret_cast<const UnpackOptionsT *>(value);
return CreateUnpackOptions(_fbb, ptr, _rehasher).Union();
}
default: return 0; default: return 0;
} }
} }
@ -9668,6 +9803,10 @@ inline BuiltinOptionsUnion::BuiltinOptionsUnion(const BuiltinOptionsUnion &u) FL
value = new LogicalNotOptionsT(*reinterpret_cast<LogicalNotOptionsT *>(u.value)); value = new LogicalNotOptionsT(*reinterpret_cast<LogicalNotOptionsT *>(u.value));
break; break;
} }
case BuiltinOptions_UnpackOptions: {
value = new UnpackOptionsT(*reinterpret_cast<UnpackOptionsT *>(u.value));
break;
}
default: default:
break; break;
} }
@ -9990,6 +10129,11 @@ inline void BuiltinOptionsUnion::Reset() {
delete ptr; delete ptr;
break; break;
} }
case BuiltinOptions_UnpackOptions: {
auto ptr = reinterpret_cast<UnpackOptionsT *>(value);
delete ptr;
break;
}
default: break; default: break;
} }
value = nullptr; value = nullptr;