Milan
Milan

Reputation: 356

How to apply tf.image.per_image_standardization() to a tensor with the wrong shape?

I have a tensor of 10.000 pictures in 32x32x3 format. So the Tensor is D4 (shape (10000,32,32,3).

Tensor("...", shape=(10000, 32, 32, 3), dtype=float32)

Now i want to apply the tf.image.per_image_standardization operations to the individual images:

tf. image. per_image_standardization (...)

What is the best practice in this case? Maybe slice the tensor in 10000 tensors with the shape (32,32,3)?

Upvotes: 1

Views: 914

Answers (1)

nessuno
nessuno

Reputation: 27050

You can use tf.map_fn for applying a specified function to every element of a tensor (unrolling it from the first dimension):

import tensorflow as tf

a = tf.get_variable("a", (10000,32,32,3))
a = tf.map_fn(lambda x: tf.image.per_image_standardization(x), a, parallel_iterations=10000)
print(a.shape)

Upvotes: 2

Related Questions