Hello,
I am trying to use TFLM on a platform using big endian. The tensor allocation fails as according to commit #689 the support for BE was removed. A custom tool for the endianness conversion of the .tflite file is proposed to use as solution. Since the model in .tflite format is a flatbuffer, I rebuilt schema_generated.h using the tflite schema with the mutable option on. I then tried to use the non-const accessors to load the data and byte-swap it, before saving it again. However I can’t seem to make it work.
I was trying something like this:
//model_as_char_array obtained using the xxd command
model = tflite::GetMutableModel(model_as_char_array);
auto vec=model->mutable_buffers();
for (auto it = vec->begin(); it != vec->end(); ++it){
auto d=it->mutable_data();// <----the problem is on this line
}
which fails to compile due to invalid conversion (const to non-const):
error: invalid conversion from 'flatbuffers::IndirectHelper<flatbuffers::Offset<tflite::Buffer> >::return_type' {aka 'const tflite::Buffer*'} to 'tflite::Buffer*' [-fpermissive]
74 | IT operator->() const { return IndirectHelper<T>::Read(data_, 0); }
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
| |
| flatbuffers::IndirectHelper<flatbuffers::Offset<tflite::Buffer> >::return_type {aka const tflite::Buffer*}
I am obviously missing something and got stuck on this hard. Can anyone propose a way to achieve the aforementioned conversion? Any help is highlt appreciated.
Thank you!
Note: While flattbuffers perform the byte-swap when the accessors are used, TFLM (probably) tries to read the buffer directly and hence the byte-swap is not performed.