# HG changeset patch # User Xavier Glorot # Date 1266364582 18000 # Node ID 291d749452df299d5dce404984dcf42081d86e2d # Parent 1b315470a5667a54ade02d8f93350e9b111845cd testtransformation.py to source from all the available data diff -r 1b315470a566 -r 291d749452df transformations/testtransformations.py --- a/transformations/testtransformations.py Tue Feb 16 18:55:51 2010 -0500 +++ b/transformations/testtransformations.py Tue Feb 16 18:56:22 2010 -0500 @@ -1,12 +1,15 @@ #!/usr/bin/env python + from pylearn.io import filetensor as ft import copy import pygame import time import numpy as N +from ttf2jpg import ttf2jpg + #from gimpfu import * @@ -28,24 +31,71 @@ MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(),GIMP1(),Rature(),Occlusion(), PermutPixel(),DistorsionGauss(),AddBackground(), PoivreSel(), BruitGauss(), Contrast()] ###---------------------complexity associated to each of them -complexity = [0.6,0.6,0.6,0.6,0.6,0.3,0.3,0.5,0.5,0.5,0.3,0.3,0.5] -complexity = [0.5]*len(MODULE_INSTANCES) +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] +#complexity = [0.5]*len(MODULE_INSTANCES) #complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.] +def createimage(path,d): + for i in range(100): + screen.fill(0) + a=d[i,:] + off1=4*32 + off2=0 + for u in range(100): + b=N.asarray(N.reshape(a,(32,32))) + c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T + new=pygame.surfarray.make_surface(c) + new=pygame.transform.scale2x(new) + new=pygame.transform.scale2x(new) + #new.set_palette(anglcolorpalette) + screen.blit(new,(0,0)) + exemple.blit(new,(0,0)) + + offset = 4*32 + offset2 = 0 + ct = 0 + for j in MODULE_INSTANCES: + #max dilation + ctmp = N.random.rand()*complexity[ct] + #random + print j.get_settings_names(), j.regenerate_parameters(ctmp) + + b=j.transform_image(b) + c=N.asarray([b*255]*3).T + new=pygame.surfarray.make_surface(c) + new=pygame.transform.scale2x(new) + new=pygame.transform.scale2x(new) + if u==0: + #new.set_palette(anglcolorpalette) + screen.blit(new,(offset,offset2)) + font = pygame.font.SysFont('liberationserif',18) + text = font.render('%s '%(int(ctmp*100.0)/100.0) + j.__module__,0,(255,255,255),(0,0,0)) + screen.blit(text,(offset,offset2+4*32)) + if ct == len(MODULE_INSTANCES)/2-1: + offset = 0 + offset2 = 4*32+20 + else: + offset += 4*32 + ct+=1 + exemple.blit(new,(off1,off2)) + if off1 != 9*4*32: + off1+=4*32 + else: + off1=0 + off2+=4*32 + pygame.image.save(exemple,path+'/perimages/%s.PNG'%i) + pygame.image.save(screen,path+'/exemples/%s.PNG'%i) + + nbmodule = len(MODULE_INSTANCES) -datapath = '/data/lisa/data/nist/by_class/' -f = open(datapath+'lower/lower_train_data.ft') -d = ft.read(f) - -d = d[0:1000,:]/255.0 - pygame.surfarray.use_arraytype('numpy') #pygame.display.init() screen = pygame.Surface((4*(nbmodule+1)/2*32,2*(4*32+20)),depth=32) +exemple = pygame.Surface((10*4*32,10*4*32),depth=32) anglcolorpalette=[(x,x,x) for x in xrange(0,256)] #pygame.Surface.set_palette(anglcolorpalette) @@ -53,43 +103,49 @@ pygame.font.init() -for i in range(1000): - a=d[i,:] - b=N.asarray(N.reshape(a,(32,32))) - c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T - new=pygame.surfarray.make_surface(c) - new=pygame.transform.scale2x(new) - new=pygame.transform.scale2x(new) - #new.set_palette(anglcolorpalette) - screen.blit(new,(0,0)) - - offset = 4*32 - offset2 = 0 - ct = 0 - for j in MODULE_INSTANCES: - #max dilation - - #random - print j.get_settings_names(), j.regenerate_parameters(N.random.rand()*complexity[ct]) +d = N.zeros((100,1024)) + +from Facade import * + +for i in range(100): + d[i,:]=N.asarray(N.reshape(generateCaptcha(0,0),(1,1024))/255.0,dtype='float32') + +createimage('/u/glorotxa/transf/capcha',d) + + +for i in range(100): + myttf2jpg = ttf2jpg() + d[i,:]=N.reshape(myttf2jpg.generate_image(),(1,1024)) +createimage('/u/glorotxa/transf/fonts',d) + + - b=j.transform_image(b) - c=N.asarray([b*255]*3).T - - new=pygame.surfarray.make_surface(c) - new=pygame.transform.scale2x(new) - new=pygame.transform.scale2x(new) - #new.set_palette(anglcolorpalette) - screen.blit(new,(offset,offset2)) - font = pygame.font.SysFont('liberationserif',18) - text = font.render(j.__module__,0,(255,255,255),(0,0,0)) - screen.blit(text,(offset,offset2+4*32)) - if ct == len(MODULE_INSTANCES)/2-1: - offset = 0 - offset2 = 4*32+20 - else: - offset += 4*32 - ct+=1 - pygame.image.save(screen,'/u/glorotxa/exemples/%s.PNG'%i) - #raw_input('Press Enter') +datapath = '/data/lisa/data/nist/by_class/' +f = open(datapath+'lower/lower_train_data.ft') +d = ft.read(f) +d = d[0:100,:]/255.0 +createimage('/u/glorotxa/transf/NIST_lower',d) + +datapath = '/data/lisa/data/nist/by_class/' +f = open(datapath+'upper/upper_train_data.ft') +d = ft.read(f) +d = d[0:100,:]/255.0 +createimage('/u/glorotxa/transf/NIST_upper',d) + +datapath = '/data/lisa/data/nist/by_class/' +f = open(datapath+'digits_reshuffled/digits_reshuffled_train_data.ft') +d = ft.read(f) +d = d[0:100,:]/255.0 +createimage('/u/glorotxa/transf/NIST_digits',d) + +datapath = '/data/lisa/data/ocr_breuel/filetensor/unlv-corrected-2010-02-01-shuffled.ft/' +f = open(datapath) +d = ft.read(f) +d = d[0:100,:]/255.0 +createimage('/u/glorotxa/transf/OCR',d) + + + + #pygame.display.quit()