Facenet: implementing facenet for variable size image, with batch with tf.train.batch_join, dynamic_pad = True

Created on 18 Apr 2017  路  2Comments  路  Source: davidsandberg/facenet

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.

  1. support variable size input, the code is like this

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?

  1. To convert variable size to fixed size for fully connected layer, I replace a max_pooling layer with Spatial Pyramid Pooling.

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

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arunxz98 picture arunxz98  路  3Comments

MaartenBloemen picture MaartenBloemen  路  3Comments

shdyn picture shdyn  路  4Comments

ouyangbei picture ouyangbei  路  4Comments

Leedonggeon picture Leedonggeon  路  3Comments