示例#1
0
        //後からActivationを追加する用
        public void SetActivation(CompressibleActivation activation)
        {
            this.Activator = activation;

            //Kernelの再構築が必要
            CreateKernel();
        }
示例#2
0
        protected CompressibleFunction(string functionName, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(name, inputNames, outputNames)
        {
            string kernelNameBase = functionName.Replace(" ", "");

            this.ForwardKernelName    = kernelNameBase + "Forward";
            this.BackwardgWKernelName = kernelNameBase + "gWBackward";
            this.BackwardgXKernelName = kernelNameBase + "gXBackward";

            this.Activator = activation;

            this.SetGpuEnable(gpuEnable);
        }
示例#3
0
        //後からActivationを追加する用
        public void SetActivation(CompressibleActivation activation)
        {
            this.Activator = activation;

            if (this.Activator != null)
            {
                foreach (var activationParameterer in this._activationParameters)
                {
                    this.KernelString = this.KernelString.Replace(activationParameterer.Key, activationParameterer.Value);
                }
            }

            //Kernelの再構築が必要
            CreateKernel();
        }
示例#4
0
        protected CompressibleFunction(string functionName, CompressibleActivation activation = null, KeyValuePair <string, string>[] activationParameters = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(name, inputNames, outputNames)
        {
            string kernelNameBase = functionName.Replace(" ", "");

            this.ForwardKernelName    = kernelNameBase + "Forward";
            this.BackwardgWKernelName = kernelNameBase + "gWBackward";
            this.BackwardgXKernelName = kernelNameBase + "gXBackward";

            this.KernelString = Weaver.GetKernelSource(functionName);

            this._activationParameters = activationParameters;

            this.SetActivation(activation);

            this.SetGpuEnable(gpuEnable);
        }
示例#5
0
        public Deconvolution2D(int inputChannels, int outputChannels, int[] kSize, int[] subSample = null, int[] trim = null, bool noBias = false, Array initialW = null, Array initialb = null, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(FUNCTION_NAME, activation, name, inputNames, outputNames, gpuEnable)
        {
            if (subSample == null)
            {
                subSample = new[] { 1, 1 }
            }
            ;

            if (trim == null)
            {
                trim = new[] { 0, 0 }
            }
            ;

            this._kWidth  = kSize[0];
            this._kHeight = kSize[1];
            this._padX    = trim[0];
            this._padY    = trim[1];
            this.NoBias   = noBias;

            this._strideX = subSample[0];
            this._strideY = subSample[1];

            this.Parameters = new NdArray[noBias ? 1 : 2];

            this.OutputCount = outputChannels;
            this.InputCount  = inputChannels;

            this.Initialize(initialW, initialb);
        }

        void Initialize(Array initialW = null, Array initialb = null)
        {
            this.Weight      = new NdArray(InputCount, OutputCount, this._kHeight, this._kWidth);
            this.Weight.Name = this.Name + " Weight";

            if (initialW == null)
            {
                Initializer.InitWeight(this.Weight);
            }
            else
            {
                this.Weight.Data = Real.ToRealArray(initialW);
            }

            this.Parameters[0] = this.Weight;


            if (!NoBias)
            {
                this.Bias      = new NdArray(OutputCount);
                this.Bias.Name = this.Name + " Bias";

                if (initialb != null)
                {
                    this.Bias.Data = Real.ToRealArray(initialb);
                }

                this.Parameters[1] = this.Bias;
            }
        }
示例#6
0
        public Deconvolution2D(int inputChannels, int outputChannels, int kSize, int stride = 1, int pad = 0, bool noBias = false, Array initialW = null, Array initialb = null, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(FUNCTION_NAME, activation, name, inputNames, outputNames, gpuEnable)
        {
            this._kWidth  = kSize;
            this._kHeight = kSize;
            this._padX    = pad;
            this._padY    = pad;
            this._strideX = stride;
            this._strideY = stride;
            this.NoBias   = noBias;

            this.Parameters = new NdArray[noBias ? 1 : 2];

            this.OutputCount = outputChannels;
            this.InputCount  = inputChannels;

            this.Initialize(initialW, initialb);
        }
示例#7
0
        public Convolution2D(int inputChannels, int outputChannels, int[] kSize, int[] stride = null, int[] pad = null, bool noBias = false, Array initialW = null, Array initialb = null, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(FUNCTION_NAME, activation, name, inputNames, outputNames, gpuEnable)
        {
            if (pad == null)
            {
                pad = new[] { 0, 0 }
            }
            ;

            if (stride == null)
            {
                stride = new[] { 1, 1 }
            }
            ;

            this._kWidth  = kSize[0];
            this._kHeight = kSize[1];
            this._strideX = stride[0];
            this._strideY = stride[1];
            this._padX    = pad[0];
            this._padY    = pad[1];
            this.NoBias   = noBias;

            this.Parameters = new NdArray[noBias ? 1 : 2];

            this.OutputCount = outputChannels;
            this.InputCount  = inputChannels;

            this.Initialize(initialW, initialb);
        }
示例#8
0
        public Convolution2D(int inputChannels, int outputChannels, Size kSize, Size stride = new Size(), Size pad = new Size(), bool noBias = false, Array initialW = null, Array initialb = null, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(FUNCTION_NAME, activation, new[] { new KeyValuePair <string, string>(PARAM_NAME, PARAM_VALUE) }, name, inputNames, outputNames, gpuEnable)
        {
            if (pad == Size.Empty)
            {
                pad = new Size(0, 0);
            }

            if (stride == Size.Empty)
            {
                stride = new Size(1, 1);
            }

            this._kWidth  = kSize.Width;
            this._kHeight = kSize.Height;
            this._strideX = stride.Width;
            this._strideY = stride.Height;
            this._padX    = pad.Width;
            this._padY    = pad.Height;
            this.NoBias   = noBias;

            this.Parameters = new NdArray[noBias ? 1 : 2];

            this.OutputCount = outputChannels;
            this.InputCount  = inputChannels;

            this.Initialize(initialW, initialb);
        }
示例#9
0
        public Linear(int inputCount, int outputCount, bool noBias = false, Array initialW = null, Array initialb = null, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(FUNCTION_NAME, activation, name, inputNames, outputNames, gpuEnable)
        {
            this.OutputCount = outputCount;
            this.InputCount  = inputCount;

            this.Weight      = new NdArray(outputCount, inputCount);
            this.Weight.Name = this.Name + " Weight";

            this.NoBias = noBias;

            this.Parameters = new NdArray[noBias ? 1 : 2];

            if (initialW == null)
            {
                Initializer.InitWeight(this.Weight);
            }
            else
            {
                this.Weight.Data = Real.ToRealArray(initialW);
            }

            this.Parameters[0] = this.Weight;

            if (!noBias)
            {
                this.Bias      = new NdArray(outputCount);
                this.Bias.Name = this.Name + " Bias";

                if (initialb != null)
                {
                    this.Bias.Data = Real.ToRealArray(initialb);
                }

                this.Parameters[1] = this.Bias;
            }
        }
示例#10
0
        public Deconvolution2D(int inputChannels, int outputChannels, int kSize, int subSample = 1, int trim = 0, bool noBias = false, Array initialW = null, Array initialb = null, CompressibleActivation activation = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(FUNCTION_NAME, activation, new [] { new KeyValuePair <string, string>(PARAM_NAME, PARAM_VALUE) }, name, inputNames, outputNames, gpuEnable)
        {
            this._kWidth     = kSize;
            this._kHeight    = kSize;
            this._trimX      = trim;
            this._trimY      = trim;
            this._subSampleX = subSample;
            this._subSampleY = subSample;
            this.NoBias      = noBias;

            this.Parameters = new NdArray[noBias ? 1 : 2];

            this.OutputCount = outputChannels;
            this.InputCount  = inputChannels;

            this.Initialize(initialW, initialb);
        }