Exemple #1
0
 public TensorOld PrepareTrain(TensorOld input)
 {
     PreparePredict(input);
     BackwardOutput  = input.GetSameShape();
     FiltersGradient = Filters.GetSameShape();
     BiasGradient    = Bias.GetSameShape();
     return(ForwardOutput);
 }
Exemple #2
0
        /// <summary>
        /// 训练前的准备工作,检查结构,分配内存等
        /// </summary>
        /// <param name="input">输入,主要使用结构信息</param>
        /// <returns></returns>
        public TensorOld PrepareTrain(TensorOld input)
        {
            if (input.Rank != 2)
            {
                throw new TensorShapeException("input tensor must have Rank=2");
            }

            ForwardOutput  = new TensorOld(input.shape[0], UnitCount);
            BackwardOutput = input.GetSameShape();

            if (Weights == null)
            {
                SetWeights(TensorOld.RandGaussian(input.shape[1], UnitCount));
                WeightsGradient = Weights.GetSameShape();
            }
            else
            {
                if (input.shape[1] != Weights.shape[0])
                {
                    throw new TensorShapeException("input and weights are not match!");
                }
            }

            if (Bias == null)
            {
                SetBias(TensorOld.Zeros(1, UnitCount));
                BiasGradient = Bias.GetSameShape();
            }

            sampleStartIndex = new int[input.shape[0]];
            errorStartIndex  = new int[input.shape[0]];
            for (int i = 0; i < sampleStartIndex.Length; i++)
            {
                sampleStartIndex[i] = i * input.shape[1];
                errorStartIndex[i]  = i * UnitCount;
            }

            return(ForwardOutput);
        }