| 27 | } |
| 28 | |
| 29 | TfLiteStatus CopyShapeAndType(TfLiteContext* context, |
| 30 | const tensorflow::Tensor& src, |
| 31 | TfLiteTensor* tensor) { |
| 32 | tensor->type = GetTensorFlowLiteType(static_cast<TF_DataType>(src.dtype())); |
| 33 | if (tensor->type == kTfLiteNoType) { |
| 34 | context->ReportError(context, |
| 35 | "TF Lite does not support TensorFlow data type: %s", |
| 36 | DataTypeString(src.dtype()).c_str()); |
| 37 | return kTfLiteError; |
| 38 | } |
| 39 | |
| 40 | int num_dims = src.dims(); |
| 41 | TfLiteIntArray* shape = TfLiteIntArrayCreate(num_dims); |
| 42 | for (int j = 0; j < num_dims; ++j) { |
| 43 | // We need to cast from TensorFlow's int64 to TF Lite's int32. Let's |
| 44 | // make sure there's no overflow. |
| 45 | if (src.dim_size(j) >= std::numeric_limits<int>::max()) { |
| 46 | context->ReportError(context, |
| 47 | "Dimension value in TensorFlow shape is larger than " |
| 48 | "supported by TF Lite"); |
| 49 | TfLiteIntArrayFree(shape); |
| 50 | return kTfLiteError; |
| 51 | } |
| 52 | shape->data[j] = static_cast<int>(src.dim_size(j)); |
| 53 | } |
| 54 | return context->ResizeTensor(context, tensor, shape); |
| 55 | } |
| 56 | |
| 57 | TF_DataType GetTensorFlowDataType(TfLiteType type) { |
| 58 | switch (type) { |