def test_dynamic_init(self): sampler = UniformSampler(reader=get_dynamic_window_reader(), window_sizes=DYNAMIC_MOD_DATA, batch_size=2, windows_per_image=10, queue_length=10) with self.test_session() as sess: sampler.set_num_threads(2) out = sess.run(sampler.pop_batch_op()) self.assertAllClose(out['image'].shape[1:], (8, 2, 256, 2)) sampler.close_all()
def test_2d_init(self): sampler = UniformSampler(reader=get_2d_reader(), window_sizes=MOD_2D_DATA, batch_size=2, windows_per_image=10, queue_length=10) with self.test_session() as sess: sampler.set_num_threads(2) out = sess.run(sampler.pop_batch_op()) self.assertAllClose(out['image'].shape, (2, 10, 9, 1)) sampler.close_all()
def test_3d_concentric_init(self): sampler = UniformSampler(reader=get_concentric_window_reader(), window_sizes=MULTI_WINDOW_DATA, batch_size=2, windows_per_image=10, queue_length=10) with self.test_session() as sess: sampler.set_num_threads(2) out = sess.run(sampler.pop_batch_op()) img_loc = out['image_location'] seg_loc = out['label_location'] self.assertTrue(np.all(img_loc[:, 0] == seg_loc[:, 0])) self.assertTrue(np.all((img_loc - seg_loc)[:, 1:4] == [1, 1, 0])) self.assertTrue(np.all((img_loc - seg_loc)[:, 4:] == [-2, -1, 1])) self.assertAllClose(out['image'].shape, (2, 4, 10, 3, 1)) self.assertAllClose(out['label'].shape, (2, 7, 12, 2, 1)) sampler.close_all()
reader.add_preprocessing_layers( # add volume padding layer [PadLayer(image_name=['MR'], border=volume_padding_size, mode='constant')]) ### # show 'volume' -- without window sampling ### image_2d = ImageWindowDataset(reader)()['MR'][0, :, :, 0, 0, 0] vis_coordinates(image_2d, saving_name='output/image.png') ### # create & show uniform random samples ### uniform_sampler = UniformSampler(reader, spatial_window_size, windows_per_image=100) next_window = uniform_sampler.pop_batch_op() coords = [] with tf.Session() as sess: for _ in range(20): uniform_windows = sess.run(next_window) coords.append(uniform_windows['MR_location']) coords = np.concatenate(coords, axis=0) vis_coordinates(image_2d, coords, 'output/uniform.png') ### # create & show all grid samples ### grid_sampler = GridSampler(reader, spatial_window_size, window_border=border) next_grid = grid_sampler.pop_batch_op() coords = [] with tf.Session() as sess: