Beispiel #1
0
 protected override void ConfirmField()
 {
     TemporaryOutput = new BufferField(GPU, new OpenCvSharp.Size(outW, outH), outCh);
     TemporarySigma  = new BufferField(GPU, new OpenCvSharp.Size(outW, outH), outCh);
     Kernel          = new KernelField(inCh, outCh, KernelSize, optimizer);
     Kernel.Randmize();
 }
Beispiel #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="span">Data span</param>
        public GuidData(HexBufferSpan span)
            : base(NAME, span)
        {
            if (span.Length != 16)
            {
                throw new ArgumentOutOfRangeException(nameof(span));
            }
            var buffer = span.Buffer;
            var pos    = span.Span.Start;

            A      = new StructField <UInt32Data>("A", new UInt32Data(buffer, pos));
            B      = new StructField <UInt16Data>("B", new UInt16Data(buffer, pos + 4));
            C      = new StructField <UInt16Data>("C", new UInt16Data(buffer, pos + 6));
            D      = new StructField <ByteData>("D", new ByteData(buffer, pos + 8));
            E      = new StructField <ByteData>("E", new ByteData(buffer, pos + 9));
            F      = new StructField <ByteData>("F", new ByteData(buffer, pos + 0x0A));
            G      = new StructField <ByteData>("G", new ByteData(buffer, pos + 0x0B));
            H      = new StructField <ByteData>("H", new ByteData(buffer, pos + 0x0C));
            I      = new StructField <ByteData>("I", new ByteData(buffer, pos + 0x0D));
            J      = new StructField <ByteData>("J", new ByteData(buffer, pos + 0x0E));
            K      = new StructField <ByteData>("K", new ByteData(buffer, pos + 0x0F));
            Fields = new BufferField[] {
                A,
                B,
                C,
                D,
                E,
                F,
                G,
                H,
                I,
                J,
                K,
            };
        }
Beispiel #3
0
        public void Average(Gpu gpu, BufferField sigma, BufferField map, int reduction, int expansion, ref BufferField propagater)
        {
            var sw   = sigma.Width;
            var sh   = sigma.Height;
            var sc   = sigma.Channels;
            var sbuf = sigma.Buffer;

            var mbuf = map.Buffer;

            var pw   = propagater.Width / reduction;
            var ph   = propagater.Height / reduction;
            var pc   = propagater.Channels;
            var pbuf = propagater.Buffer;

            gpu.For(0, propagater.Length / (reduction * reduction), n =>
            {
                int c = (int)(n / (pw * ph));
                int l = n - c * (pw * ph);
                int y = (int)(l / pw);
                int x = l - y * pw;


                double pool = 0, count = 0;
                //bool check = false;
                for (int i = 0; i < expansion; i++)
                {
                    for (int j = 0; j < expansion; j++)
                    {
                        int _x       = x * expansion + i;
                        int _y       = y * expansion + j;
                        double _sbuf = sbuf[c][_x, _y];
                        count++;
                        pool += _sbuf;
                    }
                }
                if (count == 0)
                {
                    pool = 0;
                }
                else
                {
                    pool /= count;
                }

                for (int i = 0; i < reduction; i++)
                {
                    for (int j = 0; j < reduction; j++)
                    {
                        int _x = x * reduction + i;
                        int _y = y * reduction + j;
                        if (mbuf[c][_x, _y] > 0)
                        {
                            pbuf[c][_x, _y] = pool;
                        }
                    }
                }
            });
        }
