How to reproduce the error 'InvalidArgumentError : expected multiples argument to be a vector of length 2 but got length 3' while using tf.tile

Viewed 2200

I implemented some code with tf.tile and got this error message:

InvalidArgumentError : expected multiples argument to be a vector of length 2 but got length 3

The code is quite complicated and I can't directly find out what caused the error. So I made some dummy codes to reproduce the error, so that I may understand which value was the source of the error. However, I can't figure out how to reproduce this error with dummy code.

I tried to do it like this:

import tensorflow as tf
a = tf.constant([[1,2,3],[2,3,4]])
b = tf.tile(a, [1,1,3])

This gives me error the message:

Shape must be rank 2 but is rank 3 for 'Tile_0' with input shapes:~~

Can anybody provide some example code that can reproduce my original error?

1 Answers

After four years, I suspect a direct solution won't be useful, so here's a general explanation for the other 2,000 people that have viewed this in the meantime!

From the documentation:

This operation creates a new tensor by replicating input multiples times. The output tensor's i'th dimension has input.dims(i) * multiples[i] elements, and the values of input are replicated multiples[i] times along the 'i'th dimension. For example, tiling [a b c d] by [2] produces [a b c d a b c d].

Your a vector is a rank-2 tensor, so tf.tiles expects multiples to have 2 elements, but your multiples has 3 elements. You must match a's dimension with the length of multiples.

Related