microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
operators/vision/decode_image.hpp
57lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "ocos.h" |
| 7 | #include "string_utils.h" |
| 8 | |
| 9 | #include <cstdint> |
| 10 | |
| 11 | namespace ort_extensions { |
| 12 | struct KernelDecodeImage : BaseKernel { |
| 13 | KernelDecodeImage(const OrtApi& api) : BaseKernel(api) {} |
| 14 | |
| 15 | void Compute(OrtKernelContext* context); |
| 16 | }; |
| 17 | |
| 18 | struct CustomOpDecodeImage : OrtW::CustomOpBase<CustomOpDecodeImage, KernelDecodeImage> { |
| 19 | void* CreateKernel(const OrtApi& api, const OrtKernelInfo* info) const { |
| 20 | return new KernelDecodeImage(api); |
| 21 | } |
| 22 | |
| 23 | void KernelDestroy(void* op_kernel) { |
| 24 | delete static_cast<KernelDecodeImage*>(op_kernel); |
| 25 | } |
| 26 | |
| 27 | const char* GetName() const { |
| 28 | return "DecodeImage"; |
| 29 | } |
| 30 | |
| 31 | size_t GetInputTypeCount() const { |
| 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | ONNXTensorElementDataType GetInputType(size_t index) const { |
| 36 | switch (index) { |
| 37 | case 0: |
| 38 | return ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8; |
| 39 | default: |
| 40 | ORTX_CXX_API_THROW(MakeString("Invalid input index ", index), ORT_INVALID_ARGUMENT); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | size_t GetOutputTypeCount() const { |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | ONNXTensorElementDataType GetOutputType(size_t index) const { |
| 49 | switch (index) { |
| 50 | case 0: |
| 51 | return ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8; |
| 52 | default: |
| 53 | ORTX_CXX_API_THROW(MakeString("Invalid output index ", index), ORT_INVALID_ARGUMENT); |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | } // namespace ort_extensions |
| 58 | |