From f542d0542b1e51ca7dd12bc6b96f6a299371ae8d Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Wed, 14 Jun 2017 17:38:05 +0200 Subject: [PATCH] Initial commit --- Makefile | 47 +++++++ build.py | 41 +++++++ misc.cc | 29 +++++ misc.h | 97 +++++++++++++++ random.cc | 30 +++++ random.h | 32 +++++ shape.cc | 262 ++++++++++++++++++++++++++++++++++++++++ shape.h | 62 ++++++++++ svrt.c | 49 ++++++++ svrt.h | 26 ++++ svrt_generator.cc | 166 +++++++++++++++++++++++++ svrt_generator.h | 42 +++++++ test-svrt.py | 39 ++++++ vignette.cc | 205 +++++++++++++++++++++++++++++++ vignette.h | 54 +++++++++ vignette_generator.cc | 29 +++++ vignette_generator.h | 44 +++++++ vision_problem_1.cc | 75 ++++++++++++ vision_problem_1.h | 39 ++++++ vision_problem_10.cc | 70 +++++++++++ vision_problem_10.h | 39 ++++++ vision_problem_11.cc | 97 +++++++++++++++ vision_problem_11.h | 41 +++++++ vision_problem_12.cc | 81 +++++++++++++ vision_problem_12.h | 41 +++++++ vision_problem_13.cc | 110 +++++++++++++++++ vision_problem_13.h | 41 +++++++ vision_problem_14.cc | 93 ++++++++++++++ vision_problem_14.h | 42 +++++++ vision_problem_15.cc | 63 ++++++++++ vision_problem_15.h | 38 ++++++ vision_problem_16.cc | 66 ++++++++++ vision_problem_16.h | 38 ++++++ vision_problem_17.cc | 97 +++++++++++++++ vision_problem_17.h | 39 ++++++ vision_problem_18.cc | 67 ++++++++++ vision_problem_18.h | 39 ++++++ vision_problem_19.cc | 75 ++++++++++++ vision_problem_19.h | 38 ++++++ vision_problem_2.cc | 80 ++++++++++++ vision_problem_2.h | 42 +++++++ vision_problem_20.cc | 55 +++++++++ vision_problem_20.h | 39 ++++++ vision_problem_21.cc | 75 ++++++++++++ vision_problem_21.h | 39 ++++++ vision_problem_22.cc | 63 ++++++++++ vision_problem_22.h | 39 ++++++ vision_problem_23.cc | 125 +++++++++++++++++++ vision_problem_23.h | 40 ++++++ vision_problem_3.cc | 102 ++++++++++++++++ vision_problem_3.h | 39 ++++++ vision_problem_4.cc | 73 +++++++++++ vision_problem_4.h | 40 ++++++ vision_problem_5.cc | 50 ++++++++ vision_problem_5.h | 39 ++++++ vision_problem_6.cc | 102 ++++++++++++++++ vision_problem_6.h | 39 ++++++ vision_problem_7.cc | 50 ++++++++ vision_problem_7.h | 38 ++++++ vision_problem_8.cc | 82 +++++++++++++ vision_problem_8.h | 41 +++++++ vision_problem_9.cc | 78 ++++++++++++ vision_problem_9.h | 38 ++++++ vision_problem_tools.cc | 62 ++++++++++ vision_problem_tools.h | 41 +++++++ 65 files changed, 4094 insertions(+) create mode 100644 Makefile create mode 100755 build.py create mode 100644 misc.cc create mode 100644 misc.h create mode 100644 random.cc create mode 100644 random.h create mode 100644 shape.cc create mode 100644 shape.h create mode 100644 svrt.c create mode 100644 svrt.h create mode 100644 svrt_generator.cc create mode 100644 svrt_generator.h create mode 100755 test-svrt.py create mode 100644 vignette.cc create mode 100644 vignette.h create mode 100644 vignette_generator.cc create mode 100644 vignette_generator.h create mode 100644 vision_problem_1.cc create mode 100644 vision_problem_1.h create mode 100644 vision_problem_10.cc create mode 100644 vision_problem_10.h create mode 100644 vision_problem_11.cc create mode 100644 vision_problem_11.h create mode 100644 vision_problem_12.cc create mode 100644 vision_problem_12.h create mode 100644 vision_problem_13.cc create mode 100644 vision_problem_13.h create mode 100644 vision_problem_14.cc create mode 100644 vision_problem_14.h create mode 100644 vision_problem_15.cc create mode 100644 vision_problem_15.h create mode 100644 vision_problem_16.cc create mode 100644 vision_problem_16.h create mode 100644 vision_problem_17.cc create mode 100644 vision_problem_17.h create mode 100644 vision_problem_18.cc create mode 100644 vision_problem_18.h create mode 100644 vision_problem_19.cc create mode 100644 vision_problem_19.h create mode 100644 vision_problem_2.cc create mode 100644 vision_problem_2.h create mode 100644 vision_problem_20.cc create mode 100644 vision_problem_20.h create mode 100644 vision_problem_21.cc create mode 100644 vision_problem_21.h create mode 100644 vision_problem_22.cc create mode 100644 vision_problem_22.h create mode 100644 vision_problem_23.cc create mode 100644 vision_problem_23.h create mode 100644 vision_problem_3.cc create mode 100644 vision_problem_3.h create mode 100644 vision_problem_4.cc create mode 100644 vision_problem_4.h create mode 100644 vision_problem_5.cc create mode 100644 vision_problem_5.h create mode 100644 vision_problem_6.cc create mode 100644 vision_problem_6.h create mode 100644 vision_problem_7.cc create mode 100644 vision_problem_7.h create mode 100644 vision_problem_8.cc create mode 100644 vision_problem_8.h create mode 100644 vision_problem_9.cc create mode 100644 vision_problem_9.h create mode 100644 vision_problem_tools.cc create mode 100644 vision_problem_tools.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7629f3d --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ + +# svrt is the ``Synthetic Visual Reasoning Test'', an image +# generator for evaluating classification performance of machine +# learning systems, humans and primates. +# +# Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ +# Written by Francois Fleuret +# +# This file is part of svrt. +# +# svrt is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# svrt is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with selector. If not, see . + +ifeq ($(DEBUG),yes) + CXXFLAGS = -fPIC -Wall -g -DDEBUG +else + CXXFLAGS = -fPIC -Wall -g -O3 +endif + +all: libsvrt.so TAGS + +TAGS: *.cc *.h + etags *.cc *.h + +libsvrt.so: \ + misc.o random.o \ + svrt_generator.o \ + shape.o vignette.o vignette_generator.o \ + $(patsubst %.cc,%.o,$(wildcard vision_problem_*.cc)) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -fPIC -o $@ $^ + +Makefile.depend: *.h *.cc Makefile + $(CC) $(CXXFLAGS) -M *.cc > Makefile.depend + +clean: + \rm -f svrt *.o *.so Makefile.depend + +-include Makefile.depend diff --git a/build.py b/build.py new file mode 100755 index 0000000..ef0b46d --- /dev/null +++ b/build.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +# svrt is the ``Synthetic Visual Reasoning Test'', an image +# generator for evaluating classification performance of machine +# learning systems, humans and primates. +# +# Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ +# Written by Francois Fleuret +# +# This file is part of svrt. +# +# svrt is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# svrt is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with selector. If not, see . + +import os +from torch.utils.ffi import create_extension + +abs_path = os.path.dirname(os.path.abspath(__file__)) + +ffi = create_extension( + '_ext.svrt', + headers = [ 'svrt.h' ], + sources = [ 'svrt.c' ], + extra_objects = [ abs_path + '/libsvrt.so' ], + libraries = [ ], + library_dirs = [ ], + define_macros = [ ], + with_cuda = False +) + +if __name__ == '__main__': + ffi.build() diff --git a/misc.cc b/misc.cc new file mode 100644 index 0000000..3affb33 --- /dev/null +++ b/misc.cc @@ -0,0 +1,29 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include + +using namespace std; + +#include "misc.h" diff --git a/misc.h b/misc.h new file mode 100644 index 0000000..e101861 --- /dev/null +++ b/misc.h @@ -0,0 +1,97 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef MISC_H +#define MISC_H + +#include +#include +#include +#include +#include +#include + +using namespace std; + +typedef double scalar_t; +// typedef float scalar_t; + +const int buffer_size = 1024; + +using namespace std; + +#ifdef DEBUG +#define ASSERT(x) if(!(x)) { \ + std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << endl; \ + abort(); \ +} +#else +#define ASSERT(x) +#endif + +template +T **allocate_array(int a, int b) { + T *tmp = new T[a * b]; + T **array = new T *[a]; + for(int k = 0; k < a; k++) { + array[k] = tmp; + tmp += b; + } + return array; +} + +template +void deallocate_array(T **array) { + delete[] array[0]; + delete[] array; +} + +template +void write_var(ostream *os, const T *x) { os->write((char *) x, sizeof(T)); } + +template +void read_var(istream *is, T *x) { is->read((char *) x, sizeof(T)); } + +template +inline T sq(T x) { + return x * x; +} + +inline scalar_t log2(scalar_t x) { + return log(x)/log(2.0); +} + +template +void grow(int *nb_max, int nb, T** current, int factor) { + ASSERT(*nb_max > 0); + if(nb == *nb_max) { + T *tmp = new T[*nb_max * factor]; + memcpy(tmp, *current, *nb_max * sizeof(T)); + delete[] *current; + *current = tmp; + *nb_max *= factor; + } +} + +#endif diff --git a/random.cc b/random.cc new file mode 100644 index 0000000..28ae5d6 --- /dev/null +++ b/random.cc @@ -0,0 +1,30 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "random.h" + +scalar_t random_uniform_0_1() { + return drand48(); + // return THRandom_uniform(SVRT_generator, 0, 1); +} diff --git a/random.h b/random.h new file mode 100644 index 0000000..283f8e7 --- /dev/null +++ b/random.h @@ -0,0 +1,32 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef RANDOM_H +#define RANDOM_H + +#include "misc.h" + +scalar_t random_uniform_0_1(); + +#endif diff --git a/shape.cc b/shape.cc new file mode 100644 index 0000000..057face --- /dev/null +++ b/shape.cc @@ -0,0 +1,262 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "shape.h" + +int Shape::generate_part_part(scalar_t *xp, scalar_t *yp, int *nb_pixels, + scalar_t radius, scalar_t hole_radius, + scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2) { + if(abs(x1 - x2) > gap_max || abs(y1 - y2) > gap_max) { + + scalar_t d = sqrt(scalar_t(sq(x1 - x2) + sq(y1 - y2)))/5; + scalar_t x3, y3, dx, dy; + + do { + // Isotropic jump + do { + dx = (2 * random_uniform_0_1() - 1) * d; + dy = (2 * random_uniform_0_1() - 1) * d; + } while(sq(dx) + sq(dy) > sq(d)); + x3 = (x1 + x2) / 2 + dx; + y3 = (y1 + y2) / 2 + dy; + } while(sq(x3) + sq(y3) > sq(radius)); + + if(generate_part_part(xp, yp, nb_pixels, + radius, hole_radius, x1, y1, x3, y3)) { + return 1; + } + + if(generate_part_part(xp, yp, nb_pixels, + radius, hole_radius, x3, y3, x2, y2)) { + return 1; + } + + } else { + + if(sq(x1) + sq(y1) >= sq(radius) || sq(x1) + sq(y1) < sq(hole_radius)) { + return 1; + } + + xp[*nb_pixels] = x1; + yp[*nb_pixels] = y1; + (*nb_pixels)++; + + } + + return 0; +} + +void Shape::generate_part(scalar_t *xp, scalar_t *yp, int *nb_pixels, + scalar_t radius, scalar_t hole_radius) { + scalar_t x1, y1, x2, y2, x3, y3, x4, y4; + int err1, err2, err3, err4; + + do { + *nb_pixels = 0; + + do { + x1 = random_uniform_0_1() * radius; + y1 = random_uniform_0_1() * radius; + } while(sq(x1) + sq(y1) > sq(radius) || sq(x1) + sq(y1) < sq(hole_radius)); + + do { + x2 = -random_uniform_0_1() * radius; + y2 = random_uniform_0_1() * radius; + } while(sq(x2) + sq(y2) > sq(radius) || sq(x2) + sq(y2) < sq(hole_radius)); + + do { + x3 = -random_uniform_0_1() * radius; + y3 = -random_uniform_0_1() * radius; + } while(sq(x3) + sq(y3) > sq(radius) || sq(x3) + sq(y3) < sq(hole_radius)); + + do { + x4 = random_uniform_0_1() * radius; + y4 = -random_uniform_0_1() * radius; + } while(sq(x4) + sq(y4) > sq(radius) || sq(x4) + sq(y4) < sq(hole_radius)); + + n_pixels1 = *nb_pixels; + err1 = generate_part_part(xp, yp, nb_pixels, radius, hole_radius, x1, y1, x2, y2); + n_pixels2 = *nb_pixels; + err2 = generate_part_part(xp, yp, nb_pixels, radius, hole_radius, x2, y2, x3, y3); + n_pixels3 = *nb_pixels; + err3 = generate_part_part(xp, yp, nb_pixels, radius, hole_radius, x3, y3, x4, y4); + n_pixels4 = *nb_pixels; + err4 = generate_part_part(xp, yp, nb_pixels, radius, hole_radius, x4, y4, x1, y1); + + } while(err1 || err2 || err3 || err4); +} + +Shape::Shape() { + nb_pixels = 0; + x_pixels = 0; + y_pixels = 0; +} + +Shape::~Shape() { + delete[] x_pixels; + delete[] y_pixels; +} + +void Shape::randomize(scalar_t radius, scalar_t hole_radius) { + delete[] x_pixels; + delete[] y_pixels; + nb_pixels = 0; + scalar_t tmp_x_pixels[nb_max_pixels], tmp_y_pixels[nb_max_pixels]; + generate_part(tmp_x_pixels, tmp_y_pixels, &nb_pixels, radius, hole_radius); + x_pixels = new scalar_t[nb_pixels]; + y_pixels = new scalar_t[nb_pixels]; + for(int p = 0; p < nb_pixels; p++) { + x_pixels[p] = tmp_x_pixels[p]; + y_pixels[p] = tmp_y_pixels[p]; + } + + rotate(random_uniform_0_1() * M_PI * 2); + + // { // ******************************* START *************************** +// #warning Test code added on 2009 Sep 09 18:15:25 + // for(int p = 0; p < nb_pixels; p++) { + // cout << x_pixels[p] << " " << y_pixels[p] << endl; + // } + // } // ******************************** END **************************** + +} + +void Shape::copy(Shape *shape) { + delete[] x_pixels; + delete[] y_pixels; + nb_pixels = shape->nb_pixels; + n_pixels1 = shape->n_pixels1; + n_pixels2 = shape->n_pixels2; + n_pixels3 = shape->n_pixels3; + n_pixels4 = shape->n_pixels4; + x_pixels = new scalar_t[nb_pixels]; + y_pixels = new scalar_t[nb_pixels]; + for(int p = 0; p < nb_pixels; p++) { + x_pixels[p] = shape->x_pixels[p]; + y_pixels[p] = shape->y_pixels[p]; + } +} + +void Shape::scale(scalar_t s) { + for(int p = 0; p < nb_pixels; p++) { + x_pixels[p] *= s; + y_pixels[p] *= s; + } +} + +void Shape::rotate(scalar_t alpha) { + scalar_t ux = cos(alpha), uy = -sin(alpha); + scalar_t vx = sin(alpha), vy = cos(alpha); + scalar_t x, y; + for(int p = 0; p < nb_pixels; p++) { + x = x_pixels[p] * ux + y_pixels[p] * uy; + y = x_pixels[p] * vx + y_pixels[p] * vy; + x_pixels[p] = x; + y_pixels[p] = y; + } +} + +void Shape::symmetrize(scalar_t axis_x, scalar_t axis_y) { + scalar_t sql = sq(axis_x) + sq(axis_y); + scalar_t u, v; + for(int p = 0; p < nb_pixels; p++) { + u = x_pixels[p] * axis_y - y_pixels[p] * axis_x; + v = x_pixels[p] * axis_x + y_pixels[p] * axis_y; + u = - u; + x_pixels[p] = ( u * axis_y + v * axis_x) / sql; + y_pixels[p] = (- u * axis_x + v * axis_y) / sql; + } +} + + +int Shape::overwrites(Vignette *vignette, scalar_t xc, scalar_t yc, int n1, int n2) { + int x1 = int(x_pixels[n1 % nb_pixels] + xc); + int y1 = int(y_pixels[n1 % nb_pixels] + yc); + int x2 = int(x_pixels[n2 % nb_pixels] + xc); + int y2 = int(y_pixels[n2 % nb_pixels] + yc); + int n3 = (n1 + n2) / 2; + + if(n1 + 1 < n2 && (abs(x1 - x2) > 1 || abs(y1 - y2) > 1)) { + return + overwrites(vignette, xc, yc, n1, n3) || + overwrites(vignette, xc, yc, n3, n2); + } else { + + if(x1 >= margin && x1 < Vignette::width - margin && + y1 >= margin && y1 < Vignette::height - margin) { + + if(margin > 0) { + for(int xx = x1 - margin; xx <= x1 + margin; xx++) { + for(int yy = y1 - margin; yy <= y1 + margin; yy++) { + if(vignette->content[xx + Vignette::width * yy] != 255) { + return 1; + } + } + } + } + + return 0; + } else { + return 1; + } + } +} + +int Shape::overwrites(Vignette *vignette, scalar_t xc, scalar_t yc) { + return + overwrites(vignette, xc, yc, n_pixels1, n_pixels2) || + overwrites(vignette, xc, yc, n_pixels2, n_pixels3) || + overwrites(vignette, xc, yc, n_pixels3, n_pixels4) || + overwrites(vignette, xc, yc, n_pixels4, nb_pixels); +} + +void Shape::draw(int part_number, Vignette *vignette, scalar_t xc, scalar_t yc, int n1, int n2) { + int x1 = int(x_pixels[n1 % nb_pixels] + xc); + int y1 = int(y_pixels[n1 % nb_pixels] + yc); + int x2 = int(x_pixels[n2 % nb_pixels] + xc); + int y2 = int(y_pixels[n2 % nb_pixels] + yc); + int n3 = (n1 + n2) / 2; + + if(n1 + 1 < n2 && (abs(x1 - x2) > 1 || abs(y1 - y2) > 1)) { + draw(part_number, vignette, xc, yc, n1, n3); + draw(part_number, vignette, xc, yc, n3, n2); + } else { + if(x1 >= margin && x1 < Vignette::width-margin && + y1 >= margin && y1 < Vignette::height-margin) { + vignette->content[x1 + Vignette::width * y1] = 0; +#ifdef KEEP_PART_PRESENCE + vignette->part_presence[x1 + Vignette::width * y1] |= (1 << part_number); +#endif + } else { + abort(); + } + } +} + +void Shape::draw(int part_number, Vignette *vignette, scalar_t xc, scalar_t yc) { + draw(part_number, vignette, xc, yc, n_pixels1, n_pixels2); + draw(part_number, vignette, xc, yc, n_pixels2, n_pixels3); + draw(part_number, vignette, xc, yc, n_pixels3, n_pixels4); + draw(part_number, vignette, xc, yc, n_pixels4, nb_pixels); +} diff --git a/shape.h b/shape.h new file mode 100644 index 0000000..6e09f02 --- /dev/null +++ b/shape.h @@ -0,0 +1,62 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef SHAPE_H +#define SHAPE_H + +#include "misc.h" +#include "random.h" +#include "vignette.h" + +class Shape { + static const int margin = 1; + static const int nb_max_pixels = Vignette::width * Vignette::height; + static const scalar_t gap_max = 0.25; + int n_pixels1, n_pixels2, n_pixels3, n_pixels4; + int nb_pixels; + scalar_t xc, yc; + scalar_t *x_pixels; + scalar_t *y_pixels; + + int generate_part_part(scalar_t *xp, scalar_t *yp, int *nb_pixels, scalar_t radius, scalar_t hole_radius, + scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2); + void generate_part(scalar_t *xp, scalar_t *yp, int *nb_pixels, scalar_t radius, scalar_t hole_radius); + int overwrites(Vignette *vignette, scalar_t xc, scalar_t yc, int first, int nb); + void draw(int part_number, Vignette *vignette, scalar_t xc, scalar_t yc, int first, int nb); + +public: + Shape(); + ~Shape(); + + void randomize(scalar_t radius, scalar_t hole_radius); + void copy(Shape *shape); + void scale(scalar_t s); + void rotate(scalar_t alpha); + void symmetrize(scalar_t axis_x, scalar_t axis_y); + + int overwrites(Vignette *vignette, scalar_t xc, scalar_t yc); + void draw(int part_number, Vignette *vignette, scalar_t xc, scalar_t yc); +}; + +#endif diff --git a/svrt.c b/svrt.c new file mode 100644 index 0000000..0f53642 --- /dev/null +++ b/svrt.c @@ -0,0 +1,49 @@ + +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include + +#include "svrt_generator.h" + +THByteTensor *generate_vignettes(long n_problem, long nb_vignettes) { + struct VignetteSet vs; + + svrt_generate_vignettes(n_problem, nb_vignettes, &vs); + printf("SANITY %d %d %d\n", vs.nb_vignettes, vs.width, vs.height); + + THLongStorage *size = THLongStorage_newWithSize(3); + size->data[0] = nb_vignettes; + size->data[1] = vs.height; + size->data[2] = vs.width; + + THByteTensor *result = THByteTensor_newWithSize(size, NULL); + THLongStorage_free(size); + + /* st0 = THByteTensor_stride(result, 0); */ + /* st1 = THByteTensor_stride(result, 1); */ + /* st2 = THByteTensor_stride(result, 2); */ + + return result; +} diff --git a/svrt.h b/svrt.h new file mode 100644 index 0000000..4335df3 --- /dev/null +++ b/svrt.h @@ -0,0 +1,26 @@ + +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +THByteTensor *generate_vignettes(long n_problem, long nb_images); diff --git a/svrt_generator.cc b/svrt_generator.cc new file mode 100644 index 0000000..82b7c3b --- /dev/null +++ b/svrt_generator.cc @@ -0,0 +1,166 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include +#include +#include +#include +#include + +using namespace std; + +#include "random.h" + +#include "vision_problem_1.h" +#include "vision_problem_2.h" +#include "vision_problem_3.h" +#include "vision_problem_4.h" +#include "vision_problem_5.h" +#include "vision_problem_6.h" +#include "vision_problem_7.h" +#include "vision_problem_8.h" +#include "vision_problem_9.h" +#include "vision_problem_10.h" +#include "vision_problem_11.h" +#include "vision_problem_12.h" +#include "vision_problem_13.h" +#include "vision_problem_14.h" +#include "vision_problem_15.h" +#include "vision_problem_16.h" +#include "vision_problem_17.h" +#include "vision_problem_18.h" +#include "vision_problem_19.h" +#include "vision_problem_20.h" +#include "vision_problem_21.h" +#include "vision_problem_22.h" +#include "vision_problem_23.h" + +#define NB_PROBLEMS 23 + +VignetteGenerator *new_generator(int nb) { + VignetteGenerator *generator; + + switch(nb) { + case 1: + generator = new VisionProblem_1(); + break; + case 2: + generator = new VisionProblem_2(); + break; + case 3: + generator = new VisionProblem_3(); + break; + case 4: + generator = new VisionProblem_4(); + break; + case 5: + generator = new VisionProblem_5(); + break; + case 6: + generator = new VisionProblem_6(); + break; + case 7: + generator = new VisionProblem_7(); + break; + case 8: + generator = new VisionProblem_8(); + break; + case 9: + generator = new VisionProblem_9(); + break; + case 10: + generator = new VisionProblem_10(); + break; + case 11: + generator = new VisionProblem_11(); + break; + case 12: + generator = new VisionProblem_12(); + break; + case 13: + generator = new VisionProblem_13(); + break; + case 14: + generator = new VisionProblem_14(); + break; + case 15: + generator = new VisionProblem_15(); + break; + case 16: + generator = new VisionProblem_16(); + break; + case 17: + generator = new VisionProblem_17(); + break; + case 18: + generator = new VisionProblem_18(); + break; + case 19: + generator = new VisionProblem_19(); + break; + case 20: + generator = new VisionProblem_20(); + break; + case 21: + generator = new VisionProblem_21(); + break; + case 22: + generator = new VisionProblem_22(); + break; + case 23: + generator = new VisionProblem_23(); + break; + default: + cerr << "Can not find problem " + << nb + << endl; + abort(); + } + + generator->precompute(); + + return generator; +} + +extern "C" { + + struct VignetteSet { + int n_problem; + int nb_vignettes; + int width; + int height; + unsigned char *data; + }; + + void svrt_generate_vignettes(int n_problem, int nb_vignettes, VignetteSet *result) { + VignetteGenerator *vg = new_generator(n_problem); + result->n_problem = n_problem; + result->nb_vignettes = nb_vignettes; + result->width = Vignette::width; + result->height = Vignette::height; + result->data = (unsigned char *) malloc(sizeof(unsigned char) * result->nb_vignettes * result->width * result->height); + delete vg; + } + +} diff --git a/svrt_generator.h b/svrt_generator.h new file mode 100644 index 0000000..bdfe5c1 --- /dev/null +++ b/svrt_generator.h @@ -0,0 +1,42 @@ + +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct VignetteSet { + int n_problem; + int nb_vignettes; + int width; + int height; + unsigned char *data; +}; + +void svrt_generate_vignettes(int n_problem, int nb_vignettes, struct VignetteSet *result); + +#ifdef __cplusplus +} +#endif diff --git a/test-svrt.py b/test-svrt.py new file mode 100755 index 0000000..92fc554 --- /dev/null +++ b/test-svrt.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +# svrt is the ``Synthetic Visual Reasoning Test'', an image +# generator for evaluating classification performance of machine +# learning systems, humans and primates. +# +# Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/ +# Written by Francois Fleuret +# +# This file is part of svrt. +# +# svrt is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# svrt is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with selector. If not, see . + +import time + +import torch + +from torch import optim +from torch import FloatTensor as Tensor +from torch.autograd import Variable +from torch import nn +from torch.nn import functional as fn +from torchvision import datasets, transforms, utils + +from _ext import svrt + +train_set = svrt.generate_vignettes(12, 1234) + +print(str(type(train_set)), train_set.size()) diff --git a/vignette.cc b/vignette.cc new file mode 100644 index 0000000..9e615e4 --- /dev/null +++ b/vignette.cc @@ -0,0 +1,205 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vignette.h" + +void Vignette::clear() { + for(int k = 0; k < width * height; k++) { + content[k] = 255; +#ifdef KEEP_PART_PRESENCE + part_presence[k] = 0; +#endif + } +} + +void Vignette::fill(int x, int y, int v) { + if(x >= 0 && x < Vignette::width && y >= 0 && y < Vignette::height && + content[x + Vignette::width * y] == 255) { + content[x + Vignette::width * y] = v; + fill(x + 1, y , v); + fill(x - 1, y , v); + fill(x , y + 1, v); + fill(x , y - 1, v); + } +} + +void Vignette::switch_values(int v1, int v2) { + for(int k = 0; k < Vignette::height * Vignette::width; k++) { + if(content[k] == v1) { + content[k] = v2; + } else if(content[k] == v2) { + content[k] = v1; + } + } +} + +void Vignette::replace_value(int from, int to) { + for(int k = 0; k < Vignette::height * Vignette::width; k++) { + if(content[k] == from) { + content[k] = to; + } + } +} + +void Vignette::superpose(Vignette *infront, Vignette *inback) { + for(int k = 0; k < Vignette::height * Vignette::width; k++) { + if(infront->content[k] < 255) { + content[k] = infront->content[k]; + } else { + content[k] = inback->content[k]; + } + } +} + +int Vignette::intersection(Vignette *v) { + int n = 0; + for(int k = 0; k < Vignette::height * Vignette::width; k++) { + if(content[k] < 255 && v->content[k] < 255) { + n++; + } + } + return n; +} + +void Vignette::grow() { + int tmp[Vignette::width * Vignette::height]; + for(int k = 0; k < Vignette::height * Vignette::width; k++) { + tmp[k] = content[k]; + } + int k; + for(int y = 1; y < Vignette::height - 1; y++) { + for(int x = 1; x < Vignette::width - 1; x++) { + k = x + Vignette::width * y; + content[k] = min(tmp[k], + min(min(tmp[k - Vignette::width], tmp[k - 1]), + min(tmp[k + 1], tmp[k + Vignette::width]))); + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vignette.h b/vignette.h new file mode 100644 index 0000000..81b7898 --- /dev/null +++ b/vignette.h @@ -0,0 +1,54 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VIGNETTE_H +#define VIGNETTE_H + +#include "misc.h" + +#define KEEP_PART_PRESENCE + +class Vignette { +public: + static const int width = 128; + static const int height = width; + static const int nb_grayscales = 256; + + int content[width * height]; +#ifdef KEEP_PART_PRESENCE + unsigned int part_presence[width * height]; +#endif + + void clear(); + + void fill(int x, int y, int v); + void switch_values(int c1, int c2); + void replace_value(int from, int to); + void superpose(Vignette *infront, Vignette *inback); + int intersection(Vignette *v); + void grow(); + +}; + +#endif diff --git a/vignette_generator.cc b/vignette_generator.cc new file mode 100644 index 0000000..417fb22 --- /dev/null +++ b/vignette_generator.cc @@ -0,0 +1,29 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vignette_generator.h" + +VignetteGenerator::~VignetteGenerator() { } + +void VignetteGenerator::precompute() { } diff --git a/vignette_generator.h b/vignette_generator.h new file mode 100644 index 0000000..c02d7df --- /dev/null +++ b/vignette_generator.h @@ -0,0 +1,44 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VIGNETTE_GENERATOR_H +#define VIGNETTE_GENERATOR_H + +#include "misc.h" +#include "vignette.h" + +class VignetteGenerator { +public: + // We need a virtual destructor since we have virtual methods + virtual ~VignetteGenerator(); + + // Some generators need to do pre-computations that can not be put + // in the constructor + virtual void precompute(); + + // Generate a vignette + virtual void generate(int label, Vignette *vignette) = 0; +}; + +#endif diff --git a/vision_problem_1.cc b/vision_problem_1.cc new file mode 100644 index 0000000..73e656d --- /dev/null +++ b/vision_problem_1.cc @@ -0,0 +1,75 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_1.h" +#include "shape.h" + +VisionProblem_1::VisionProblem_1() { } + +void VisionProblem_1::generate(int label, Vignette *vignette) { + int nb_shapes = 2; + int xs[nb_shapes], ys[nb_shapes]; + scalar_t scales[nb_shapes], angles[nb_shapes]; + Shape shapes[nb_shapes]; + + int error; + do { + + scalar_t max_scale = -1; + + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * Vignette::width); + ys[n] = int(random_uniform_0_1() * Vignette::height); + + scales[n] = 2.5; + + if(n == 0 || scales[n] > max_scale) max_scale = scales[n]; + + angles[n] = 0; + } + + for(int n = 0; n < nb_shapes; n++) { + if(n == 0 || label == 0) { + shapes[n].randomize(max_scale * part_size / 2, max_scale * hole_size/2); + } else { + shapes[n].copy(&shapes[0]); + } + } + + for(int n = 0; n < nb_shapes; n++) { + shapes[n].scale(scales[n] / max_scale); + shapes[n].rotate(angles[n]); + } + + vignette->clear(); + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + error |= shapes[n].overwrites(vignette, xs[n], ys[n]); + if(!error) { + shapes[n].draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_1.h b/vision_problem_1.h new file mode 100644 index 0000000..afdf97a --- /dev/null +++ b/vision_problem_1.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_1_H +#define VISION_PROBLEM_1_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_1 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_1(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_10.cc b/vision_problem_10.cc new file mode 100644 index 0000000..adb6a4a --- /dev/null +++ b/vision_problem_10.cc @@ -0,0 +1,70 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_10.h" +#include "shape.h" + +VisionProblem_10::VisionProblem_10() { } + +void VisionProblem_10::generate(int label, Vignette *vignette) { + int nb_shapes = 4; + int xs[nb_shapes], ys[nb_shapes]; + + int error; + do { + do { + if(label == 1) { + scalar_t alpha = random_uniform_0_1() * 2 * M_PI; + scalar_t radius = random_uniform_0_1() * Vignette::width / 2; + scalar_t xc = random_uniform_0_1() * Vignette::width; + scalar_t yc = random_uniform_0_1() * Vignette::height; + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(xc + part_size/2 + + radius * sin(alpha + n * 2 * M_PI / scalar_t(nb_shapes))); + ys[n] = int(yc + part_size/2 + + radius * cos(alpha + n * 2 * M_PI / scalar_t(nb_shapes))); + } + } else { + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * Vignette::width); + ys[n] = int(random_uniform_0_1() * Vignette::height); + } + } + } while(cluttered_shapes(part_size, nb_shapes, xs, ys)); + + vignette->clear(); + + Shape shape; + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(n == 0) { + shape.randomize(part_size / 2, part_hole_size / 2); + } + error |= shape.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape.draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_10.h b/vision_problem_10.h new file mode 100644 index 0000000..e9b3baf --- /dev/null +++ b/vision_problem_10.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_10_H +#define VISION_PROBLEM_10_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_10 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int part_hole_size = Vignette::width / 64; +public: + VisionProblem_10(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_11.cc b/vision_problem_11.cc new file mode 100644 index 0000000..89ecdfc --- /dev/null +++ b/vision_problem_11.cc @@ -0,0 +1,97 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_11.h" +#include "shape.h" + +VisionProblem_11::VisionProblem_11() { } + +void VisionProblem_11::generate(int label, Vignette *vignette) { + int nb_shapes; + int xs, ys, i = 0, pxs, pys; + const int dist_min = Vignette::width/12; + int nb_attempts, max_nb_attempts = 100; + + Vignette mask, tmp; + + nb_shapes = 2; + + do { + nb_attempts = 0; + + mask.clear(); + vignette->clear(); + + pxs = 0; pys = 0; + + for(int s = 0; nb_attempts < max_nb_attempts && s < nb_shapes; s++) { + Shape shape; + + do { + tmp.clear(); + + do { + + if(s == 0) { + shape.randomize(big_part_size / 2, big_part_hole_size / 2); + } else { + shape.randomize(small_part_size / 2, small_part_hole_size / 2); + } + + if(nb_shapes == 2 || s == 0 || label == 0) { + xs = int(random_uniform_0_1() * Vignette::width); + ys = int(random_uniform_0_1() * Vignette::height); + } else { + xs = pxs + int(4 * (random_uniform_0_1() - 0.5) * small_part_hole_size); + ys = pys + int(4 * (random_uniform_0_1() - 0.5) * small_part_hole_size); + } + nb_attempts++; + + } while(nb_attempts < max_nb_attempts && + shape.overwrites(&tmp, xs, ys)); + + if(nb_attempts < max_nb_attempts) { + shape.draw(s, &tmp, xs, ys); + tmp.fill(xs, ys, 128); + i = tmp.intersection(&mask); + } + + nb_attempts++; + } while(nb_attempts < max_nb_attempts && + s > 0 && + ((label == 0 && i > 0) || (label == 1 && (i < 1 || i > 4)))); + + if(nb_attempts < max_nb_attempts) { + shape.draw(s, vignette, xs, ys); + pxs = xs; pys = ys; + + if(label == 0) { + for(int k = 0; k < dist_min; k++) tmp.grow(); + } + + mask.superpose(&mask, &tmp); + } + } + } while(nb_attempts >= max_nb_attempts); +} diff --git a/vision_problem_11.h b/vision_problem_11.h new file mode 100644 index 0000000..a8cf1ef --- /dev/null +++ b/vision_problem_11.h @@ -0,0 +1,41 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_11_H +#define VISION_PROBLEM_11_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_11 : public VignetteGenerator { + static const int small_part_size = Vignette::width / 3; + static const int small_part_hole_size = Vignette::width / 9; + static const int big_part_size = (Vignette::width * 3)/4; + static const int big_part_hole_size = Vignette::width / 4; +public: + VisionProblem_11(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_12.cc b/vision_problem_12.cc new file mode 100644 index 0000000..3348b4e --- /dev/null +++ b/vision_problem_12.cc @@ -0,0 +1,81 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_12.h" +#include "shape.h" + +VisionProblem_12::VisionProblem_12() { } + +void VisionProblem_12::generate(int label, Vignette *vignette) { + int nb_shapes = 3; + scalar_t alpha, beta, gamma; + int xs, ys; + Shape shape; + + int error; + + do { + scalar_t xc, yc, radius; + xc = (random_uniform_0_1() * 0.5 + 0.25) * Vignette::width; + yc = (random_uniform_0_1() * 0.5 + 0.25) * Vignette::height; + radius = (random_uniform_0_1() * 0.5 + 0.1) * Vignette::width; + alpha = random_uniform_0_1() * 2 * M_PI; + beta = (random_uniform_0_1() * 0.4 + 0.1) * M_PI; + + vignette->clear(); + error = 0; + + for(int n = 0; n < nb_shapes; n++) { + if(label) { + if(n == 0) + gamma = alpha + M_PI - beta/2; + else if(n == 1) + gamma = alpha + M_PI + beta/2; + else + gamma = alpha; + } else { + if(n == 0) + gamma = alpha + M_PI - beta/2; + else if(n == 1) + gamma = alpha; + else + gamma = alpha + M_PI + beta/2; + } + + if(n < 2) { + shape.randomize(small_part_size, small_part_hole_size); + } else { + shape.randomize(big_part_size, big_part_hole_size); + } + + xs = int(xc + radius * cos(gamma)); + ys = int(yc + radius * sin(gamma)); + + error |= shape.overwrites(vignette, xs, ys); + if(!error) { + shape.draw(n, vignette, xs, ys); + } + } + } while(error); +} diff --git a/vision_problem_12.h b/vision_problem_12.h new file mode 100644 index 0000000..3d17d83 --- /dev/null +++ b/vision_problem_12.h @@ -0,0 +1,41 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_12_H +#define VISION_PROBLEM_12_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_12 : public VignetteGenerator { + static const int small_part_size = Vignette::width / 12; + static const int small_part_hole_size = Vignette::width / 24; + static const int big_part_size = Vignette::width / 6; + static const int big_part_hole_size = Vignette::width / 12; +public: + VisionProblem_12(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_13.cc b/vision_problem_13.cc new file mode 100644 index 0000000..7193a3a --- /dev/null +++ b/vision_problem_13.cc @@ -0,0 +1,110 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_13.h" +#include "shape.h" + +VisionProblem_13::VisionProblem_13() { } + +void VisionProblem_13::generate(int label, Vignette *vignette) { + Shape big_shape, small_shape; + int big_xs1, big_ys1, small_xs1, small_ys1; + int big_xs2, big_ys2, small_xs2, small_ys2; + int translated_small_xs = 0, translated_small_ys = 0; + Vignette tmp; + const int dist_min = Vignette::width/4; + int nb_attempts; + const int max_nb_attempts = 100; + + do { + nb_attempts = 0; + do { + + vignette->clear(); + + big_shape.randomize(big_part_size / 2, big_part_hole_size / 2); + + tmp.clear(); + do { + big_xs1 = int(random_uniform_0_1() * Vignette::width); + big_ys1 = int(random_uniform_0_1() * Vignette::height); + nb_attempts++; + } while(nb_attempts < max_nb_attempts && + big_shape.overwrites(vignette, big_xs1, big_ys1)); + + if(nb_attempts < max_nb_attempts) { + big_shape.draw(0, vignette, big_xs1, big_ys1); + big_shape.draw(0, &tmp, big_xs1, big_ys1); + for(int k = 0; k < dist_min; k++) tmp.grow(); + } + + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + small_xs1 = int(random_uniform_0_1() * Vignette::width); + small_ys1 = int(random_uniform_0_1() * Vignette::height); + nb_attempts++; + } while(nb_attempts < max_nb_attempts && + (!small_shape.overwrites(&tmp, small_xs1, small_ys1) || + small_shape.overwrites(vignette, small_xs1, small_ys1))); + + if(nb_attempts < max_nb_attempts) { + small_shape.draw(1, vignette, small_xs1, small_ys1); + } + + tmp.clear(); + do { + big_xs2 = int(random_uniform_0_1() * Vignette::width); + big_ys2 = int(random_uniform_0_1() * Vignette::height); + nb_attempts++; + } while(nb_attempts < max_nb_attempts && + big_shape.overwrites(vignette, big_xs2, big_ys2)); + if(nb_attempts < max_nb_attempts) { + big_shape.draw(2, vignette, big_xs2, big_ys2); + big_shape.draw(0, &tmp, big_xs2, big_ys2); + for(int k = 0; k < dist_min; k++) tmp.grow(); + + translated_small_xs = small_xs1 + (big_xs2 - big_xs1); + translated_small_ys = small_ys1 + (big_ys2 - big_ys1); + } + } while(nb_attempts < max_nb_attempts && + small_shape.overwrites(vignette, + translated_small_xs, + translated_small_ys)); + + if(label) { + small_xs2 = translated_small_xs; + small_ys2 = translated_small_ys; + } else { + do { + small_xs2 = int(random_uniform_0_1() * Vignette::width); + small_ys2 = int(random_uniform_0_1() * Vignette::height); + nb_attempts++; + } while(nb_attempts < max_nb_attempts && + (sq(small_xs2 - translated_small_xs) + sq(small_ys2 - translated_small_ys) < sq(dist_min) || + !small_shape.overwrites(&tmp, small_xs2, small_ys2) || + small_shape.overwrites(vignette, small_xs2, small_ys2))); + } + } while(nb_attempts >= max_nb_attempts); + small_shape.draw(3, vignette, small_xs2, small_ys2); +} diff --git a/vision_problem_13.h b/vision_problem_13.h new file mode 100644 index 0000000..98c49f8 --- /dev/null +++ b/vision_problem_13.h @@ -0,0 +1,41 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_13_H +#define VISION_PROBLEM_13_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_13 : public VignetteGenerator { + static const int small_part_size = Vignette::width / 6; + static const int small_part_hole_size = Vignette::width / 12; + static const int big_part_size = Vignette::width / 2; + static const int big_part_hole_size = Vignette::width / 4; +public: + VisionProblem_13(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_14.cc b/vision_problem_14.cc new file mode 100644 index 0000000..a89804b --- /dev/null +++ b/vision_problem_14.cc @@ -0,0 +1,93 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_14.h" +#include "shape.h" + +VisionProblem_14::VisionProblem_14() { } + +void VisionProblem_14::sample_shapes_positions_aligned(int nb_shapes, int *xs, int *ys) { + for(int n = 0; n < nb_shapes - 1; n++) { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2; + ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2; + } + scalar_t alpha = random_uniform_0_1(); + xs[nb_shapes - 1] = int(alpha * xs[0] + (1 - alpha) * xs[1]); + ys[nb_shapes - 1] = int(alpha * ys[0] + (1 - alpha) * ys[1]); +} + +void VisionProblem_14::sample_shapes_positions_uniformly(int nb_shapes, int *xs, int *ys) { + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2; + ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2; + } +} + +int VisionProblem_14::there_is_an_alignment(scalar_t dist_threshold, int nb_shapes, int *xs, int *ys) { + for(int a = 0; a < nb_shapes; a++) { + for(int b = 0; b < nb_shapes; b++) { + for(int c = 0; c < b; c++) { + if(a != b && a != c) { + if(point_in_band(scalar_t(xs[a]), scalar_t(ys[a]), + scalar_t(xs[b]), scalar_t(ys[b]), + scalar_t(xs[c]), scalar_t(ys[c]), + dist_threshold)) return 1; + } + } + } + } + return 0; +} + + +void VisionProblem_14::generate(int label, Vignette *vignette) { + int nb_shapes = 3; + int xs[nb_shapes], ys[nb_shapes]; + int error; + + do { + if(label) { + sample_shapes_positions_aligned(nb_shapes, xs, ys); + } else { + do { + sample_shapes_positions_uniformly(nb_shapes, xs, ys); + } while(there_is_an_alignment(Vignette::width/20, 3, xs, ys)); + } + + vignette->clear(); + + Shape shape; + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(n == 0) { + shape.randomize(part_size/2, hole_size/2); + } + error |= shape.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape.draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_14.h b/vision_problem_14.h new file mode 100644 index 0000000..c1598ff --- /dev/null +++ b/vision_problem_14.h @@ -0,0 +1,42 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_14_H +#define VISION_PROBLEM_14_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_14 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; + void sample_shapes_positions_aligned(int nb_shapes, int *xs, int *ys); + void sample_shapes_positions_uniformly(int nb_shapes, int *xs, int *ys); + int there_is_an_alignment(scalar_t dist_threshold, int nb_shapes, + int *xs, int *ys); +public: + VisionProblem_14(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_15.cc b/vision_problem_15.cc new file mode 100644 index 0000000..c09d75f --- /dev/null +++ b/vision_problem_15.cc @@ -0,0 +1,63 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_15.h" +#include "shape.h" + +VisionProblem_15::VisionProblem_15() { } + +void VisionProblem_15::generate(int label, Vignette *vignette) { + int nb_shapes = 4; + int xs[nb_shapes], ys[nb_shapes]; + + int error; + do { + do { + scalar_t alpha = random_uniform_0_1() * 2 * M_PI; + scalar_t radius = random_uniform_0_1() * Vignette::width / 2; + scalar_t xc = random_uniform_0_1() * Vignette::width; + scalar_t yc = random_uniform_0_1() * Vignette::height; + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(xc + part_size/2 + + radius * sin(alpha + n * 2 * M_PI / scalar_t(nb_shapes))); + ys[n] = int(yc + part_size/2 + + radius * cos(alpha + n * 2 * M_PI / scalar_t(nb_shapes))); + } + } while(cluttered_shapes(part_size, nb_shapes, xs, ys)); + + vignette->clear(); + + Shape shape; + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(n == 0 || label == 0) { + shape.randomize(part_size / 2, part_hole_size / 2); + } + error |= shape.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape.draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_15.h b/vision_problem_15.h new file mode 100644 index 0000000..b842dbd --- /dev/null +++ b/vision_problem_15.h @@ -0,0 +1,38 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_15_H +#define VISION_PROBLEM_15_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_15 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int part_hole_size = Vignette::width / 64; +public: + VisionProblem_15(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_16.cc b/vision_problem_16.cc new file mode 100644 index 0000000..c61d075 --- /dev/null +++ b/vision_problem_16.cc @@ -0,0 +1,66 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_16.h" +#include "shape.h" + +VisionProblem_16::VisionProblem_16() { } + +void VisionProblem_16::generate(int label, Vignette *vignette) { + int error; + + int nb_shapes = 6; + int xs[nb_shapes], ys[nb_shapes]; + Shape shape1, shape2; + shape1.randomize(part_size / 2, hole_size / 2); + shape2.copy(&shape1); + + if(label == 1) { + shape2.symmetrize(0.0, 1.0); + } + + do { + vignette->clear(); + error = 0; + + // First half of the shapes are random + for(int n = 0; n < nb_shapes/2; n++) { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2; + ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2; + error |= shape1.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape1.draw(n, vignette, xs[n], ys[n]); + } + } + + for(int n = nb_shapes/2; n < nb_shapes; n++) { + xs[n] = Vignette::width - xs[n - nb_shapes/2]; + ys[n] = ys[n - nb_shapes/2]; + error |= shape2.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape2.draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_16.h b/vision_problem_16.h new file mode 100644 index 0000000..1799c31 --- /dev/null +++ b/vision_problem_16.h @@ -0,0 +1,38 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_16_H +#define VISION_PROBLEM_16_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_16 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_16(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_17.cc b/vision_problem_17.cc new file mode 100644 index 0000000..9609764 --- /dev/null +++ b/vision_problem_17.cc @@ -0,0 +1,97 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_17.h" +#include "shape.h" + +VisionProblem_17::VisionProblem_17() { } + +void VisionProblem_17::generate(int label, Vignette *vignette) { + const int nb_shapes = 4; + int xs[nb_shapes], ys[nb_shapes]; + int shape_number[nb_shapes]; + + ASSERT(nb_shapes == 4); + + int too_ambiguous; + + int error; + + do { + Shape shape1, shape2; + shape1.randomize(part_size/2, hole_size/2); + shape2.randomize(part_size/2, hole_size/2); + + ////////////////////////////////////////////////////////////////////// + + do { + for(int n = 0; n < nb_shapes; n++) { + if(n < nb_shapes - 1) { + shape_number[n] = 0; + } else { + shape_number[n] = 1; + } + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size)) + part_size/2; + ys[n] = int(random_uniform_0_1() * (Vignette::width - part_size)) + part_size/2; + } + + scalar_t a = scalar_t(xs[1] - xs[0]), b = scalar_t(ys[1] - ys[0]); + scalar_t c = scalar_t(xs[2] - xs[1]), d = scalar_t(ys[2] - ys[1]); + scalar_t det = a * d - b * c; + scalar_t u = scalar_t(xs[1] * xs[1] - xs[0] * xs[0] + ys[1] * ys[1] - ys[0] * ys[0]); + scalar_t v = scalar_t(xs[2] * xs[2] - xs[1] * xs[1] + ys[2] * ys[2] - ys[1] * ys[1]); + scalar_t xc = 1/(2 * det) *( d * u - b * v); + scalar_t yc = 1/(2 * det) *(- c * u + a * v); + + if(label == 1) { + xs[nb_shapes - 1] = int(xc); + ys[nb_shapes - 1] = int(yc); + too_ambiguous = 0; + } else { + too_ambiguous = sqrt(sq(scalar_t(xs[nb_shapes - 1]) - xc) + + sq(scalar_t(ys[nb_shapes - 1]) - yc)) < scalar_t(part_size); + } + } while(too_ambiguous || + cluttered_shapes(part_size, nb_shapes, xs, ys)); + + ////////////////////////////////////////////////////////////////////// + + vignette->clear(); + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(shape_number[n] == 0) { + error |= shape1.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape1.draw(n, vignette, xs[n], ys[n]); + } + } else { + error |= shape2.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape2.draw(n, vignette, xs[n], ys[n]); + } + } + } + } while(error); +} diff --git a/vision_problem_17.h b/vision_problem_17.h new file mode 100644 index 0000000..f614126 --- /dev/null +++ b/vision_problem_17.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_17_H +#define VISION_PROBLEM_17_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_17 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_17(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_18.cc b/vision_problem_18.cc new file mode 100644 index 0000000..cffe85c --- /dev/null +++ b/vision_problem_18.cc @@ -0,0 +1,67 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_18.h" +#include "shape.h" + +VisionProblem_18::VisionProblem_18() { } + +void VisionProblem_18::generate(int label, Vignette *vignette) { + int error; + + int nb_shapes = 6; + int xs[nb_shapes], ys[nb_shapes]; + Shape shape1, shape2; + shape1.randomize(part_size / 2, hole_size / 2); + shape2.copy(&shape1); + + do { + vignette->clear(); + error = 0; + + // First half of the shapes are random + for(int n = 0; n < nb_shapes/2; n++) { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2; + ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2; + error |= shape1.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape1.draw(n, vignette, xs[n], ys[n]); + } + } + + for(int n = nb_shapes/2; n < nb_shapes; n++) { + if(label == 1) { + xs[n] = Vignette::width - xs[n - nb_shapes/2]; + ys[n] = ys[n - nb_shapes/2]; + } else { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2; + ys[n] = ys[n - nb_shapes/2]; + } + error |= shape2.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape2.draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_18.h b/vision_problem_18.h new file mode 100644 index 0000000..b8c4dca --- /dev/null +++ b/vision_problem_18.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_18_H +#define VISION_PROBLEM_18_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_18 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_18(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_19.cc b/vision_problem_19.cc new file mode 100644 index 0000000..a947a09 --- /dev/null +++ b/vision_problem_19.cc @@ -0,0 +1,75 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_19.h" +#include "shape.h" + +VisionProblem_19::VisionProblem_19() { } + +void VisionProblem_19::generate(int label, Vignette *vignette) { + int nb_shapes = 2; + int xs[nb_shapes], ys[nb_shapes]; + scalar_t scales[nb_shapes], angles[nb_shapes]; + Shape shapes[nb_shapes]; + + int error; + do { + + scalar_t max_scale = -1; + + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * Vignette::width); + ys[n] = int(random_uniform_0_1() * Vignette::height); + + scales[n] = 1.0 + 3.0 * random_uniform_0_1(); + + if(n == 0 || scales[n] > max_scale) max_scale = scales[n]; + + angles[n] = 0; + } + + for(int n = 0; n < nb_shapes; n++) { + if(n == 0 || label == 0) { + shapes[n].randomize(max_scale * part_size / 2, max_scale * hole_size/2); + } else { + shapes[n].copy(&shapes[0]); + } + } + + for(int n = 0; n < nb_shapes; n++) { + shapes[n].scale(scales[n] / max_scale); + shapes[n].rotate(angles[n]); + } + + vignette->clear(); + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + error |= shapes[n].overwrites(vignette, xs[n], ys[n]); + if(!error) { + shapes[n].draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_19.h b/vision_problem_19.h new file mode 100644 index 0000000..794b28e --- /dev/null +++ b/vision_problem_19.h @@ -0,0 +1,38 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_19_H +#define VISION_PROBLEM_19_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_19 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_19(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_2.cc b/vision_problem_2.cc new file mode 100644 index 0000000..142ed12 --- /dev/null +++ b/vision_problem_2.cc @@ -0,0 +1,80 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_2.h" +#include "shape.h" + +VisionProblem_2::VisionProblem_2() { } + +void VisionProblem_2::generate(int label, Vignette *vignette) { + int x_big, y_big, x_small, y_small; + Shape big_shape, small_shape; + Vignette mask; + int nb_attempts, max_nb_attempts = 10; + int dist_min = Vignette::width/8; + + do { + vignette->clear(); + mask.clear(); + + big_shape.randomize(big_part_size / 2, big_part_hole_size / 2); + + do { + x_big = int(random_uniform_0_1() * Vignette::width); + y_big = int(random_uniform_0_1() * Vignette::height); + } while(big_shape.overwrites(vignette, x_big, y_big)); + + // The mask will encode either a thin area the small shape should + // intersect with (class 1) or a thick one it should not (class 0) + + big_shape.draw(0, &mask, x_big, y_big); + + if(label) { + mask.grow(); + } else { + for(int k = 0; k < dist_min; k++) { + mask.grow(); + } + } + + big_shape.draw(0, vignette, x_big, y_big); + vignette->fill(x_big, y_big, 128); + vignette->switch_values(128, 255); + + nb_attempts = 0; + do { + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + x_small = x_big + int((random_uniform_0_1() - 0.5) * big_part_size); + y_small = y_big + int((random_uniform_0_1() - 0.5) * big_part_size); + } while(small_shape.overwrites(vignette, x_small, y_small)); // || + nb_attempts++; + } while(nb_attempts < max_nb_attempts && + ((label && !small_shape.overwrites(&mask, x_small, y_small)) || + (!label && small_shape.overwrites(&mask, x_small, y_small)))); + + vignette->replace_value(128, 255); + small_shape.draw(1, vignette, x_small, y_small); + } while(nb_attempts >= max_nb_attempts); +} diff --git a/vision_problem_2.h b/vision_problem_2.h new file mode 100644 index 0000000..a1239f0 --- /dev/null +++ b/vision_problem_2.h @@ -0,0 +1,42 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_2_H +#define VISION_PROBLEM_2_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_2 : public VignetteGenerator { + static const int small_part_size = Vignette::width/6; + static const int small_part_hole_size = Vignette::width/64; + static const int big_part_size = (Vignette::width * 3)/4; + static const int big_part_hole_size = Vignette::width / 3; + +public: + VisionProblem_2(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_20.cc b/vision_problem_20.cc new file mode 100644 index 0000000..557b113 --- /dev/null +++ b/vision_problem_20.cc @@ -0,0 +1,55 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_20.h" +#include "shape.h" + +VisionProblem_20::VisionProblem_20() { } + + +void VisionProblem_20::generate(int label, Vignette *vignette) { + int nb_shapes = 2; + int xs[nb_shapes], ys[nb_shapes]; + Shape shapes[nb_shapes]; + + int error; + do{ + vignette->clear(); + error = 0; + for(int n = 0; !error && n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * Vignette::width); + ys[n] = int(random_uniform_0_1() * Vignette::height); + if(!label || n == 0) { + shapes[n].randomize(part_size / 2, part_hole_size / 2); + } else { + shapes[n].copy(&shapes[0]); + shapes[n].symmetrize(ys[n] - ys[0], - xs[n] + xs[0]); + } + error |= shapes[n].overwrites(vignette, xs[n], ys[n]); + if(!error) { + shapes[n].draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_20.h b/vision_problem_20.h new file mode 100644 index 0000000..a1f1b7a --- /dev/null +++ b/vision_problem_20.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_20_H +#define VISION_PROBLEM_20_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_20 : public VignetteGenerator { + static const int part_size = Vignette::width / 4; + static const int part_hole_size = Vignette::width / 32; +public: + VisionProblem_20(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_21.cc b/vision_problem_21.cc new file mode 100644 index 0000000..e92d6f9 --- /dev/null +++ b/vision_problem_21.cc @@ -0,0 +1,75 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_21.h" +#include "shape.h" + +VisionProblem_21::VisionProblem_21() { } + +void VisionProblem_21::generate(int label, Vignette *vignette) { + int nb_shapes = 2; + int xs[nb_shapes], ys[nb_shapes]; + scalar_t scales[nb_shapes], angles[nb_shapes]; + Shape shapes[nb_shapes]; + + int error; + do { + + scalar_t max_scale = -1; + + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * Vignette::width); + ys[n] = int(random_uniform_0_1() * Vignette::height); + + scales[n] = 1.0 + 3.0 * random_uniform_0_1(); + + if(n == 0 || scales[n] > max_scale) max_scale = scales[n]; + + angles[n] = random_uniform_0_1() * 2 * M_PI; + } + + for(int n = 0; n < nb_shapes; n++) { + if(n == 0 || label == 0) { + shapes[n].randomize(max_scale * part_size / 2, max_scale * hole_size/2); + } else { + shapes[n].copy(&shapes[0]); + } + } + + for(int n = 0; n < nb_shapes; n++) { + shapes[n].scale(scales[n] / max_scale); + shapes[n].rotate(angles[n]); + } + + vignette->clear(); + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + error |= shapes[n].overwrites(vignette, xs[n], ys[n]); + if(!error) { + shapes[n].draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_21.h b/vision_problem_21.h new file mode 100644 index 0000000..3fa825a --- /dev/null +++ b/vision_problem_21.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_21_H +#define VISION_PROBLEM_21_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_21 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_21(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_22.cc b/vision_problem_22.cc new file mode 100644 index 0000000..5d6acda --- /dev/null +++ b/vision_problem_22.cc @@ -0,0 +1,63 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_22.h" +#include "shape.h" + +VisionProblem_22::VisionProblem_22() { } + +void VisionProblem_22::sample_shapes_positions_aligned(int nb_shapes, int *xs, int *ys) { + for(int n = 0; n < nb_shapes - 1; n++) { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2; + ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2; + } + scalar_t alpha = random_uniform_0_1(); + xs[nb_shapes - 1] = int(alpha * xs[0] + (1 - alpha) * xs[1]); + ys[nb_shapes - 1] = int(alpha * ys[0] + (1 - alpha) * ys[1]); +} + +void VisionProblem_22::generate(int label, Vignette *vignette) { + int nb_shapes = 3; + int xs[nb_shapes], ys[nb_shapes]; + int error; + + do { + sample_shapes_positions_aligned(nb_shapes, xs, ys); + + vignette->clear(); + + Shape shape; + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(n == 0 || label == 0) { + shape.randomize(part_size/2, hole_size/2); + } + error |= shape.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape.draw(n, vignette, xs[n], ys[n]); + } + } + } while(error); +} diff --git a/vision_problem_22.h b/vision_problem_22.h new file mode 100644 index 0000000..f7cbdbe --- /dev/null +++ b/vision_problem_22.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_22_H +#define VISION_PROBLEM_22_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_22 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; + void sample_shapes_positions_aligned(int nb_shapes, int *xs, int *ys); +public: + VisionProblem_22(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_23.cc b/vision_problem_23.cc new file mode 100644 index 0000000..023234d --- /dev/null +++ b/vision_problem_23.cc @@ -0,0 +1,125 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_23.h" +#include "shape.h" + + +VisionProblem_23::VisionProblem_23() { } + +void VisionProblem_23::generate(int label, Vignette *vignette) { + int x_big, y_big, x_small, y_small; + Shape big_shape, small_shape; + + int error; + do { + + vignette->clear(); + + error = 0; + + big_shape.randomize(big_part_size / 2, big_part_hole_size / 2); + + do { + x_big = int(random_uniform_0_1() * Vignette::width); + y_big = int(random_uniform_0_1() * Vignette::height); + } while(big_shape.overwrites(vignette, x_big, y_big)); + + if(!error) { + big_shape.draw(0, vignette, x_big, y_big); + + if(label) { + // We fill outside + vignette->fill(x_big, y_big, 128); + vignette->switch_values(128, 255); + // Find a location for a small shape inside + int nb_attempts = 0; + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + x_small = int(random_uniform_0_1() * Vignette::width); + y_small = int(random_uniform_0_1() * Vignette::height); + error = small_shape.overwrites(vignette, x_small, y_small); + nb_attempts++; + } while(error && nb_attempts < 10); + + if(!error) { + // Found it, unfill outside, fill inside and draw + vignette->replace_value(128, 255); + vignette->fill(x_big, y_big, 128); + + small_shape.draw(1, vignette, x_small, y_small); + + int nb_attempts = 0; + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + x_small = int(random_uniform_0_1() * Vignette::width); + y_small = int(random_uniform_0_1() * Vignette::height); + error = small_shape.overwrites(vignette, x_small, y_small); + nb_attempts++; + } while(error && nb_attempts < 10); + if(!error) { + // Found it, unfill and draw + vignette->replace_value(128, 255); + small_shape.draw(2, vignette, x_small, y_small); + } + } + } else { + vignette->fill(x_big, y_big, 128); + + if(random_uniform_0_1() < 0.5) { + vignette->switch_values(128, 255); + } + + int nb_attempts = 0; + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + x_small = int(random_uniform_0_1() * Vignette::width); + y_small = int(random_uniform_0_1() * Vignette::height); + error = small_shape.overwrites(vignette, x_small, y_small); + nb_attempts++; + } while(error && nb_attempts < 10); + + if(!error) { + small_shape.draw(1, vignette, x_small, y_small); + vignette->fill(x_small, y_small, 128); + int nb_attempts = 0; + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + x_small = int(random_uniform_0_1() * Vignette::width); + y_small = int(random_uniform_0_1() * Vignette::height); + error = small_shape.overwrites(vignette, x_small, y_small); + nb_attempts++; + } while(error && nb_attempts < 10); + + if(!error) { + small_shape.draw(2, vignette, x_small, y_small); + vignette->replace_value(128, 255); + } + } + } + + } + + } while(error); +} diff --git a/vision_problem_23.h b/vision_problem_23.h new file mode 100644 index 0000000..ec0665c --- /dev/null +++ b/vision_problem_23.h @@ -0,0 +1,40 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_23_H +#define VISION_PROBLEM_23_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_23 : public VignetteGenerator { + static const int small_part_size = Vignette::width/6; + static const int small_part_hole_size = Vignette::width/64; + static const int big_part_size = (Vignette::width * 3)/4; + static const int big_part_hole_size = Vignette::width / 3; +public: + VisionProblem_23(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_3.cc b/vision_problem_3.cc new file mode 100644 index 0000000..f34cd56 --- /dev/null +++ b/vision_problem_3.cc @@ -0,0 +1,102 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_3.h" +#include "shape.h" + +VisionProblem_3::VisionProblem_3() { } + +void VisionProblem_3::generate(int label, Vignette *vignette) { + int nb_shapes = 4; + Vignette avoid, tmp; + const int dist_min = Vignette::width / 8; + + int nb_attempts; + const int max_nb_attempts = 100; + + do { + avoid.clear(); + vignette->clear(); + + nb_attempts = 0; + + for(int s = 0; nb_attempts < max_nb_attempts && s < nb_shapes; s++) { + Shape shape; + + int xs, ys, i, proper_margin, proper_connection; + + do { + tmp.clear(); + do { + do { + xs = int(random_uniform_0_1() * Vignette::width); + ys = int(random_uniform_0_1() * Vignette::height); + shape.randomize(part_size, hole_size); + } while(shape.overwrites(&tmp, xs, ys)); // check not out-of-vignette + + // omg this is ugly + if(label && s == 1) { + proper_margin = 1; + } else { + proper_margin = !shape.overwrites(&avoid, xs, ys); + } + + if((label && (s == 1 || s == 3)) || (!label && (s >= 2))) { + proper_connection = shape.overwrites(vignette, xs, ys); + } else { + proper_connection = 1; + } + + nb_attempts++; + + } while(nb_attempts < max_nb_attempts && !proper_margin); + + shape.draw(s, &tmp, xs, ys); + tmp.fill(xs, ys, 128); + + if(proper_margin && proper_connection) { + if((label && (s == 1 || s == 3)) || (!label && (s >= 2))) { + i = vignette->intersection(&tmp); + proper_connection = (i > 0) && (i < 4); + } else { + proper_connection = 1; + } + } else { + proper_connection = 0; // To avoid compilation warning + } + } while(nb_attempts < max_nb_attempts && (!proper_margin || !proper_connection)); + + if(nb_attempts < max_nb_attempts) { + shape.draw(s, vignette, xs, ys); + vignette->fill(xs, ys, 128); + if((label && s < 2) || (!label && s < 1)) { + for(int k = 0; k < dist_min; k++) tmp.grow(); + avoid.superpose(&avoid, &tmp); + } + } + } + } while(nb_attempts >= max_nb_attempts); + + vignette->replace_value(128, 255); +} diff --git a/vision_problem_3.h b/vision_problem_3.h new file mode 100644 index 0000000..2df8286 --- /dev/null +++ b/vision_problem_3.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_3_H +#define VISION_PROBLEM_3_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_3 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_3(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_4.cc b/vision_problem_4.cc new file mode 100644 index 0000000..a663244 --- /dev/null +++ b/vision_problem_4.cc @@ -0,0 +1,73 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_4.h" +#include "shape.h" + +VisionProblem_4::VisionProblem_4() { } + +void VisionProblem_4::generate(int label, Vignette *vignette) { + int x_big, y_big, x_small, y_small; + Shape big_shape, small_shape; + + int error; + do { + + vignette->clear(); + + error = 0; + + big_shape.randomize(big_part_size / 2, big_part_hole_size / 2); + + do { + x_big = int(random_uniform_0_1() * Vignette::width); + y_big = int(random_uniform_0_1() * Vignette::height); + } while(big_shape.overwrites(vignette, x_big, y_big)); + + if(!error) { + big_shape.draw(0, vignette, x_big, y_big); + + vignette->fill(x_big, y_big, 128); + + if(label) { + vignette->switch_values(128, 255); + } + + int nb_attempts = 0; + do { + small_shape.randomize(small_part_size / 2, small_part_hole_size / 2); + x_small = int(random_uniform_0_1() * Vignette::width); + y_small = int(random_uniform_0_1() * Vignette::height); + error = small_shape.overwrites(vignette, x_small, y_small); + nb_attempts++; + } while(error && nb_attempts < 10); + + if(!error) { + vignette->replace_value(128, 255); + small_shape.draw(1, vignette, x_small, y_small); + } + } + + } while(error); +} diff --git a/vision_problem_4.h b/vision_problem_4.h new file mode 100644 index 0000000..a0ecf85 --- /dev/null +++ b/vision_problem_4.h @@ -0,0 +1,40 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_4_H +#define VISION_PROBLEM_4_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_4 : public VignetteGenerator { + static const int small_part_size = Vignette::width/6; + static const int small_part_hole_size = Vignette::width/64; + static const int big_part_size = (Vignette::width * 3)/4; + static const int big_part_hole_size = Vignette::width / 3; +public: + VisionProblem_4(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_5.cc b/vision_problem_5.cc new file mode 100644 index 0000000..e2c3628 --- /dev/null +++ b/vision_problem_5.cc @@ -0,0 +1,50 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_5.h" +#include "shape.h" + +VisionProblem_5::VisionProblem_5() { } + +void VisionProblem_5::generate(int label, Vignette *vignette) { + int nb_shapes; + + nb_shapes = 4; + + vignette->clear(); + Shape shape; + + for(int s = 0; s < nb_shapes; s++) { + if(label == 0 || s == 0 || s == nb_shapes/2) { + shape.randomize(part_size, part_hole_size); + } + + int xs, ys; + do { + xs = int(random_uniform_0_1() * Vignette::width); + ys = int(random_uniform_0_1() * Vignette::height); + } while(shape.overwrites(vignette, xs, ys)); + shape.draw(s, vignette, xs, ys); + } +} diff --git a/vision_problem_5.h b/vision_problem_5.h new file mode 100644 index 0000000..8c23f0d --- /dev/null +++ b/vision_problem_5.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_5_H +#define VISION_PROBLEM_5_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_5 : public VignetteGenerator { + static const int part_size = Vignette::width/6; + static const int part_hole_size = Vignette::width/64; +public: + VisionProblem_5(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_6.cc b/vision_problem_6.cc new file mode 100644 index 0000000..e48f0cb --- /dev/null +++ b/vision_problem_6.cc @@ -0,0 +1,102 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_6.h" +#include "shape.h" + +VisionProblem_6::VisionProblem_6() { } + +void VisionProblem_6::generate(int label, Vignette *vignette) { + const int nb_shapes = 4; + int xs[nb_shapes], ys[nb_shapes]; + int shape_number[nb_shapes]; + + ASSERT(nb_shapes == 4); + + int too_ambiguous; + + int error; + + do { + Shape shape1, shape2; + shape1.randomize(part_size/2, hole_size/2); + shape2.randomize(part_size/2, hole_size/2); + + scalar_t xc1, yc1, alpha1; + scalar_t xc2, yc2, alpha2; + scalar_t r; + shape_number[0] = 0; + shape_number[1] = 0; + shape_number[2] = 1; + shape_number[3] = 1; + do { + if(label == 1) { + xc1 = random_uniform_0_1() * (Vignette::width - part_size) ; + yc1 = random_uniform_0_1() * (Vignette::width - part_size) ; + alpha1 = random_uniform_0_1() * M_PI * 2; + r = random_uniform_0_1() * (Vignette::width + Vignette::height)/2; + + xc2 = random_uniform_0_1() * (Vignette::width - part_size) ; + yc2 = random_uniform_0_1() * (Vignette::width - part_size) ; + alpha2 = random_uniform_0_1() * M_PI * 2; + + xs[0] = int(xc1 + r * cos(alpha1)); + ys[0] = int(yc1 + r * sin(alpha1)); + xs[1] = int(xc1 - r * cos(alpha1)); + ys[1] = int(yc1 - r * sin(alpha1)); + xs[2] = int(xc2 + r * cos(alpha2)); + ys[2] = int(yc2 + r * sin(alpha2)); + xs[3] = int(xc2 - r * cos(alpha2)); + ys[3] = int(yc2 - r * sin(alpha2)); + too_ambiguous = 0; + } else { + for(int n = 0; n < nb_shapes; n++) { + xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size)); + ys[n] = int(random_uniform_0_1() * (Vignette::width - part_size)); + } + scalar_t d1 = sqrt(sq(xs[0] - xs[1]) + sq(ys[0] - ys[1])); + scalar_t d2 = sqrt(sq(xs[2] - xs[3]) + sq(ys[2] - ys[3])); + too_ambiguous = abs(d1 - d2) < scalar_t(part_size); + } + } while(too_ambiguous || + cluttered_shapes(part_size, nb_shapes, xs, ys)); + + vignette->clear(); + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(shape_number[n] == 0) { + error |= shape1.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape1.draw(n, vignette, xs[n], ys[n]); + } + } else { + error |= shape2.overwrites(vignette, xs[n], ys[n]); + if(!error) { + shape2.draw(n, vignette, xs[n], ys[n]); + } + } + } + } while(error); +} diff --git a/vision_problem_6.h b/vision_problem_6.h new file mode 100644 index 0000000..1cbc3fb --- /dev/null +++ b/vision_problem_6.h @@ -0,0 +1,39 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_6_H +#define VISION_PROBLEM_6_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_6 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_6(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_7.cc b/vision_problem_7.cc new file mode 100644 index 0000000..528b56f --- /dev/null +++ b/vision_problem_7.cc @@ -0,0 +1,50 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_7.h" +#include "shape.h" + +VisionProblem_7::VisionProblem_7() { } + +void VisionProblem_7::generate(int label, Vignette *vignette) { + int nb_shapes; + + nb_shapes = 6; + + vignette->clear(); + Shape shape; + + for(int s = 0; s < nb_shapes; s++) { + if((label == 0 && s%2 == 0) || (label == 1 && s%3 == 0)) { + shape.randomize(part_size, part_hole_size); + } + + int xs, ys; + do { + xs = int(random_uniform_0_1() * Vignette::width); + ys = int(random_uniform_0_1() * Vignette::height); + } while(shape.overwrites(vignette, xs, ys)); + shape.draw(s, vignette, xs, ys); + } +} diff --git a/vision_problem_7.h b/vision_problem_7.h new file mode 100644 index 0000000..1e7bb98 --- /dev/null +++ b/vision_problem_7.h @@ -0,0 +1,38 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_7_H +#define VISION_PROBLEM_7_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_7 : public VignetteGenerator { + static const int part_size = Vignette::width/6; + static const int part_hole_size = Vignette::width/64; +public: + VisionProblem_7(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_8.cc b/vision_problem_8.cc new file mode 100644 index 0000000..12e2d7a --- /dev/null +++ b/vision_problem_8.cc @@ -0,0 +1,82 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_8.h" +#include "shape.h" + +VisionProblem_8::VisionProblem_8() { } + +void VisionProblem_8::generate(int label, Vignette *vignette) { + int x_big, y_big, x_small, y_small; + Shape big_shape, small_shape; + + int error; + do { + + vignette->clear(); + + error = 0; + + big_shape.randomize(big_part_size / 2, big_part_hole_size / 2); + small_shape.copy(&big_shape); + small_shape.scale(0.5); + + do { + x_big = int(random_uniform_0_1() * Vignette::width); + y_big = int(random_uniform_0_1() * Vignette::height); + } while(big_shape.overwrites(vignette, x_big, y_big)); + + if(!error) { + big_shape.draw(0, vignette, x_big, y_big); + + vignette->fill(x_big, y_big, 128); + + if(label) { + vignette->switch_values(128, 255); + } else { + if(random_uniform_0_1() < 0.5) { + vignette->switch_values(128, 255); + Shape tmp; + tmp.randomize(big_part_size / 2, big_part_hole_size / 2); + small_shape.copy(&tmp); + small_shape.scale(0.5); + } + } + + int nb_attempts = 0; + do { + x_small = int(random_uniform_0_1() * Vignette::width); + y_small = int(random_uniform_0_1() * Vignette::height); + error = small_shape.overwrites(vignette, x_small, y_small); + nb_attempts++; + } while(error && nb_attempts < 10); + + if(!error) { + vignette->replace_value(128, 255); + small_shape.draw(1, vignette, x_small, y_small); + } + } + + } while(error); +} diff --git a/vision_problem_8.h b/vision_problem_8.h new file mode 100644 index 0000000..b194452 --- /dev/null +++ b/vision_problem_8.h @@ -0,0 +1,41 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_8_H +#define VISION_PROBLEM_8_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_8 : public VignetteGenerator { + static const int small_part_size = Vignette::width/6; + static const int small_part_hole_size = Vignette::width/64; + static const int big_part_size = (Vignette::width * 3)/4; + static const int big_part_hole_size = Vignette::width / 3; +public: + VisionProblem_8(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_9.cc b/vision_problem_9.cc new file mode 100644 index 0000000..83de226 --- /dev/null +++ b/vision_problem_9.cc @@ -0,0 +1,78 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_9.h" +#include "shape.h" + +VisionProblem_9::VisionProblem_9() { } + +void VisionProblem_9::generate(int label, Vignette *vignette) { + int nb_shapes = 3; + int xs[nb_shapes], ys[nb_shapes]; + Shape big_shape, small_shape; + + int error; + + do { + scalar_t x1 = int(random_uniform_0_1() * Vignette::width); + scalar_t y1 = int(random_uniform_0_1() * Vignette::height); + scalar_t x2 = int(random_uniform_0_1() * Vignette::width); + scalar_t y2 = int(random_uniform_0_1() * Vignette::height); + scalar_t alpha = 0.25 + 0.5 * random_uniform_0_1(); + + big_shape.randomize(part_size, hole_size); + small_shape.copy(&big_shape); + small_shape.scale(0.5); + + if(label == 0) { + xs[0] = int(x1); ys[0] = int(y1); + xs[1] = int(x2); ys[1] = int(y2); + xs[2] = int(alpha * x1 + (1 - alpha) * x2); ys[2] = int(alpha * y1 + (1 - alpha) * y2); + } else { + xs[0] = int(x1); ys[0] = int(y1); + xs[1] = int(alpha * x1 + (1 - alpha) * x2); ys[1] = int(alpha * y1 + (1 - alpha) * y2); + xs[2] = int(x2); ys[2] = int(y2); + } + + vignette->clear(); + + error = 0; + for(int n = 0; n < nb_shapes; n++) { + if(n < 2) { + error |= small_shape.overwrites(vignette, xs[n], ys[n]); + if(!error) { + small_shape.draw(n, vignette, xs[n], ys[n]); + } + } else { + error |= big_shape.overwrites(vignette, xs[n], ys[n]); + if(!error) { + big_shape.draw(n, vignette, xs[n], ys[n]); + } + } + vignette->fill(xs[n], ys[n], 128); + } + + vignette->replace_value(128, 255); + } while(error); +} diff --git a/vision_problem_9.h b/vision_problem_9.h new file mode 100644 index 0000000..b785da1 --- /dev/null +++ b/vision_problem_9.h @@ -0,0 +1,38 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ +#ifndef VISION_PROBLEM_9_H +#define VISION_PROBLEM_9_H + +#include "vignette_generator.h" +#include "vision_problem_tools.h" + +class VisionProblem_9 : public VignetteGenerator { + static const int part_size = Vignette::width / 6; + static const int hole_size = Vignette::width / 64; +public: + VisionProblem_9(); + virtual void generate(int label, Vignette *vignette); +}; + +#endif diff --git a/vision_problem_tools.cc b/vision_problem_tools.cc new file mode 100644 index 0000000..0100e90 --- /dev/null +++ b/vision_problem_tools.cc @@ -0,0 +1,62 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#include "vision_problem_tools.h" + +int cluttered_shapes(int part_size, int nb_shapes, int *xs, int *ys) { + for(int n = 0; n < nb_shapes; n++) { + for(int m = 0; m < n; m++) { + if(abs(xs[n] - xs[m]) < part_size && abs(ys[n] - ys[m]) < part_size) + return 1; + } + } + return 0; +} + +scalar_t dist_point_to_segment(scalar_t xp, scalar_t yp, + scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2) { + scalar_t s; + s = (xp - x1) * (x2 - x1) + (yp - y1) * (y2 - y1); + if(s < 0) { + return sqrt(sq(xp - x1) + sq(yp - y1)); + } else if(s > sq(x2 - x1) + sq(y2 - y1)) { + return sqrt(sq(xp - x2) + sq(yp - y2)); + } else { + return abs((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1))/sqrt(sq(x2 - x1) + sq(y2 - y1)); + } +} + +int point_in_band(scalar_t xp, scalar_t yp, + scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2, + scalar_t width) { + scalar_t s; + s = (xp - x1) * (x2 - x1) + (yp - y1) * (y2 - y1); + if(s < 0) { + return 0; + } else if(s > sq(x2 - x1) + sq(y2 - y1)) { + return 0; + } else { + return abs((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1))/sqrt(sq(x2 - x1) + sq(y2 - y1)) <= width; + } +} diff --git a/vision_problem_tools.h b/vision_problem_tools.h new file mode 100644 index 0000000..5631711 --- /dev/null +++ b/vision_problem_tools.h @@ -0,0 +1,41 @@ +/* + * svrt is the ``Synthetic Visual Reasoning Test'', an image + * generator for evaluating classification performance of machine + * learning systems, humans and primates. + * + * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/ + * Written by Francois Fleuret + * + * This file is part of svrt. + * + * svrt is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * svrt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with selector. If not, see . + * + */ + +#ifndef VISION_PROBLEM_TOOLS_H +#define VISION_PROBLEM_TOOLS_H + +#include "misc.h" +#include "random.h" +#include "vignette.h" + +int cluttered_shapes(int part_size, int nb_shapes, int *xs, int *ys); + +scalar_t dist_point_to_segment(scalar_t xp, scalar_t yp, + scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2); + +int point_in_band(scalar_t xp, scalar_t yp, + scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2, + scalar_t width); + +#endif -- 2.20.1