| 191 | |
| 192 | |
| 193 | class SliceArgsIterator(object): |
| 194 | def __init__( |
| 195 | self, |
| 196 | batch_size, |
| 197 | num_dims=3, |
| 198 | image_shape=None, # Needed if normalized_anchor and normalized_shape are False |
| 199 | image_layout=None, # Needed if axis_names is used to specify the slice |
| 200 | normalized_anchor=True, |
| 201 | normalized_shape=True, |
| 202 | axes=None, |
| 203 | axis_names=None, |
| 204 | min_norm_anchor=0.0, |
| 205 | max_norm_anchor=0.2, |
| 206 | min_norm_shape=0.4, |
| 207 | max_norm_shape=0.75, |
| 208 | seed=54643613, |
| 209 | ): |
| 210 | self.batch_size = batch_size |
| 211 | self.num_dims = num_dims |
| 212 | self.image_shape = image_shape |
| 213 | self.image_layout = image_layout |
| 214 | self.normalized_anchor = normalized_anchor |
| 215 | self.normalized_shape = normalized_shape |
| 216 | self.axes = axes |
| 217 | self.axis_names = axis_names |
| 218 | self.min_norm_anchor = min_norm_anchor |
| 219 | self.max_norm_anchor = max_norm_anchor |
| 220 | self.min_norm_shape = min_norm_shape |
| 221 | self.max_norm_shape = max_norm_shape |
| 222 | self.seed = seed |
| 223 | |
| 224 | if not self.axis_names and not self.axes: |
| 225 | self.axis_names = "WH" |
| 226 | |
| 227 | if self.axis_names: |
| 228 | self.axes = [] |
| 229 | for axis_name in self.axis_names: |
| 230 | assert axis_name in self.image_layout |
| 231 | self.axes.append(self.image_layout.index(axis_name)) |
| 232 | assert len(self.axes) > 0 |
| 233 | |
| 234 | def __iter__(self): |
| 235 | self.i = 0 |
| 236 | self.n = self.batch_size |
| 237 | return self |
| 238 | |
| 239 | def __next__(self): |
| 240 | pos = [] |
| 241 | size = [] |
| 242 | anchor_amplitude = self.max_norm_anchor - self.min_norm_anchor |
| 243 | anchor_offset = self.min_norm_anchor |
| 244 | shape_amplitude = self.max_norm_shape - self.min_norm_shape |
| 245 | shape_offset = self.min_norm_shape |
| 246 | np.random.seed(self.seed) |
| 247 | for k in range(self.batch_size): |
| 248 | norm_anchor = anchor_amplitude * np.random.rand(len(self.axes)) + anchor_offset |
| 249 | norm_shape = shape_amplitude * np.random.rand(len(self.axes)) + shape_offset |
| 250 |
no outgoing calls