def get_example(load_example, eval_tracker, model, get_offsets): """Generates individual training examples. Args: load_example: callable returning a tuple of image and label ndarrays as well as the seed coordinate and volume name of the example eval_tracker: EvalTracker object model: FFNModel object get_offsets: iterable of (x, y, z) offsets to investigate within the training patch Yields: tuple of: seed array, shape [1, z, y, x, 1] image array, shape [1, z, y, x, 1] label array, shape [1, z, y, x, 1] """ seed_shape = train_canvas_size(model).tolist()[::-1] while True: full_patches, full_labels, loss_weights, coord, volname = load_example( ) # Write a random fraction of paired examples to images and make sure they have # matching and correct orientations. if FLAGS.debug: if random.uniform(0, 1) > 0.999: write_patch_and_label_to_img( patch=full_patches[0, 0, :, :, 0] * FLAGS.image_stddev + FLAGS.image_mean, label=full_labels[0, 0, :, :, 0] * 255, unique_id='_'.join(coord[0].astype(str).tolist()), dirname="./debug") # Always start with a clean seed. seed = logit(mask.make_seed(seed_shape, 1, pad=FLAGS.seed_pad)) for off in get_offsets(model, seed): predicted = mask.crop_and_pad(seed, off, model.input_seed_size[::-1]) patches = mask.crop_and_pad(full_patches, off, model.input_image_size[::-1]) labels = mask.crop_and_pad(full_labels, off, model.pred_mask_size[::-1]) weights = mask.crop_and_pad(loss_weights, off, model.pred_mask_size[::-1]) # Necessary, since the caller is going to update the array and these # changes need to be visible in the following iterations. assert predicted.base is seed yield predicted, patches, labels, weights # TODO(jpgard): track volname in eval_tracker. Currently nothing is done with # volname, but it should be monitored to ensure coverage of all training # volumes. Similar for coord; would be good to check coordinates covered, # or at least a sample of them. eval_tracker.add_patch(full_labels, seed, loss_weights, coord, volname, full_patches)
def get_example(load_example, eval_tracker, model, get_offsets): """Generates individual training examples. Args: load_example: callable returning a tuple of image and label ndarrays as well as the seed coordinate and volume name of the example eval_tracker: EvalTracker object model: FFNModel object get_offsets: iterable of (x, y, z) offsets to investigate within the training patch Yields: tuple of: seed array, shape [1, z, y, x, 1] image array, shape [1, z, y, x, 1] label array, shape [1, z, y, x, 1] """ seed_shape = train_canvas_size(model).tolist()[::-1] while True: full_patches, full_labels, loss_weights, coord, volname = load_example( ) # Always start with a clean seed. seed = logit(mask.make_seed(seed_shape, 1, pad=FLAGS.seed_pad)) for off in get_offsets(model, seed): predicted = mask.crop_and_pad(seed, off, model.input_seed_size[::-1]) patches = mask.crop_and_pad(full_patches, off, model.input_image_size[::-1]) labels = mask.crop_and_pad(full_labels, off, model.pred_mask_size[::-1]) weights = mask.crop_and_pad(loss_weights, off, model.pred_mask_size[::-1]) # Necessary, since the caller is going to update the array and these # changes need to be visible in the following iterations. assert predicted.base is seed yield predicted, patches, labels, weights # eval_tracker.add_patch( # full_labels, seed, loss_weights, coord, volname, full_patches) eval_tracker.add_patch_v2(full_labels, seed, loss_weights, coord, volname, full_patches)