示例#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);
        }
示例#2
0
        public void Track(NPPImage_32fC1 imgTrack, NPPImage_32fC1 imgRef, NPPImage_32fC2 preShift, int i, float2 baseShiftRef, float baseRotationRef, float2 baseShifttoTrack, float baseRotationtoTrack, float threshold)
        {
            if (imgTrack.WidthRoi != imgRef.WidthRoi || imgTrack.HeightRoi != imgRef.HeightRoi ||
                imgTrack.WidthRoi != currentWidth || imgTrack.HeightRoi != currentHeight)
            {
                throw new ArgumentOutOfRangeException();
            }

            int level = imgTrack.Width / imgTrack.WidthRoi;

            convertToTilesBorder.RunSafe(imgRef, imgRefSortedTiles, currentTileSize, currentMaxShift, CurrentBlockCountX, CurrentBlockCountY, baseShiftRef, baseRotationRef); //template
            forward[i].Exec(imgRefSortedTiles.DevicePointer, imgRefCplx.DevicePointer);

            convertToTiles.RunSafe(imgTrack, imgToTrackSortedTiles, preShift, currentTileSize, currentMaxShift, CurrentBlockCountX, CurrentBlockCountY, baseShifttoTrack, baseRotationtoTrack); //image in paper

            //DumpFloat(imgToTrackSortedTiles, currentTileSize + 2* currentMaxShift, currentTileSize + 2 * currentMaxShift, CurrentBlockCountX * CurrentBlockCountY, tileIdx, "tilesTrack_" + level + "_" + debugCallCounter + ".bin");
            //DumpFloat(imgRefSortedTiles, currentTileSize + 2 * currentMaxShift, currentTileSize + 2 * currentMaxShift, CurrentBlockCountX * CurrentBlockCountY, tileIdx, "tilesRef_" + level + "_" + debugCallCounter + ".bin");

            forward[i].Exec(imgToTrackSortedTiles.DevicePointer, imgToTrackCplx.DevicePointer);

            conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);

            backward[i].Exec(imgToTrackCplx.DevicePointer, imgCrossCorrelation.DevicePointer);
            imgCrossCorrelation.DivC(CurrentBlockSize * CurrentBlockSize);

            squaredSumKernel.RunSafe(imgRefSortedTiles, squaredSumsOfTiles, currentMaxShift, currentTileSize, CurrentBlockCountX * CurrentBlockCountY);
            //DumpFloat(squaredSumsOfTiles, 1, 1, CurrentBlockCountX * CurrentBlockCountY, tileIdx, "squaredSums_" + level + "_" + debugCallCounter + ".bin");

            boxFilterXKernel.RunSafe(imgToTrackSortedTiles, imgRefSortedTiles, currentMaxShift, currentTileSize, CurrentBlockCountX * CurrentBlockCountY);
            boxFilterYKernel.RunSafe(imgRefSortedTiles, imgToTrackSortedTiles, currentMaxShift, currentTileSize, CurrentBlockCountX * CurrentBlockCountY);
            //DumpFloat(imgToTrackSortedTiles, currentTileSize + 2 * currentMaxShift, currentTileSize + 2 * currentMaxShift, CurrentBlockCountX * CurrentBlockCountY, tileIdx, "boxFilter_" + level + "_" + debugCallCounter + ".bin");
            normalizedCCKernel.RunSafe(imgCrossCorrelation, squaredSumsOfTiles, imgToTrackSortedTiles, shiftImages, currentMaxShift, currentTileSize, CurrentBlockCountX * CurrentBlockCountY);

            //DumpFloat(shiftImages, (2 * currentMaxShift + 1), (2 * currentMaxShift + 1), CurrentBlockCountX * CurrentBlockCountY, tileIdx, "tilesShift_" + level + "_" + debugCallCounter + ".bin");

            patchShift.SetRoi(0, 0, CurrentBlockCountX, CurrentBlockCountY);
            findMinimumKernel.RunSafe(shiftImages, patchShift, currentMaxShift, CurrentBlockCountX, CurrentBlockCountY, threshold);

            NPPImage_32fC1 preShiftFloat   = new NPPImage_32fC1(preShift.DevicePointer, 2 * CurrentBlockCountX, CurrentBlockCountY, preShift.Pitch);
            NPPImage_32fC1 patchShiftFloat = new NPPImage_32fC1(patchShift.DevicePointer, 2 * CurrentBlockCountX, CurrentBlockCountY, patchShift.Pitch);

            preShiftFloat.Add(patchShiftFloat);
            debugCallCounter++;
        }