示例#1
0
        public override float InferenceTraining(CudaDeviceVariable <float> input)
        {
            float error = 0;

            switch (_norm)
            {
            case Norm.L1:
                //derivative of cost-function. Hier L1-Norm:

                _res.CopyToDevice(input);
                _groundTrouthData.Sub(input, _dx);
                _dx.Threshold_GTVal(0, 1);
                _dx.Threshold_LTVal(0, -1);
                _dx.DivC(_batch * _inChannels * _inWidth * _inHeight);

                _groundTrouthData.Sub(input, _temp);
                _temp.Abs();
                _temp.Sum(_summedError, _buffer);

                error = _summedError;
                error = error / _batch / _inChannels / _inWidth / _inHeight;
                break;

            case Norm.L2:
                //derivative of cost-function. Hier L2-Norm:
                _res.CopyToDevice(input);
                _groundTrouthData.Sub(input, _dx);
                _dx.DivC(_batch * _inChannels * _inWidth * _inHeight);

                _groundTrouthData.Sub(input, _temp);
                _temp.Sqr();
                _temp.Sum(_summedError, _buffer);

                error = _summedError;
                error = error / _batch / _inChannels / _inWidth / _inHeight;
                break;

            case Norm.MSSSIM:
                _res.CopyToDevice(input);
                _kernelMSSSIML1.RunSafe(input, _groundTrouthData, _msssiml1, _dx, _inChannels, _batch, 1.0f);

                _msssiml1.Sum(_summedError, _buffer);
                error = _summedError;
                error = error / _batch / _inChannels;
                break;

            case Norm.Mix:
                _res.CopyToDevice(input);
                _kernelMSSSIML1.RunSafe(input, _groundTrouthData, _msssiml1, _dx, _inChannels, _batch, 0.84f);
                _msssiml1.Sum(_summedError, _buffer);
                error = _summedError;
                break;

            default:
                break;
            }


            return(error);
        }