private static Data load_data_super(string[] paths, int n, int m, int w, int h, int scale) { if (m != 0) { paths = get_random_paths(paths, n, m); } Data d = new Data(); d.Shallow = 0; int i; d.X.Rows = n; d.X.Vals = new float[n][]; d.X.Cols = w * h * 3; d.Y.Rows = n; d.Y.Vals = new float[n][]; d.Y.Cols = w * scale * h * scale * 3; for (i = 0; i < n; ++i) { Image im = LoadArgs.load_image_color(paths[i], 0, 0); Image crop = LoadArgs.random_crop_image(im, w * scale, h * scale); int flip = Utils.Rand.Next() % 2; if (flip != 0) { LoadArgs.flip_image(crop); } Image resize = LoadArgs.resize_image(crop, w, h); d.X.Vals[i] = resize.Data; d.Y.Vals[i] = crop.Data; } return(d); }
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); }
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); }
private static Matrix load_image_augment_paths(string[] paths, int n, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) { int i; Matrix x = new Matrix(n); for (i = 0; i < n; ++i) { Image im = LoadArgs.load_image_color(paths[i], 0, 0); Image crop = LoadArgs.random_augment_image(im, angle, aspect, min, max, size); int flip = Utils.Rand.Next() % 2; if (flip != 0) { LoadArgs.flip_image(crop); } LoadArgs.random_distort_image(crop, hue, saturation, exposure); x.Vals[i] = crop.Data; x.Cols = crop.H * crop.W * crop.C; } return(x); }