Beispiel #4
0
        private void Min(Gpu gpu, BufferField input, int reduction, int expansion, ref BufferField map, ref BufferField output)
        {
            var iw   = input.Width;
            var ih   = input.Height;
            var ic   = input.Channels;
            var ibuf = input.Buffer;

            var ow   = output.Width / expansion;
            var oh   = output.Height / expansion;
            var oc   = output.Channels;
            var obuf = output.Buffer;

            var mbuf = map.Buffer;

            gpu.For(0, output.Length / (expansion * expansion), n =>
            {
                int c = (int)(n / (ow * oh));
                int l = n - c * (ow * oh);
                int y = (int)(l / ow);
                int x = l - y * ow;

                double pool = double.MaxValue;
                for (int i = 0; i < reduction; i++)
                {
                    for (int j = 0; j < reduction; j++)
                    {
                        int _x       = x * reduction + i;
                        int _y       = y * reduction + j;
                        double _ibuf = ibuf[c][_x, _y];
                        if (_ibuf < pool)
                        {
                            pool = _ibuf;
                        }
                    }
                }
                for (int i = 0; i < reduction; i++)
                {
                    for (int j = 0; j < reduction; j++)
                    {
                        int _x       = x * reduction + i;
                        int _y       = y * reduction + j;
                        double _ibuf = ibuf[c][_x, _y];
                        if (_ibuf == pool)
                        {
                            mbuf[c][_x, _y] = 1;
                        }
                    }
                }

                for (int i = 0; i < expansion; i++)
                {
                    for (int j = 0; j < expansion; j++)
                    {
                        obuf[c][x * expansion + i, y * expansion + j] = pool;
                    }
                }
            });
        }
Beispiel #5
0
        public void Process(Gpu gpu, BufferField input, KernelField kernel, int dilation, int expand, ref BufferField output)
        {
            var iw   = input.Width;
            var ih   = input.Height;
            var ic   = input.Channels;
            var ibuf = input.Buffer;

            var ow   = output.Width;
            var oh   = output.Height;
            var oc   = output.Channels;
            var obuf = output.Buffer;

            var ks    = kernel.Size;
            var kbias = kernel.Bias;
            var kbuf  = kernel.Buffer;

            gpu.For(0, output.Length, n =>
            {
                int c = (int)(n / (ow * oh));
                int l = n - c * (ow * oh);
                int y = (int)(l / ow);
                int x = l - y * ow;

                double v = kbias[c];
                for (int _c = 0; _c < ic; _c++)
                {
                    for (int s = -ks; s <= ks; s++)
                    {
                        for (int t = -ks; t <= ks; t++)
                        {
                            int i = x + s * dilation;
                            int j = y + t * dilation;
                            if (i % expand == 0 && j % expand == 0)
                            {
                                int _i = i / expand;
                                int _j = j / expand;
                                if (_i >= 0 && _i < iw && _j >= 0 && _j < ih)
                                {
                                    v += ibuf[_c][_i, _j] * kbuf[_c][c][s + ks, t + ks];
                                }
                            }
                        }
                    }
                }
                obuf[c][x, y] = v;
            });
        }
Beispiel #6
0
        public override void Forward(Gpu gpu, BufferField temporaryOutput, ref BufferField output)
        {
            var ow    = output.Width;
            var oh    = output.Height;
            var oc    = output.Channels;
            var obuf  = output.Buffer;
            var tobuf = temporaryOutput.Buffer;

            gpu.For(0, output.Length, n =>
            {
                int c = (int)(n / (ow * oh));
                int l = n - c * (ow * oh);
                int y = (int)(l / ow);
                int x = l - y * ow;

                obuf[c][x, y] = tobuf[c][x, y];
            });
        }
Beispiel #7
0
        public override void Back(Gpu gpu, BufferField sigma, BufferField temporaryOutput, ref BufferField temporarySigma)
        {
            var tsw   = temporarySigma.Width;
            var tsh   = temporarySigma.Height;
            var tsc   = temporarySigma.Channels;
            var tsbuf = temporarySigma.Buffer;

            var sbuf = sigma.Buffer;

            gpu.For(0, temporarySigma.Length, n =>
            {
                int c = (int)(n / (tsw * tsh));
                int l = n - c * (tsw * tsh);
                int y = (int)(l / tsw);
                int x = l - y * tsw;

                tsbuf[c][x, y] = sbuf[c][x, y];
            });
        }
