Exemplo n.º 1
0
        ///<summary>Обратное распространение ошибки(градиента) и её попутное вычисление.</summary>
        public float Backward()
        {
            this.Layers[18].Output.DW = new float[this.Layers[18].Output.W.Length];
            var Result = Losses.StyleLoss(this.Layers[18].Output, this.Style4, 0.2e6f);

            this.Layers[18].Backward();
            this.Layers[17].Backward();
            this.Layers[16].Backward();
            Result += Losses.ContentLoss(this.Layers[15].Output, this.Content, 8.0f);
            this.Layers[15].Backward();
            this.Layers[14].Backward();
            this.Layers[13].Backward();
            this.Layers[12].Backward();
            Result += Losses.StyleLoss(this.Layers[11].Output, this.Style3, 0.2e6f);
            this.Layers[11].Backward();
            this.Layers[10].Backward();
            this.Layers[9].Backward();
            this.Layers[8].Backward();
            this.Layers[7].Backward();
            Result += Losses.StyleLoss(this.Layers[6].Output, this.Style2, 0.2e6f);
            this.Layers[6].Backward();
            this.Layers[5].Backward();
            this.Layers[4].Backward();
            this.Layers[3].Backward();
            this.Layers[2].Backward();
            Result += Losses.StyleLoss(this.Layers[1].Output, this.Style1, 0.2e6f);
            this.Layers[1].Backward();
            this.Layers[0].Backward();
            return(Result);
        }
Exemplo n.º 2
0
 ///<summary>Запускает итеративный процесс. Количество итераций: 1000.</summary>
 ///<param name="X">Начальное изображение (холст).</param>
 public void StartIterativeProcess(Tensor X){
   for(int i = 0; i < 1000; i++){
     this.Forward(X);
     var l = this.Backward();
     l += Losses.TVFLoss(X, 1f);
     Adam.Train(X);
     if(OnIterationDone != null){
       OnIterationDone(i, l);
     }
   }
 }