Im new to tensorflow and need help in managing my image dataset. Since the image set is huge the reading and training phases should overlap. Each image has also way more pixels in its width than in its height. I need to split the wide image into square parts. Since the width of the image varies, also the amount of parts will change.
It follows my example code, where I need help in getting it to work:
def main(unused_argv):
filenames = tf.constant(['im_01.png', 'im_02.png', 'im_03.png', 'im_04.png'])
labels = tf.constant([0, 1, 0, 1])
def parse_fn(file, label):
image = tf.image.decode_png(tf.read_file(file), channels=1)
shape_list = image.get_shape().as_list()
image_width = shape_list[0]
image_height = shape_list[1]
num_pieces = int(image_width/image_height)
Xy_pairs = []
for i in range(num_pieces):
offset_width = i * image_height
sub_image = tf.image.crop_to_bounding_box(image, 0, offset_width, image_height, image_height)
sub_image = tf.image.resize_images(sub_image, [128, 128])
Xy_pairs.append((sub_image, label))
return Dataset.from_tensor_slices(Xy_pairs)
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.flat_map(parse_fn)
sess = tf.InteractiveSession()
it = dataset.make_one_shot_iterator()
while True:
print('OUT: ' + it.get_next().eval())
The error looks like this TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
since tensorflow does not know the size of the images while computing the dataflow graph. Im pretty sure I need something like a placeholder for image.get_shape()
. I hope the community can help me with this.