comparison transformations/pipeline.py @ 134:4981c729149c

Fixed various bugs in pipeline for Python 2.5 support
author boulanni <nicolas_boulanger@hotmail.com>
date Sat, 20 Feb 2010 02:09:09 -0500
parents ccce06590e64
children 6f3b866c0182
comparison
equal deleted inserted replaced
133:a4e5128ef2cb 134:4981c729149c
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 from ttf2jpg import ttf2jpg
58 from ..pycaptcha.Facade import generateCaptcha 58 from pycaptcha.Facade import generateCaptcha
59 59
60 if DEBUG: 60 if DEBUG:
61 from visualizer import Visualizer 61 from visualizer import Visualizer
62 # Either put the visualizer as in the MODULES_INSTANCES list 62 # Either put the visualizer as in the MODULES_INSTANCES list
63 # after each module you want to visualize, or in the 63 # after each module you want to visualize, or in the
224 224
225 for i in xrange(num_img): 225 for i in xrange(num_img):
226 r = numpy.random.rand() 226 r = numpy.random.rand()
227 if r <= prob_font: 227 if r <= prob_font:
228 yield ttf.generate_image() 228 yield ttf.generate_image()
229 elif r <= prob_font + prob_captcha: 229 elif r <=prob_font + prob_captcha:
230 (arr, charac) = generateCaptcha(0,1) 230 (arr, charac) = generateCaptcha(0,1)
231 yield arr.astype(numpy.float32)/255, L.index(charac) 231 yield arr.astype(numpy.float32)/255, L.index(charac[0])
232 elif r <= prob_font + prob_captcha + prob_ocr: 232 elif r <= prob_font + prob_captcha + prob_ocr:
233 j = numpy.random.randint(len(ocr_labels)) 233 j = numpy.random.randint(len(ocr_labels))
234 yield ocr_img[j].astype(numpy.float32)/255, ocr_labels[j] 234 yield ocr_img[j].astype(numpy.float32)/255, ocr_labels[j]
235 else: 235 else:
236 j = numpy.random.randint(len(labels)) 236 j = numpy.random.randint(len(labels))
266 -l, --label-file: path to filetensor (.ft) labels file (NIST labels) 266 -l, --label-file: path to filetensor (.ft) labels file (NIST labels)
267 -c, --ocr-file: path to filetensor (.ft) data file (OCR) 267 -c, --ocr-file: path to filetensor (.ft) data file (OCR)
268 -d, --ocrlabel-file: path to filetensor (.ft) labels file (OCR labels) 268 -d, --ocrlabel-file: path to filetensor (.ft) labels file (OCR labels)
269 -a, --prob-font: probability of using a raw font image 269 -a, --prob-font: probability of using a raw font image
270 -b, --prob-captcha: probability of using a captcha image 270 -b, --prob-captcha: probability of using a captcha image
271 -e, --prob-ocr: probability of using an ocr image 271 -g, --prob-ocr: probability of using an ocr image
272 ''' 272 '''
273 273
274 # See run_pipeline.py 274 # See run_pipeline.py
275 def get_argv(): 275 def get_argv():
276 with open(ARGS_FILE) as f: 276 with open(ARGS_FILE) as f:
298 prob_ocr = 0.0 298 prob_ocr = 0.0
299 stop_after = None 299 stop_after = None
300 reload_mode = False 300 reload_mode = False
301 301
302 try: 302 try:
303 opts, args = getopt.getopt(get_argv(), "rm:z:o:p:x:s:f:l:c:d:a:b:e:", ["reload","max-complexity=", "probability-zero=", "output-file=", "params-output-file=", "labels-output-file=", "stop-after=", "data-file=", "label-file=", "ocr-file=", "ocrlabel-file=", "prob-font=", "prob-captcha=", "prob-ocr="]) 303 opts, args = getopt.getopt(get_argv(), "rm:z:o:p:x:s:f:l:c:d:a:b:g:", ["reload","max-complexity=", "probability-zero=", "output-file=", "params-output-file=", "labels-output-file=",
304 "stop-after=", "data-file=", "label-file=", "ocr-file=", "ocrlabel-file=", "prob-font=", "prob-captcha=", "prob-ocr="])
304 except getopt.GetoptError, err: 305 except getopt.GetoptError, err:
305 # print help information and exit: 306 # print help information and exit:
306 print str(err) # will print something like "option -a not recognized" 307 print str(err) # will print something like "option -a not recognized"
307 usage() 308 usage()
308 pdb.gimp_quit(0) 309 pdb.gimp_quit(0)
335 ocrlabel_path = a 336 ocrlabel_path = a
336 elif o in ('-a', "--prob-font"): 337 elif o in ('-a', "--prob-font"):
337 prob_font = float(a) 338 prob_font = float(a)
338 elif o in ('-b', "--prob-captcha"): 339 elif o in ('-b', "--prob-captcha"):
339 prob_captcha = float(a) 340 prob_captcha = float(a)
340 elif o in ('-e', "--prob-ocr"): 341 elif o in ('-g', "--prob-ocr"):
341 prob_ocr = float(a) 342 prob_ocr = float(a)
342 else: 343 else:
343 assert False, "unhandled option" 344 assert False, "unhandled option"
344 345
345 if output_file_path == None or params_output_file_path == None or labels_output_file_path == None: 346 if output_file_path == None or params_output_file_path == None or labels_output_file_path == None: