Exemple #1
0
        private void CheckDataBuffer(int index, byte[] data)
        {
            if (data == null)
            {
                string msg = "data is not valid";
                throw NNStreamerExceptionFactory.CreateException(NNStreamerError.InvalidParameter, msg);
            }

            if (index >= Tensor.SizeLimit)
            {
                string msg = "Max size of the tensors is " + Tensor.SizeLimit;
                throw NNStreamerExceptionFactory.CreateException(NNStreamerError.QuotaExceeded, msg);
            }

            if (_tensorsInfo != null)
            {
                if (index >= _tensorsInfo.Count)
                {
                    string msg = "Current information has " + _tensorsInfo.Count + " tensors";
                    throw NNStreamerExceptionFactory.CreateException(NNStreamerError.QuotaExceeded, msg);
                }

                int size = _tensorsInfo.GetTensorSize(index);
                if (data.Length != size)
                {
                    string msg = "Invalid buffer size, required size is " + size.ToString();
                    throw NNStreamerExceptionFactory.CreateException(NNStreamerError.InvalidParameter, msg);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a TensorsData instance with handle which is given by TensorsInfo.
        /// </summary>
        /// <param name="handle">The handle of tensors data.</param>
        /// <param name="info">The handle of tensors info.</param>
        /// <param name="isFetch">The boolean value for fetching the data (Default: false)</param>
        /// <param name="hasOwnership">The boolean value for automatic disposal (Default: true)</param>
        /// <since_tizen> 6 </since_tizen>
        private TensorsData(IntPtr handle, TensorsInfo info, bool isFetch = false, bool hasOwnership = true)
        {
            NNStreamer.CheckNNStreamerSupport();
            NNStreamerError ret = NNStreamerError.None;

            /* Set internal object */
            _handle = handle;
            /* Because developers can change the TensorsInfo object, it should be stored as a deep-copied instance. */
            _tensorsInfo = info.Clone();

            /* Set count */
            int count = 0;

            ret = Interop.Util.GetTensorsCount(_handle, out count);
            NNStreamer.CheckException(ret, "unable to get the count of TensorsData");

            _dataList = new ArrayList(count);

            if (isFetch)
            {
                for (int i = 0; i < count; ++i)
                {
                    IntPtr raw_data;
                    byte[] bufData = null;
                    int    size;

                    ret = Interop.Util.GetTensorData(_handle, i, out raw_data, out size);
                    NNStreamer.CheckException(ret, "unable to get the buffer of TensorsData: " + i.ToString());

                    bufData = Interop.Util.IntPtrToByteArray(raw_data, size);
                    _dataList.Add(bufData);
                }
            }
            else
            {
                for (int i = 0; i < count; ++i)
                {
                    int    size    = info.GetTensorSize(i);
                    byte[] bufData = new byte[size];

                    _dataList.Add(bufData);
                }
            }

            /* If it created as DataReceivedEventArgs, do not dispose. */
            _disposed = !hasOwnership;
        }
Exemple #3
0
        /// <summary>
        /// Creates a TensorsData instance with handle which is given by TensorsInfo.
        /// </summary>
        /// <param name="handle">The handle of tensors data.</param>
        /// <param name="info">The handle of tensors info. (Default: null)</param>
        /// <param name="isFetch">The boolean value for fetching the data (Default: false)</param>
        /// <since_tizen> 6 </since_tizen>
        private TensorsData(IntPtr handle, TensorsInfo info, bool isFetch)
        {
            NNStreamer.CheckNNStreamerSupport();
            NNStreamerError ret = NNStreamerError.None;

            /* Set internal object */
            _handle      = handle;
            _tensorsInfo = info;

            /* Set count */
            int count = 0;

            ret = Interop.Util.GetTensorsCount(_handle, out count);
            NNStreamer.CheckException(ret, "unable to get the count of TensorsData");

            _dataList = new ArrayList(count);

            if (isFetch)
            {
                for (int i = 0; i < count; ++i)
                {
                    IntPtr raw_data;
                    byte[] bufData = null;
                    int    size;

                    ret = Interop.Util.GetTensorData(_handle, i, out raw_data, out size);
                    NNStreamer.CheckException(ret, "unable to get the buffer of TensorsData: " + i.ToString());

                    bufData = Interop.Util.IntPtrToByteArray(raw_data, size);
                    _dataList.Add(bufData);
                }
            }
            else
            {
                for (int i = 0; i < count; ++i)
                {
                    int    size    = info.GetTensorSize(i);
                    byte[] bufData = new byte[size];

                    _dataList.Add(bufData);
                }
            }
        }