Example #1
0
        private void errorFn(IntPtr colVal)
        {
            if (OnErrorFunction == null)
            {
                return;
            }

            List <DisposableNamedOnnxValue> rgVal = new List <DisposableNamedOnnxValue>();
            List <string>      rgNames            = new List <string>();
            OrtValueCollection col = new OrtValueCollection(colVal);

            int nCount = col.Count;

            for (int i = 0; i < nCount; i++)
            {
                string   strName;
                OrtValue val = col.GetAt(i, out strName);
                rgVal.Add(DisposableNamedOnnxValue.CreateTensorFromOnnxValue(strName, val));
            }

            OnErrorFunction(this, new ErrorFunctionArgs(rgVal));

            // Clean-up the data used during this batch.
            foreach (IDisposable iDispose in m_rgCleanUpList)
            {
                iDispose.Dispose();
            }

            m_rgCleanUpList.Clear();
        }
Example #2
0
        private void handleGetDataFn(DataBatchArgs args, IntPtr hcol)
        {
            OrtValueCollection col = new OrtValueCollection(hcol);

            for (int i = 0; i < args.Values.Count; i++)
            {
                MemoryHandle?memHandle;
                OrtValue     val = args.Values[i].ToOrtValue(out memHandle);

                if (memHandle.HasValue)
                {
                    m_rgCleanUpList.Add(memHandle);
                }

                m_rgCleanUpList.Add(val);

                col.SetAt(i, val, args.Values[i].Name);
            }
        }
Example #3
0
        private List<KeyValuePair<string, List<int>>> getTensorDefs(OrtValueCollection col)
        {
            List<KeyValuePair<string, List<int>>> rgDefs = new List<KeyValuePair<string, List<int>>>();
            int nCount = col.Count;

            for (int i = 0; i < nCount; i++)
            {
                string strName;
                OrtValue val = col.GetAt(i, out strName);
                DisposableNamedOnnxValue shape = DisposableNamedOnnxValue.CreateTensorFromOnnxValue(strName, val);
                Tensor<long> shapet = shape.AsTensor<Int64>();
                List<int> rgShape = new List<int>();

                for (int j = 0; j < shapet.dimensions[0]; j++)
                {
                    long nDim = shapet.GetValue(j);
                    rgShape.Add((int)nDim);
                }

                rgDefs.Add(new KeyValuePair<string, List<int>>(strName, rgShape));
            }

            return rgDefs;
        }
Example #4
0
 /// <summary>
 /// Set an OrtVale at a given index.
 /// </summary>
 /// <param name="nIdx">Specifies the index where the data is to be set.</param>
 /// <param name="val">Specifies the value to set.</param>
 /// <param name="strName">Specifies the name of the value.</param>
 public void SetAt(int nIdx, OrtValue val, string strName = "")
 {
     byte[] rgName = (string.IsNullOrEmpty(strName)) ? null : NativeMethods.GetPlatformSerializedString(strName);
     NativeApiStatus.VerifySuccess(NativeMethodsTraining.OrtSetAt(_nativeHandle, nIdx, val.Handle, rgName));
 }