annotate transformations/testtransformations.py @ 91:6696391273ab

Il y a maintenant une proba 0.2 d'effectuer des permutations. Cette nouvelle fonctionnalite demande un parametre non deterministe, ce qui fait que maintenant, les fonctions 'determined_by_complexity' ont ete abandonees. Le module se comporte comme un module normal
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Thu, 11 Feb 2010 09:15:42 -0500
parents 104e0b8a1c70
children 1b8176e9892e
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
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
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
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
28 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(),GIMP1(), PermutPixel(),DistorsionGauss(), Rature(), Occlusion(),AddBackground(), BruitGauss(),PoivreSel(), 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
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
31 complexity = [0.7,0.7,0.7,0.7,0.7,0.3,0.3,0.5,0.5,0.1,0.3,0.3,0.5]
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
32 #complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
80
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
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
46 #pygame.display.init()
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
47 screen = pygame.Surface((4*(nbmodule+1)/2*32,2*(4*32+20)),depth=32)
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
48
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
49 anglcolorpalette=[(x,x,x) for x in xrange(0,256)]
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
50 #pygame.Surface.set_palette(anglcolorpalette)
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
51 #screen.set_palette(anglcolorpalette)
57
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 pygame.font.init()
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
54
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
55 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
56 a=d[i,:]
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
57 b=N.asarray(N.reshape(a,(32,32)))
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
58 c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
59 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
60 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
61 new=pygame.transform.scale2x(new)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
62 #new.set_palette(anglcolorpalette)
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
63 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
64
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
65 offset = 4*32
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
66 offset2 = 0
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
67 ct = 0
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
68 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
69 #max dilation
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
70
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
71 #random
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
72 print j.get_settings_names(), j.regenerate_parameters(N.random.rand()*complexity[ct])
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
73
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
74 b=j.transform_image(b)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
75 c=N.asarray([b*255]*3).T
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
76
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
77 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
78 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
79 new=pygame.transform.scale2x(new)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
80 #new.set_palette(anglcolorpalette)
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
81 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
82 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
83 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
84 screen.blit(text,(offset,offset2+4*32))
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
85 if ct == len(MODULE_INSTANCES)/2-1:
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
86 offset = 0
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
87 offset2 = 4*32+20
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
88 else:
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
89 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
90 ct+=1
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
91 pygame.image.save(screen,'/u/glorotxa/exemples/%s.BMP'%i)
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
92 #raw_input('Press Enter')
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
93
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
94 #pygame.display.quit()