Mercurial > ift6266
annotate transformations/testtransformations.py @ 80:4407ab3f7805
small display change in testtransformation
author | Xavier Glorot <glorotxa@iro.umontreal.ca> |
---|---|
date | Wed, 10 Feb 2010 15:03:40 -0500 |
parents | 6846136b2201 |
children | 104e0b8a1c70 |
rev | line source |
---|---|
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
2 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
3 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
4 from pylearn.io import filetensor as ft |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
5 import copy |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
6 import pygame |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
7 import time |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
8 import numpy as N |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
9 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
10 #from gimpfu import * |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
11 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
12 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
13 from PoivreSel import PoivreSel |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
14 from thick import Thick |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
15 from BruitGauss import BruitGauss |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
16 from DistorsionGauss import DistorsionGauss |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
17 from PermutPixel import PermutPixel |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
18 #from gimp_script import GIMP1 |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
19 from Rature import Rature |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
20 from contrast import Contrast |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
21 from local_elastic_distortions import LocalElasticDistorter |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
22 from slant import Slant |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
23 from Occlusion import Occlusion |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
24 from add_background_image import AddBackground |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
25 from affine_transform import AffineTransformation |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
26 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
27 ###---------------------order of transformation module |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
28 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(), PermutPixel(), Rature(), Occlusion(), BruitGauss(),PoivreSel(),AddBackground(), Contrast()] |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
29 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
30 ###---------------------complexity associated to each of them |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
31 complexity = [0.5,0.6,0.5,0.4,0.1,0.5,0.5,0.5,0.5,0.5,0.5] |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
32 complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.] |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
33 |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
34 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
35 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
36 nbmodule = len(MODULE_INSTANCES) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
37 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
38 datapath = '/data/lisa/data/nist/by_class/' |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
39 f = open(datapath+'lower/lower_train_data.ft') |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
40 d = ft.read(f) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
41 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
42 d = d[0:1000,:]/255.0 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
43 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
44 pygame.surfarray.use_arraytype('numpy') |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
45 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
46 pygame.display.init() |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
47 screen = pygame.display.set_mode((4*(nbmodule+1)/2*32,2*(4*32+20)),0,8) |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
48 anglcolorpalette=[(x,x,x) for x in xrange(0,256)] |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
49 screen.set_palette(anglcolorpalette) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
50 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
51 pygame.font.init() |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
52 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
53 for i in range(10000): |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
54 a=d[i,:] |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
55 b=N.asarray(N.reshape(a,(32,32))) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
56 c=N.asarray(N.reshape(a*255.0,(32,32))).T |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
57 new=pygame.surfarray.make_surface(c) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
58 new=pygame.transform.scale2x(new) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
59 new=pygame.transform.scale2x(new) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
60 new.set_palette(anglcolorpalette) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
61 screen.blit(new,(0,0)) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
62 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
63 offset = 4*32 |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
64 offset2 = 0 |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
65 ct = 0 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
66 for j in MODULE_INSTANCES: |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
67 #max dilation |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
68 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
69 #random |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
70 print j.get_settings_names(), j.regenerate_parameters(complexity[ct]) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
71 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
72 b=j.transform_image(b) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
73 c=N.asarray(b*255).T |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
74 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
75 new=pygame.surfarray.make_surface(c) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
76 new=pygame.transform.scale2x(new) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
77 new=pygame.transform.scale2x(new) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
78 new.set_palette(anglcolorpalette) |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
79 screen.blit(new,(offset,offset2)) |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
80 font = pygame.font.SysFont('liberationserif',18) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
81 text = font.render(j.__module__,0,(255,255,255),(0,0,0)) |
80
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
82 screen.blit(text,(offset,offset2+4*32)) |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
83 if ct == len(MODULE_INSTANCES)/2-1: |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
84 offset = 0 |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
85 offset2 = 4*32+20 |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
86 else: |
4407ab3f7805
small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
57
diff
changeset
|
87 offset += 4*32 |
57
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
88 ct+=1 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
89 pygame.display.update() |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
90 raw_input('Press Enter') |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
91 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
92 pygame.display.quit() |