Mercurial > ift6266
annotate transformations/testtransformations.py @ 59:8b9fca879543
La proportion de bruit a ete divisee par 5, ca donne une transformation beaucoup moins aggressive
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Mon, 08 Feb 2010 14:09:11 -0500 |
parents | 6846136b2201 |
children | 4407ab3f7805 |
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 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
18 #from gimp_script import GIMPTransformation |
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 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
23 #from Occlusion import Occlusion |
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 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
28 MODULE_INSTANCES = [Thick(),Slant(),AffineTransformation(), LocalElasticDistorter(), PermutPixel(), Rature(), BruitGauss(),PoivreSel(), Contrast()] |
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 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
31 complexity = [0.6,0.7,0.5,0.4,0.1,0.5,0.03,0.03,0.5] |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
32 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
33 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
34 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
|
35 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
40 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
|
41 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
42 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
|
43 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
44 pygame.display.init() |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
45 screen = pygame.display.set_mode((4*(nbmodule+1)*32,4*32+20),0,8) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
46 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
|
47 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
|
48 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
49 pygame.font.init() |
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 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
|
52 a=d[i,:] |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
61 offset = 4*32 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
62 ct = 0 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
63 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
|
64 #max dilation |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
65 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
66 #random |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
67 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
|
68 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
69 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
|
70 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
|
71 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 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
|
76 screen.blit(new,(offset,0)) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
77 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
|
78 text = font.render(j.__module__,0,(255,255,255),(0,0,0)) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
79 screen.blit(text,(offset,4*32)) |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
80 offset += 4*32 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
81 ct+=1 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
82 pygame.display.update() |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
83 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
|
84 |
6846136b2201
Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff
changeset
|
85 pygame.display.quit() |