def test_block_iter0(self): files = match_img_files(self.class_dir) block_iter = _block_iter( block_tensor=files, label=self.label, block_length=2, block_bound=False, sample_block_random=False, seed=None, ) labels = [self.label] * len(files) files_list = list(zip(files, labels)) block_list = list(block_iter) self.assertEqual(block_list, files_list)
def _interleave_fn_image_files( input_dir, label, block_length, block_bound=True, sample_block_random=False, seed=None, ): img_files = match_img_files(input_dir) block_iter = _block_iter( img_files, label, block_length=block_length, block_bound=block_bound, sample_block_random=sample_block_random, seed=seed, ) return block_iter
def test_block_iter1(self): """ test block bound""" files = match_img_files(self.class_dir) block_len = 2 block_iter = _block_iter( block_tensor=files, label=self.label, block_length=block_len, block_bound=True, sample_block_random=False, seed=None, ) labels = [self.label] * len(files) files_list = list(zip(files, labels))[:block_len] block_list = list(block_iter) self.assertEqual(block_list, files_list)
def _interleave_fn_image_triplet_files( input_dir, label, block_length, block_bound=True, sample_block_random=False, seed=None, ): img_files = match_img_files(input_dir) # if no images found in folder, assume it is a triplet folder if tf.shape(img_files)[0] == 0: triplets = match_img_files_triplet(input_dir) block_iter = _block_iter_triplet( triplets, label, block_length=block_length, block_bound=block_bound, sample_block_random=sample_block_random, seed=seed, ) # call .repeat(1) to make it a RepeatDataset, so both if/else branches are same dataset type. block_iter = block_iter.repeat(1) else: block_iter = _block_iter( img_files, label, block_length=block_length, block_bound=block_bound, sample_block_random=sample_block_random, seed=seed, ) # call .repeat(1) to make it a RepeatDataset, so both if/else branches are same dataset type. block_iter = block_iter.repeat(1) return block_iter
def flat_map_fn(input_dir, label): files = match_img_files(input_dir) n_files = tf.shape(files)[0] y = tf.tile([label], [n_files]) return tf.data.Dataset.from_tensor_slices((files, y))
def test_read_img_files_shape(self): files = match_img_files(img_folder) self.assertAllEqual(tf.shape(files), (3, ))