Exemple #1
0
        public static IntTensor BuildIntTensor(TensorProto t, SyftController ctrl)
        {
            int[] tShape = ONNXTools.GetShape(t);

            IntTensor tensor;

            int[] tData;
            if (t.Int32Data.Count == 0)
            {
                byte[] tmpData = t.RawData.ToByteArray();
                tData = new int[tmpData.Length / 4];
                Buffer.BlockCopy(tmpData, 0, tData, 0, tmpData.Length);
            }
            else
            {
                tData = new int[t.Int32Data.Count];
                t.Int32Data.CopyTo(tData, 0);
            }
            tensor = ctrl.intTensorFactory.Create(_shape: tShape, _data: tData);

            return(tensor);
        }
Exemple #2
0
        public static FloatTensor BuildFloatTensor(TensorProto t, SyftController ctrl, bool autograd = true, bool keepgrads = true)
        {
            int[] tShape = ONNXTools.GetShape(t);

            FloatTensor tensor;

            float[] tData;
            if (t.FloatData.Count == 0)
            {
                byte[] tmpData = t.RawData.ToByteArray();
                tData = new float[tmpData.Length / 4];
                Buffer.BlockCopy(tmpData, 0, tData, 0, tmpData.Length);
            }
            else
            {
                tData = new float[t.FloatData.Count];
                t.FloatData.CopyTo(tData, 0);
            }
            tensor = ctrl.floatTensorFactory.Create(_shape: tShape, _data: tData, _autograd: autograd, _keepgrads: keepgrads);

            return(tensor);
        }