-1

I am trying to train a multi-scale CNN some kind like YOLOv2 in Tensorflow: to randomly resize the batch of inputs every several epochs. But I am not so familiar with Tensorflow, the following is how I get batches of images and labels:

data_provider = slim.dataset_data_provider.DatasetDataProvider(dataset)
image, label = data_provider.get(['image', 'label'])
inputs, labels = tf.train.shuffle_batch([image, label], \
                                    batch_size=128, \
                                    num_threads=4,  \
                                    capacity= 1000, \
                                    min_after_dequeue=616)

Then I hope I can resize the batch of inputs and feed into network

rand_size=int(np.random.uniform(0.15,1)*720)
resize_output = tf.image.resize_bilinear(preprocessed_inputs, [rand_size,rand_size],align_corners=True)

Unfortunately, it does not work, it only resize the batch at the beginning, and apply the resize operation to all the inputs

Anyone have suggestions for what I should do? Thanks a lot

wyczhu
  • 1

1 Answers1

0

You want rand_size to be based on a tf.random_uniform rather than numpy/int, otherwise it will have the same value for each run of your session.

rand_size = tf.random_uniform(
    minval=int(0.15*720), maxval=720, dtype=tf.int32, shape=())

This will still resize each element of the batch by the same amount.

I'm not familiar with how slim does preprocessing, but there'd be something in there that allows you to do the above before batching (in which case you'd get a different random value each time). Alternatively look into using the more recently released tf.data.Dataset. This post might help you there.

DomJack
  • 4,098
  • 1
  • 17
  • 32