Beispiel #8
0
        public void SetInputSize(int width, int height, int inChannels)
        {
            inW  = width; inH = height;
            inCh = inChannels;
            int _outW = 0, _outH = 0;

            Adjustment(width, height, out _outW, out _outH);
            outW = _outW; outH = _outH;

            var inS  = new OpenCvSharp.Size(inW, inH);
            var outS = new OpenCvSharp.Size(outW, outH);

            Input      = new BufferField(GPU, inS, inCh);
            Output     = new BufferField(GPU, outS, outCh);
            Sigma      = new BufferField(GPU, outS, outCh);
            Propagater = new BufferField(GPU, inS, inCh);

            ConfirmField();
        }
Beispiel #9
0
        public void Process(Gpu gpu, Property.PoolingProperty.PoolType type, BufferField input, int reduction, int expansion, ref BufferField map, ref BufferField output)
        {
            switch (type)
            {
            case Property.PoolingProperty.PoolType.Max:
                Max(gpu, input, reduction, expansion, ref map, ref output);
                break;

            case Property.PoolingProperty.PoolType.Min:
                Min(gpu, input, reduction, expansion, ref map, ref output);
                break;

            case Property.PoolingProperty.PoolType.Average:
                Average(gpu, input, reduction, expansion, ref map, ref output);
                break;

            default:
                break;
            }
        }
Beispiel #10
0
        public void Process(Gpu gpu, Property.PoolingProperty.PoolType type, BufferField sigma, BufferField map, int reduction, int expansion, ref BufferField propagater)
        {
            switch (type)
            {
            case Property.PoolingProperty.PoolType.Max:
                Max(gpu, sigma, map, reduction, expansion, ref propagater);
                break;

            case Property.PoolingProperty.PoolType.Min:
                Min(gpu, sigma, map, reduction, expansion, ref propagater);
                break;

            case Property.PoolingProperty.PoolType.Average:
                Average(gpu, sigma, map, reduction, expansion, ref propagater);
                break;

            default:
                break;
            }
        }
Beispiel #11
0
        public TableRecordData?Create(uint rid)
        {
            if (!MDTable.IsValidRID(rid))
            {
                return(null);
            }
            var position = MDTable.Span.Start + (rid - 1) * MDTable.RowSize;
            var columns  = MDTable.TableInfo.Columns;
            var fields   = new BufferField[columns.Count];

            for (int i = 0; i < fields.Length; i++)
            {
                var column   = columns[i];
                var fieldPos = position + column.Offset;
                var field    = new StructField(column.Name, CreateData(fieldPos, column));
                Debug.Assert(field.Data.Span.Length == column.Size);
                fields[i] = field;
            }
            var span = new HexBufferSpan(Buffer, new HexSpan(position, MDTable.RowSize));

            return(new TableRecordData(MDTable.TableInfo.Name, new MDToken(MDTable.Table, rid), span, fields, TablesHeap));
        }
Beispiel #12
0
 public abstract void Back(Gpu gpu, BufferField sigma, BufferField temporaryOutput, ref BufferField temporarySigma);
