Mercurial > ift6266
comparison transformations/pipeline.py @ 109:9c45e0071b52
Adapté le générateur d'images de fontes pour utiliser en amont du pipeline
author | boulanni <nicolas_boulanger@hotmail.com> |
---|---|
date | Tue, 16 Feb 2010 13:10:06 -0500 |
parents | a7cd8dd3221c |
children | b84a0d009af8 |
comparison
equal
deleted
inserted
replaced
108:a7cd8dd3221c | 109:9c45e0071b52 |
---|---|
52 from local_elastic_distortions import LocalElasticDistorter | 52 from local_elastic_distortions import LocalElasticDistorter |
53 from slant import Slant | 53 from slant import Slant |
54 from Occlusion import Occlusion | 54 from Occlusion import Occlusion |
55 from add_background_image import AddBackground | 55 from add_background_image import AddBackground |
56 from affine_transform import AffineTransformation | 56 from affine_transform import AffineTransformation |
57 from ttf2jpg import ttf2jpg | |
57 | 58 |
58 if DEBUG: | 59 if DEBUG: |
59 from visualizer import Visualizer | 60 from visualizer import Visualizer |
60 # Either put the visualizer as in the MODULES_INSTANCES list | 61 # Either put the visualizer as in the MODULES_INSTANCES list |
61 # after each module you want to visualize, or in the | 62 # after each module you want to visualize, or in the |
209 img = ft.read(nist.train_data) | 210 img = ft.read(nist.train_data) |
210 labels = ft.read(nist.train_labels) | 211 labels = ft.read(nist.train_labels) |
211 if prob_ocr: | 212 if prob_ocr: |
212 ocr_img = ft.read(nist.ocr_data) | 213 ocr_img = ft.read(nist.ocr_data) |
213 ocr_labels = ft.read(nist.ocr_labels) | 214 ocr_labels = ft.read(nist.ocr_labels) |
215 ttf = ttf2jpg() | |
214 | 216 |
215 for i in xrange(num_img): | 217 for i in xrange(num_img): |
216 r = numpy.random.rand() | 218 r = numpy.random.rand() |
217 if r <= prob_font: | 219 if r <= prob_font: |
218 pass #get font | 220 yield ttf.generate_image() |
219 elif r <= prob_font + prob_captcha: | 221 elif r <= prob_font + prob_captcha: |
220 pass #get captcha | 222 pass #get captcha |
221 elif r <= prob_font + prob_captcha + prob_ocr: | 223 elif r <= prob_font + prob_captcha + prob_ocr: |
222 j = numpy.random.randint(len(ocr_labels)) | 224 j = numpy.random.randint(len(ocr_labels)) |
223 yield ocr_img[j].astype(numpy.float32)/255, ocr_labels[j] | 225 yield ocr_img[j].astype(numpy.float32)/255, ocr_labels[j] |