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(); }
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); } }
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; }