Beispiel #1
0
    def protocol(self, algo):
        rng = np.random.RandomState(self.seed)
        n_prototypes = self.n_prototypes

        coords = [prototype_coords(rng) for i in range(n_prototypes)]

        dset = functools.partial(
            self.distortion_set,
            coords=coords,
            rng=rng,
        )

        train_images, train_labels = dset(N=self.n_train_per_prototype,
                                          level=self.train_level)

        test_5_images, test_5_labels = dset(N=self.n_test_5_per_prototype,
                                            level='5')
        test_7_images, test_7_labels = dset(N=self.n_test_7_per_prototype,
                                            level='7.7')

        test_proto_images, test_proto_labels = dset(N=1, level='0')
        test_proto_labels = range(self.n_prototypes)

        # XXX: Careful not to actually expect the model to get these right.
        test_random_images = [
            render_coords_uint8_channels(prototype_coords(rng))
            for c in range(n_prototypes)
        ]
        test_random_labels = range(self.n_prototypes)

        model = algo.best_model(
            train=self.task('train', train_images, train_labels))

        loss_5 = algo.loss(model,
                           self.task('test_5', test_5_images, test_5_labels))
        loss_7 = algo.loss(model,
                           self.task('test_7', test_7_images, test_7_labels))
        loss_train = algo.loss(
            model, self.task('test_train', train_images, train_labels))
        loss_proto = algo.loss(
            model, self.task('test_proto', test_proto_images,
                             test_proto_labels))
        loss_random = algo.loss(
            model,
            self.task('test_random', test_random_images, test_random_labels))

        return algo
Beispiel #2
0
    def protocol(self, algo):
        rng = np.random.RandomState(self.seed)
        n_prototypes = self.n_prototypes

        coords = [prototype_coords(rng) for i in range(n_prototypes)]

        dset = functools.partial(self.distortion_set,
                                 coords=coords,
                                 rng=rng,
                                )

        train_images, train_labels = dset(
            N=self.n_train_per_prototype,
            level=self.train_level)

        test_5_images, test_5_labels = dset(
            N=self.n_test_5_per_prototype,
            level='5')
        test_7_images, test_7_labels = dset(
            N=self.n_test_7_per_prototype,
            level='7.7')

        test_proto_images, test_proto_labels = dset(N=1, level='0')
        test_proto_labels = range(self.n_prototypes)

        # XXX: Careful not to actually expect the model to get these right.
        test_random_images = [
            render_coords_uint8_channels(prototype_coords(rng))
            for c in range(n_prototypes)]
        test_random_labels = range(self.n_prototypes)

        model = algo.best_model(
            train=self.task('train', train_images, train_labels))


        loss_5 = algo.loss(model,
             self.task('test_5', test_5_images, test_5_labels))
        loss_7 = algo.loss(model,
             self.task('test_7', test_7_images, test_7_labels))
        loss_train = algo.loss(model,
             self.task('test_train', train_images, train_labels))
        loss_proto = algo.loss(model,
             self.task('test_proto', test_proto_images, test_proto_labels))
        loss_random = algo.loss(model,
             self.task('test_random', test_random_images, test_random_labels))

        return algo
Beispiel #3
0
def main_show():
    import matplotlib.pyplot as plt
    rng = np.random.RandomState(1)
    coords = prototype_coords(rng)
    img = render_coords(coords)
    img3 = render_coords(distort(coords, '3', rng))
    img6 = render_coords(distort(coords, '6', rng))
    plt.imshow(np.asarray([img, img3, img6]).T,
               cmap='gray',
               interpolation='nearest')
    plt.show()
Beispiel #4
0
def main_show():
    import matplotlib.pyplot as plt
    rng = np.random.RandomState(1)
    coords = prototype_coords(rng)
    img = render_coords(coords)
    img3 = render_coords(distort(coords, '3', rng))
    img6 = render_coords(distort(coords, '6', rng))
    plt.imshow(np.asarray([img, img3, img6]).T,
               cmap='gray',
               interpolation='nearest')
    plt.show()