comparison transformations/pipeline.py @ 115:b84a0d009af8

changes on pipeline mecanism: we now sample a different complexity for each transformations, this because when we use the same sampled complexity for all the modules 1/8 of the time we are close to 0 and we obtain an image very close to the source, we now save a complexity for each module in the parameters array
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Wed, 17 Feb 2010 16:20:15 -0500
parents 9c45e0071b52
children 3bec123dd75d
comparison
equal deleted inserted replaced
114:0b4080394f2c 115:b84a0d009af8
100 total = self.num_img 100 total = self.num_img
101 num_px = self.image_size[0] * self.image_size[1] 101 num_px = self.image_size[0] * self.image_size[1]
102 102
103 self.res_data = numpy.empty((total, num_px), dtype=numpy.uint8) 103 self.res_data = numpy.empty((total, num_px), dtype=numpy.uint8)
104 # +1 to store complexity 104 # +1 to store complexity
105 self.params = numpy.empty((total, self.num_params_stored+1)) 105 self.params = numpy.empty((total, self.num_params_stored+len(self.modules)))
106 self.res_labels = numpy.empty(total, dtype=numpy.int32) 106 self.res_labels = numpy.empty(total, dtype=numpy.int32)
107 107
108 def run(self, img_iterator, complexity_iterator): 108 def run(self, img_iterator, complexity_iterator):
109 img_size = self.image_size 109 img_size = self.image_size
110 110
111 should_hook_after_each = len(AFTER_EACH_MODULE_HOOK) != 0 111 should_hook_after_each = len(AFTER_EACH_MODULE_HOOK) != 0
112 should_hook_at_the_end = len(END_TRANSFORM_HOOK) != 0 112 should_hook_at_the_end = len(END_TRANSFORM_HOOK) != 0
113 113
114 for img_no, (img, label) in enumerate(img_iterator): 114 for img_no, (img, label) in enumerate(img_iterator):
115 sys.stdout.flush() 115 sys.stdout.flush()
116 complexity = complexity_iterator.next() 116
117
118 global_idx = img_no 117 global_idx = img_no
119 118
120 img = img.reshape(img_size) 119 img = img.reshape(img_size)
121 120
122 param_idx = 1 121 param_idx = 0
122 mod_idx = 0
123 # store complexity along with other params 123 # store complexity along with other params
124 self.params[global_idx, 0] = complexity 124 self.params[global_idx, 0] = complexity
125 for mod in self.modules: 125 for mod in self.modules:
126 # This used to be done _per batch_, 126 # This used to be done _per batch_,
127 # ie. out of the "for img" loop 127 # ie. out of the "for img" loop
128 complexity = complexity_iterator.next()
129 #better to do a complexity sampling for each transformations in order to have more variability
130 #otherwise a lot of images similar to the source are generated (i.e. when complexity is close to 0 (1/8 of the time))
131 #we need to save the complexity of each transformations and the sum of these complexity is a good indicator of the overall
132 #complexity
133 self.params[global_idx, mod_idx] = complexity
134 mod_idx += 1
135
128 p = mod.regenerate_parameters(complexity) 136 p = mod.regenerate_parameters(complexity)
129 self.params[global_idx, param_idx:param_idx+len(p)] = p 137 self.params[global_idx, param_idx+len(self.modules):param_idx+len(p)+len(self.modules)] = p
130 param_idx += len(p) 138 param_idx += len(p)
131 139
132 img = mod.transform_image(img) 140 img = mod.transform_image(img)
133 141
134 if should_hook_after_each: 142 if should_hook_after_each: