Ejemplo n.º 1
0
        private static Data load_data_swag(string[] paths, int n, int classes, float jitter)
        {
            int    index      = Utils.Rand.Next() % n;
            string randomPath = paths[index];

            Image orig = LoadArgs.load_image_color(randomPath, 0, 0);
            int   h    = orig.H;
            int   w    = orig.W;

            Data d = new Data();

            d.Shallow = 0;
            d.W       = w;
            d.H       = h;

            d.X.Rows = 1;
            d.X.Vals = new float[d.X.Rows][];
            d.X.Cols = h * w * 3;

            int k = (4 + classes) * 30;

            d.Y = new Matrix(1, k);

            int dw = (int)(w * jitter);
            int dh = (int)(h * jitter);

            int pleft  = (int)Utils.rand_uniform(-dw, dw);
            int pright = (int)Utils.rand_uniform(-dw, dw);
            int ptop   = (int)Utils.rand_uniform(-dh, dh);
            int pbot   = (int)Utils.rand_uniform(-dh, dh);

            int swidth  = w - pleft - pright;
            int sheight = h - ptop - pbot;

            float sx = (float)swidth / w;
            float sy = (float)sheight / h;

            int   flip    = Utils.Rand.Next() % 2;
            Image cropped = LoadArgs.crop_image(orig, pleft, ptop, swidth, sheight);

            float dx = ((float)pleft / w) / sx;
            float dy = ((float)ptop / h) / sy;

            Image sized = LoadArgs.resize_image(cropped, w, h);

            if (flip != 0)
            {
                LoadArgs.flip_image(sized);
            }
            d.X.Vals[0] = sized.Data;

            fill_truth_swag(randomPath, d.Y.Vals[0], classes, flip, dx, dy, 1.0f / sx, 1.0f / sy);

            return(d);
        }
Ejemplo n.º 2
0
        private static Data load_data_region(int n, string[] paths, int m, int w, int h, int size, int classes, float jitter, float hue, float saturation, float exposure)
        {
            string[] randomPaths = get_random_paths(paths, n, m);
            int      i;
            Data     d = new Data();

            d.Shallow = 0;

            d.X.Rows = n;
            d.X.Vals = new float[d.X.Rows][];
            d.X.Cols = h * w * 3;


            int k = size * size * (5 + classes);

            d.Y = new Matrix(n, k);
            for (i = 0; i < n; ++i)
            {
                Image orig = LoadArgs.load_image_color(randomPaths[i], 0, 0);

                int oh = orig.H;
                int ow = orig.W;

                int dw = (int)(ow * jitter);
                int dh = (int)(oh * jitter);

                int pleft  = (int)Utils.rand_uniform(-dw, dw);
                int pright = (int)Utils.rand_uniform(-dw, dw);
                int ptop   = (int)Utils.rand_uniform(-dh, dh);
                int pbot   = (int)Utils.rand_uniform(-dh, dh);

                int swidth  = ow - pleft - pright;
                int sheight = oh - ptop - pbot;

                float sx = (float)swidth / ow;
                float sy = (float)sheight / oh;

                int   flip    = Utils.Rand.Next() % 2;
                Image cropped = LoadArgs.crop_image(orig, pleft, ptop, swidth, sheight);

                float dx = ((float)pleft / ow) / sx;
                float dy = ((float)ptop / oh) / sy;

                Image sized = LoadArgs.resize_image(cropped, w, h);
                if (flip != 0)
                {
                    LoadArgs.flip_image(sized);
                }
                LoadArgs.random_distort_image(sized, hue, saturation, exposure);
                d.X.Vals[i] = sized.Data;

                fill_truth_region(randomPaths[i], d.Y.Vals[i], classes, size, flip, dx, dy, 1.0f / sx, 1.0f / sy);
            }
            return(d);
        }