Example #1
0
        private NodeMetadata GetMetadataFromTypeInfo(IntPtr typeInfo)
        {
            IntPtr tensorInfo = NativeMethods.ONNXRuntimeCastTypeInfoToTensorInfo(typeInfo);
            // Convert the newly introduced ONNXRuntimeTypeInfo* to the older ONNXRuntimeTypeAndShapeInfo*

            TensorElementType type = NativeMethods.ONNXRuntimeGetTensorElementType(tensorInfo);
            Type dotnetType        = null;
            int  width             = 0;

            TensorElementTypeConverter.GetTypeAndWidth(type, out dotnetType, out width);
            ulong numDimensions = NativeMethods.ONNXRuntimeGetNumOfDimensions(tensorInfo);

            long[] dimensions = new long[(int)numDimensions];
            NativeMethods.ONNXRuntimeGetDimensions(tensorInfo, dimensions, numDimensions);
            int[] intDimensions = new int[(int)numDimensions];
            for (ulong i = 0; i < numDimensions; i++)
            {
                intDimensions[i] = (int)dimensions[i];
            }
            return(new NodeMetadata(intDimensions, dotnetType));
        }