Mercurial > ift6266
comparison transformations/testtransformations.py @ 118:0d083964af4b
small change to testtransformation to match with the pipeline behavior
author | Xavier Glorot <glorotxa@iro.umontreal.ca> |
---|---|
date | Wed, 17 Feb 2010 16:25:44 -0500 |
parents | 291d749452df |
children | 5e00ed18ae32 |
comparison
equal
deleted
inserted
replaced
117:c9d680d9a908 | 118:0d083964af4b |
---|---|
29 | 29 |
30 ###---------------------order of transformation module | 30 ###---------------------order of transformation module |
31 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(),GIMP1(),Rature(),Occlusion(), PermutPixel(),DistorsionGauss(),AddBackground(), PoivreSel(), BruitGauss(), Contrast()] | 31 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(),GIMP1(),Rature(),Occlusion(), PermutPixel(),DistorsionGauss(),AddBackground(), PoivreSel(), BruitGauss(), Contrast()] |
32 | 32 |
33 ###---------------------complexity associated to each of them | 33 ###---------------------complexity associated to each of them |
34 complexity = [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5] | 34 complexity = 0.6 |
35 #complexity = [0.5]*len(MODULE_INSTANCES) | 35 #complexity = [0.5]*len(MODULE_INSTANCES) |
36 #complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.] | 36 #complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.] |
37 n=100 | |
37 | 38 |
38 def createimage(path,d): | 39 def createimage(path,d): |
39 for i in range(100): | 40 for i in range(n): |
40 screen.fill(0) | 41 screen.fill(0) |
41 a=d[i,:] | 42 a=d[i,:] |
42 off1=4*32 | 43 off1=4*32 |
43 off2=0 | 44 off2=0 |
44 for u in range(100): | 45 for u in range(n): |
45 b=N.asarray(N.reshape(a,(32,32))) | 46 b=N.asarray(N.reshape(a,(32,32))) |
46 c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T | 47 c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T |
47 new=pygame.surfarray.make_surface(c) | 48 new=pygame.surfarray.make_surface(c) |
48 new=pygame.transform.scale2x(new) | 49 new=pygame.transform.scale2x(new) |
49 new=pygame.transform.scale2x(new) | 50 new=pygame.transform.scale2x(new) |
52 exemple.blit(new,(0,0)) | 53 exemple.blit(new,(0,0)) |
53 | 54 |
54 offset = 4*32 | 55 offset = 4*32 |
55 offset2 = 0 | 56 offset2 = 0 |
56 ct = 0 | 57 ct = 0 |
58 ctmp = N.random.rand()*complexity | |
59 print u | |
57 for j in MODULE_INSTANCES: | 60 for j in MODULE_INSTANCES: |
58 #max dilation | 61 #max dilation |
59 ctmp = N.random.rand()*complexity[ct] | 62 #ctmp = N.random.rand()*complexity[ct] |
60 #random | 63 ctmp = N.random.rand()*complexity |
61 print j.get_settings_names(), j.regenerate_parameters(ctmp) | 64 #print j.get_settings_names(), j.regenerate_parameters(ctmp) |
62 | 65 j.regenerate_parameters(ctmp) |
66 | |
63 b=j.transform_image(b) | 67 b=j.transform_image(b) |
64 c=N.asarray([b*255]*3).T | 68 c=N.asarray([b*255]*3).T |
65 new=pygame.surfarray.make_surface(c) | 69 new=pygame.surfarray.make_surface(c) |
66 new=pygame.transform.scale2x(new) | 70 new=pygame.transform.scale2x(new) |
67 new=pygame.transform.scale2x(new) | 71 new=pygame.transform.scale2x(new) |
93 | 97 |
94 pygame.surfarray.use_arraytype('numpy') | 98 pygame.surfarray.use_arraytype('numpy') |
95 | 99 |
96 #pygame.display.init() | 100 #pygame.display.init() |
97 screen = pygame.Surface((4*(nbmodule+1)/2*32,2*(4*32+20)),depth=32) | 101 screen = pygame.Surface((4*(nbmodule+1)/2*32,2*(4*32+20)),depth=32) |
98 exemple = pygame.Surface((10*4*32,10*4*32),depth=32) | 102 exemple = pygame.Surface((N.ceil(N.sqrt(n))*4*32,N.ceil(N.sqrt(n))*4*32),depth=32) |
99 | 103 |
100 anglcolorpalette=[(x,x,x) for x in xrange(0,256)] | 104 anglcolorpalette=[(x,x,x) for x in xrange(0,256)] |
101 #pygame.Surface.set_palette(anglcolorpalette) | 105 #pygame.Surface.set_palette(anglcolorpalette) |
102 #screen.set_palette(anglcolorpalette) | 106 #screen.set_palette(anglcolorpalette) |
103 | 107 |
104 pygame.font.init() | 108 pygame.font.init() |
105 | 109 |
106 d = N.zeros((100,1024)) | 110 d = N.zeros((n,1024)) |
111 | |
112 | |
113 datapath = '/data/lisa/data/nist/by_class/' | |
114 f = open(datapath+'digits_reshuffled/digits_reshuffled_train_data.ft') | |
115 d = ft.read(f) | |
116 d = d[0:n,:]/255.0 | |
117 createimage('/u/glorotxa/transf/NIST_digits',d) | |
107 | 118 |
108 from Facade import * | 119 from Facade import * |
109 | 120 |
110 for i in range(100): | 121 for i in range(n): |
111 d[i,:]=N.asarray(N.reshape(generateCaptcha(0,0),(1,1024))/255.0,dtype='float32') | 122 d[i,:]=N.asarray(N.reshape(generateCaptcha(0.5,0),(1,1024))/255.0,dtype='float32') |
112 | 123 |
113 createimage('/u/glorotxa/transf/capcha',d) | 124 createimage('/u/glorotxa/transf/capcha',d) |
114 | 125 |
115 | 126 |
116 for i in range(100): | 127 for i in range(n): |
117 myttf2jpg = ttf2jpg() | 128 myttf2jpg = ttf2jpg() |
118 d[i,:]=N.reshape(myttf2jpg.generate_image(),(1,1024)) | 129 d[i,:]=N.reshape(myttf2jpg.generate_image()[0],(1,1024)) |
119 createimage('/u/glorotxa/transf/fonts',d) | 130 createimage('/u/glorotxa/transf/fonts',d) |
120 | 131 |
121 | 132 |
122 | 133 |
123 datapath = '/data/lisa/data/nist/by_class/' | 134 datapath = '/data/lisa/data/nist/by_class/' |
124 f = open(datapath+'lower/lower_train_data.ft') | 135 f = open(datapath+'lower/lower_train_data.ft') |
125 d = ft.read(f) | 136 d = ft.read(f) |
126 d = d[0:100,:]/255.0 | 137 d = d[0:n,:]/255.0 |
127 createimage('/u/glorotxa/transf/NIST_lower',d) | 138 createimage('/u/glorotxa/transf/NIST_lower',d) |
128 | 139 |
129 datapath = '/data/lisa/data/nist/by_class/' | 140 datapath = '/data/lisa/data/nist/by_class/' |
130 f = open(datapath+'upper/upper_train_data.ft') | 141 f = open(datapath+'upper/upper_train_data.ft') |
131 d = ft.read(f) | 142 d = ft.read(f) |
132 d = d[0:100,:]/255.0 | 143 d = d[0:n,:]/255.0 |
133 createimage('/u/glorotxa/transf/NIST_upper',d) | 144 createimage('/u/glorotxa/transf/NIST_upper',d) |
134 | 145 datapath = '/data/lisa/data/ocr_breuel/filetensor/unlv-corrected-2010-02-01-shuffled.ft' |
135 datapath = '/data/lisa/data/nist/by_class/' | |
136 f = open(datapath+'digits_reshuffled/digits_reshuffled_train_data.ft') | |
137 d = ft.read(f) | |
138 d = d[0:100,:]/255.0 | |
139 createimage('/u/glorotxa/transf/NIST_digits',d) | |
140 | |
141 datapath = '/data/lisa/data/ocr_breuel/filetensor/unlv-corrected-2010-02-01-shuffled.ft/' | |
142 f = open(datapath) | 146 f = open(datapath) |
143 d = ft.read(f) | 147 d = ft.read(f) |
144 d = d[0:100,:]/255.0 | 148 d = d[0:n,:]/255.0 |
145 createimage('/u/glorotxa/transf/OCR',d) | 149 createimage('/u/glorotxa/transf/OCR',d) |
146 | 150 |
147 | 151 |
148 | 152 |
149 | 153 |