Beispiel #13
0
        public string UpdateBufferDropDownData(int bufferfieldid, int ItemID, string ItemName, string ItemCode)
        {
            string        result        = "F";
            List <object> lstTask       = new List <object>();
            BufferField   bf            = new BufferField();
            string        DropdownTitle = "";

            try
            {
                //using (var db = new Cubicle_EntityEntities())
                //{
                //    DropdownTitle = db.BufferFields.Where(a => a.Id == bufferfieldid).Select(a => a.DropdownTitle).FirstOrDefault();
                //}
                //if (DropdownTitle == "Currency")  //Dropdown1 is for currency
                //{
                //    BLCurrencyRepository objCurr = new BLCurrencyRepository();
                //    Currency Cu = new Currency();
                //    Cu = objCurr.GetCurrencyID(ItemID);
                //    Cu.CurrencyName = ItemName;
                //    Cu.CurrencyCode = ItemCode;
                //    Cu.EntityState = EntityState.Modified;
                //    objCurr.UpdateCurrency(Cu);
                //    result = "S";

                //}
                //else if (DropdownTitle == "MaterialUnits")  //Dropdown2 is for MaterialUnit
                //{
                //    BLMaterialUnit objmat = new BLMaterialUnit();
                //    MaterialUnit Mat = new MaterialUnit();
                //    Mat = objmat.GetMaterialUnitBYID(ItemID);
                //    Mat.UnitName = ItemName;
                //    Mat.UnitCode = ItemCode;
                //    Mat.EntityState = EntityState.Modified;
                //    objmat.UpdateMaterialUnit(Mat);
                //    result = "S";
                //}
                //else if (DropdownTitle == "TaxCode") //Dropdown3 is for TaxCode
                //{
                //    BLTaxCodeRepository objmat = new BLTaxCodeRepository();
                //    TaxCode Mat = new TaxCode();
                //    Mat = objmat.GetTaxCodeByID(ItemID);
                //    Mat.Description = ItemName;
                //    Mat.TaxAmount = Convert.ToDecimal(ItemCode); //TaxAmount accepts only decimal values
                //    Mat.EntityState = EntityState.Modified;
                //    objmat.UpdateTaxCode(Mat);
                //    result = "S";
                //}
                //else if (DropdownTitle == "Dropdown4")
                //{
                //    BLDropDown4Repository bldrop = new BLDropDown4Repository();
                //    Dropdown4 dropdown = new Dropdown4();
                //    dropdown = bldrop.GetDropDown4ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown4(dropdown);
                //}
                //else if (DropdownTitle == "Dropdown5")
                //{
                //    BLDropDown5Repository bldrop = new BLDropDown5Repository();
                //    Dropdown5 dropdown = new Dropdown5();
                //    dropdown = bldrop.GetDropDown5ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown5(dropdown);
                //}
                //else if (DropdownTitle == "Dropdown6")
                //{

                //    BLDropDown6Repository bldrop = new BLDropDown6Repository();
                //    Dropdown6 dropdown = new Dropdown6();
                //    dropdown = bldrop.GetDropDown6ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown6(dropdown);
                //}
                //else if (DropdownTitle == "Dropdown7")
                //{
                //    BLDropDown7Repository bldrop = new BLDropDown7Repository();
                //    Dropdown7 dropdown = new Dropdown7();
                //    dropdown = bldrop.GetDropDown7ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown7(dropdown);
                //}
                //else if (DropdownTitle == "Dropdown8")
                //{
                //    BLDropDown8Repository bldrop = new BLDropDown8Repository();
                //    Dropdown8 dropdown = new Dropdown8();
                //    dropdown = bldrop.GetDropDown8ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown8(dropdown);
                //}
                //else if (DropdownTitle == "Dropdown9")
                //{
                //    BLDropDown9Repository bldrop = new BLDropDown9Repository();
                //    Dropdown9 dropdown = new Dropdown9();
                //    dropdown = bldrop.GetDropDown9ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown9(dropdown);
                //}
                //else if (DropdownTitle == "Dropdown10")
                //{
                //    BLDropDown10Repository bldrop = new BLDropDown10Repository();
                //    Dropdown10 dropdown = new Dropdown10();
                //    dropdown = bldrop.GetDropDown10ByID(ItemID);
                //    dropdown.ItemName = ItemName;
                //    dropdown.ItemCode = ItemCode;
                //    dropdown.EntityState = EntityState.Modified;
                //    bldrop.UpdateDropDown10(dropdown);
                //}
            }

            catch (Exception ex)
            {
                //bool false = UserInterfaceExceptionHandler.HandleException(ref ex);
            }
            return(result);
        }
