Beverlie
Beverlie

Reputation: 461

ValueError: setting an array element with a sequence with Tensorflow

I am trying to reproduce the deep video portrait (2018) and they are referring Isola (2017) which implements patchGAN.

In patchGAN, the discriminator returns [batch_size, patch_width, patch_height, 1] of tensor and I'd like to feed this tensor to my loss defined as following:

EcGAN = tf.reduce_mean(tf.log(D_real)+ tf.log(np.float32(1. - D_fake))) 

So I comprised following pseudo operation checker and run:

sheudo_input = tf.Variable(np.float32(np.random.uniform(low=-1., high=1., size=[16, 30, 30, 1]))) 
EcGAN = tf.reduce_mean(tf.log(sheudo_input)+ tf.log(np.float32(1. - sheudo_input))) 

But EcGAN not computed and reutrns error like this:

ValueError: setting an array element with a sequence.

What would be the possible promblem and how to solve it?

Upvotes: 1

Views: 142

Answers (1)

cs95
cs95

Reputation: 402263

The np.float32 call is the problem. Numpy functions don't play nice with tensors unless on eager execution mode.

When attempting to cast, you should use tf.cast. Or in this case, the result should be a float anyway, so this is enough:

tf.log(sheudo_input) + tf.log(1. - sheudo_input)

Upvotes: 2

Related Questions