def test_data_splitter_with_np_array_with_larger_last_slice(): x = np.ones([32, 32, 32, 3], dtype=np.float32) res2 = data_splitter(x, 5) assert all( map(lambda x: shape_as_list(x) == [6, 32, 32, 3], [res2['slice{}'.format(i)] for i in range(4)])) is True assert shape_as_list(res2['slice4']) == [8, 32, 32, 3]
def test_data_splitter_with_tensor_with_larger_last_slice(): x = tf.ones([32, 64, 64, 3], dtype=tf.float32) x = Tensor(x) res2 = data_splitter(x, 5) assert all( map(lambda x: shape_as_list(x) == [6, 64, 64, 3], [res2['slice{}'.format(i)] for i in range(4)])) is True assert all( map(lambda x: isinstance(x, Tensor), [res2['slice{}'.format(i)] for i in range(5)])) is True assert shape_as_list(res2['slice4']) == [8, 64, 64, 3]
def _(x, nb_split, name='data_splitter'): shape_x = shape_as_list(x) split_size = shape_x[0] // nb_split res = {} offset = 0 for i in range(nb_split - 1): res['slice{}'.format(i)] = x[offset:offset + split_size] offset = offset + split_size res['slice{}'.format(nb_split - 1)] = x[offset:] return res
def _(x, nb_split, name='data_splitter'): shape_x = shape_as_list(x) split_size = shape_x[0] // nb_split res = {} offset = [0 for i in shape_x] slice_size = copy.copy(shape_x) slice_size[0] = split_size for i in range(nb_split - 1): res['slice{}'.format(i)] = tf.slice(x, offset, slice_size) offset[0] = offset[0] + split_size slice_size[0] = shape_x[0] - offset[0] res['slice{}'.format(nb_split - 1)] = tf.slice(x, offset, slice_size) return res
def test_data_splitter_with_tf_tensor(): x = tf.ones([32, 64, 64, 3], dtype=tf.float32) res1 = data_splitter(x, 4) assert all( map(lambda x: shape_as_list(x) == [8, 64, 64, 3], [res1['slice{}'.format(i)] for i in range(4)])) is True
def test_data_splitter_with_np_array(): x = np.ones([32, 32, 32, 3], dtype=np.float32) res1 = data_splitter(x, 4) assert all( map(lambda x: shape_as_list(x) == [8, 32, 32, 3], [res1['slice{}'.format(i)] for i in range(4)])) is True