Exemplo n.º 1
0
        public void AddVariable(string nodeId, long[] onnxShape, string onnxLayout)
        {
            var onnxRank              = onnxShape.Length;
            var permuatations         = ONNXLayout.AxisPermutationsForMappingONNXLayoutToBarracuda(onnxRank, onnxLayout);
            var barracudaChannelIndex = permuatations.Length - 1;
            var onnxChannelIndex      = permuatations[barracudaChannelIndex];
            var channels              = (onnxLayout != "?" && onnxChannelIndex >= 0) ? (int)onnxShape[onnxChannelIndex]: -1;
            var layout = VariableTensor.Layout.Unknown;

            if (onnxLayout == "NCHW")
            {
                layout = VariableTensor.Layout.NCHW;
            }
            else if (onnxLayout == "NHWC")
            {
                layout = VariableTensor.Layout.NHWC;
            }

            variables[nodeId] = new VariableTensor {
                features       = channels,
                rank           = onnxRank,
                layout         = layout,
                productOfShape = null
            };
        }
Exemplo n.º 2
0
        public Tensor ToBarracuda(string onnxLayout)
        {
            Profiler.BeginSample("ONNXTensor.ToBarracuda");
            if (onnxLayout == "?")
            {
                throw new OnnxLayerImportException("Unknown ONNX layout in not supported when converting constant tensor to Barracuda");
            }

            Assert.IsTrue(m_Shape.All(v => v > 0));
            var permutations = ONNXLayout.AxisPermutationsForMappingONNXLayoutToBarracuda(rank, onnxLayout);

            Assert.IsTrue(rank <= permutations.Length);

            var outTensor = Permute(m_Data, permutations);

            Profiler.EndSample();
            return(outTensor);
        }