Hi David @davidsandberg , I am implementing facenet using your existing code. I want to support variable size input. What I have done is two steps.
for _ in range(nrof_preprocess_threads):
filenames, label = input_queue.dequeue()
print (filenames)
images = []
for filename in tf.unpack(filenames):
file_contents = tf.read_file(filename)
image = tf.image.decode_png(file_contents)
# if args.random_crop:
# image = tf.random_crop(image, [args.image_size_height, args.image_size_width, 1])
# else:
# image = tf.image.resize_image_with_crop_or_pad(image, args.image_size_height, args.image_size_width)
# if args.random_flip:
# image = tf.image.random_flip_left_right(image)
# image_shape = tf.shape(image)
# tmp_height = tf.cast(tf.gather(image_shape,1),tf.int32)
# tmp_width = tf.cast(tf.gather(image_shape,2),tf.int32)
# print(tmp_height)
#resized_image = tf.image.resize_images(image, [299, 299])
#pylint: disable=no-member
image.set_shape((None, None, 1))
images.append(tf.image.per_image_standardization(image))
images_and_labels.append([images, label])
image_batch, label_batch = tf.train.batch_join(
images_and_labels, batch_size=batch_size_placeholder, capacity=4 * nrof_preprocess_threads * args.batch_size, enqueue_many=True,
shapes=[(None,None,1),()],dynamic_pad=True,
allow_smaller_final_batch=True)
I just set the dynamic_pad=True, and shapes=[(None,None,1),()] to do dynamic padding within a batch .
However, I got Error at runtime, saying that the dimension is not the same, like below:
ERROR:tensorflow:Exception in QueueRunner: Shapes of all inputs must match: values[0].shape = [160,196,1] != values[1].shape = [160,205,1]
[[Node: batch_join/packed = Pack[N=3, T=DT_FLOAT, axis=0, _device="/job:localhost/replica:0/task:0/gpu:0"](Div, Div_1, Div_2)]]
[[Node: batch_join/packed/_17 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_80_batch_join/packed", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Do you have some experience about variable size images in Tensorflow?
Chunlei
I get the feeling that you would actually want to use tf.pad. Have you tried that one?
I actually solved the problem by setting
"image_paths_placeholder = tf.placeholder(tf.string, shape=(None,1), name='image_paths')
labels_placeholder = tf.placeholder(tf.int64, shape=(None,1), name='labels')"
Instead of
"image_paths_placeholder = tf.placeholder(tf.string, shape=(None,3), name='image_paths')
labels_placeholder = tf.placeholder(tf.int64, shape=(None,3), name='labels')"
and set thread to 1, so that the triplet list order is the same. And then apply tf.train.batch_join with dynamic_pad won't cause any issue.
Thanks,
Chunlei
Most helpful comment
I actually solved the problem by setting
"image_paths_placeholder = tf.placeholder(tf.string, shape=(None,1), name='image_paths')
labels_placeholder = tf.placeholder(tf.int64, shape=(None,1), name='labels')"
Instead of
"image_paths_placeholder = tf.placeholder(tf.string, shape=(None,3), name='image_paths')
labels_placeholder = tf.placeholder(tf.int64, shape=(None,3), name='labels')"
and set thread to 1, so that the triplet list order is the same. And then apply tf.train.batch_join with dynamic_pad won't cause any issue.
Thanks,
Chunlei