Beispiel #14
0
		protected HexField(BufferField field)
			: this(field.Data, field.Name) {
		}
Beispiel #15
0
 protected override void ConfirmField()
 {
     Map = new BufferField(GPU, new OpenCvSharp.Size(inW, inH), inCh);
 }
Beispiel #16
0
 public abstract void Forward(Gpu gpu, BufferField temporaryOutput, ref BufferField output);
Beispiel #17
0
        public void Process(Gpu gpu, BufferField input, BufferField sigma, int dilation, int expand, ref BufferField propagater, ref KernelField kernel)
        {
            var iw   = input.Width;
            var ih   = input.Height;
            var ic   = input.Channels;
            var ibuf = input.Buffer;

            var sw   = sigma.Width;
            var sh   = sigma.Height;
            var sc   = sigma.Channels;
            var sbuf = sigma.Buffer;

            var ks    = kernel.Size;
            var kbias = kernel.Bias;
            var kbuf  = kernel.Buffer;

            var dkbias = kernel.dBias;
            var dkbuf  = kernel.dBuffer;

            var pw   = propagater.Width;
            var ph   = propagater.Height;
            var pc   = propagater.Channels;
            var pbuf = propagater.Buffer;

            #region Update Kernel
            gpu.For(0, sc, c =>
            {
                double db  = dkbias[c];
                double ddb = 0;
                for (int x = 0; x < sw; x++)
                {
                    for (int y = 0; y < sh; y++)
                    {
                        ddb += sbuf[c][x, y];
                    }
                }
                dkbias[c] = db + (ddb / (sw * sh));
            });

            gpu.For(0, (2 * ks + 1) * (2 * ks + 1), n =>
            {
                int s  = (int)(n / (2 * ks + 1));
                int t  = n - s * (2 * ks + 1);
                int _s = s - ks;
                int _t = t - ks;

                for (int c = 0; c < ic; c++)
                {
                    for (int d = 0; d < sc; d++)
                    {
                        double dk  = dkbuf[c][d][s, t];
                        double ddk = 0;
                        int cnk    = 0;
                        for (int x = 0; x < sw; x++)
                        {
                            for (int y = 0; y < sh; y++)
                            {
                                int _x = x + _s * dilation;
                                int _y = y + _t * dilation;
                                if (_x % expand == 0 && _y % expand == 0)
                                {
                                    int __x = _x / expand;
                                    int __y = _y / expand;
                                    if (__x >= 0 && __x < iw && __y >= 0 && __y < ih)
                                    {
                                        cnk++;
                                        ddk += ibuf[c][__x, __y] * sbuf[d][x, y];
                                    }
                                }
                            }
                        }
                        dkbuf[c][d][s, t] = dk + ((ddk / (sw * sh * (2 * (ks - 1) + 1))));
                    }
                }
            });
            #endregion

            #region Calculate Propagater
            gpu.For(0, propagater.Length, n =>
            {
                int c = (int)(n / (pw * ph));
                int l = n - c * (pw * ph);
                int y = (int)(l / pw);
                int x = l - y * pw;

                double v = 0;
                for (int _c = 0; _c < sc; _c++)
                {
                    for (int s = ks; s >= -ks; s--)
                    {
                        for (int t = ks; t >= -ks; t--)
                        {
                            int i = x + s * dilation;
                            int j = y + t * dilation;
                            if (i % expand == 0 && j % expand == 0)
                            {
                                int _i = i / expand;
                                int _j = j / expand;
                                if (_i >= 0 && _i < sw && _j >= 0 && _j < sh)
                                {
                                    v += sbuf[_c][_i, _j] * kbuf[c][_c][s + ks, t + ks];
                                }
                            }
                        }
                    }
                }
                pbuf[c][x, y] = v;
            });
            #endregion
        }