Beispiel #1
0
        public static Tensor4[] GetRandBatch(Tensor3[] x, int[] y, int batchSize, NeuralNet net)
        {
            Tensor4 batchX = new Tensor4(x[0].width, x[0].height, x[0].deep, batchSize);
            Tensor4 batchY = new Tensor4(net.output.width, net.output.height, net.output.deep, batchSize);

            int[] indexes = new int[batchSize];

            int index = 0;

            while (true)
            {
                indexes[index] = (int)(rand.NextDouble() * x.Length);
                for (int i = 0; i < index; i++)
                {
                    if (indexes[i] == indexes[index])
                    {
                        break;
                    }
                    if (i == index - 1)
                    {
                        index++;
                        break;
                    }
                }
                if (index == 0)
                {
                    index++;
                }
                if (index == indexes.Length)
                {
                    break;
                }
            }


            for (int i = 0; i < batchSize; i++)
            {
                for (int zInd = 0; zInd < x[indexes[i]].deep; zInd++)
                {
                    for (int yInd = 0; yInd < x[indexes[i]].height; yInd++)
                    {
                        for (int xInd = 0; xInd < x[indexes[i]].width; xInd++)
                        {
                            batchX[i, zInd, yInd, xInd] = x[indexes[i]][zInd, yInd, xInd];
                        }
                    }
                }

                Tensor3 Y = new Tensor3(net.output.width, net.output.height, net.output.deep);
                if (net.output.width != 1)
                {
                    Y[0, 0, y[indexes[i]]] = 1.0;
                }
                else
                {
                    Y[y[indexes[i]], 0, 0] = 1.0;
                }

                for (int zInd = 0; zInd < Y.deep; zInd++)
                {
                    for (int yInd = 0; yInd < Y.height; yInd++)
                    {
                        for (int xInd = 0; xInd < Y.width; xInd++)
                        {
                            batchY[i, zInd, yInd, xInd] = Y[zInd, yInd, xInd];
                        }
                    }
                }
            }

            return(new Tensor4[] { batchX, batchY });
        }
Beispiel #2
0
        public int Calculation(Tensor3 inp, int layNum = 0, double thres = 0.4)
        {
            Tensor4 input = inp.ToTensor4();

            return(CalculationBase(input, layNum, thres)[0]);
        }
Beispiel #3
0
 public int Calculation(Tensor3 input)
 {
     return(CalculationBase(input.ToTensor4()));
 }