0

I have a batch of 10 images, which gives the size (10, 224, 224, 3), I want to create a larger image of size (2240, 224, 3).

import tensorflow as tf

x = tf.random.uniform(minval=0, maxval=1, shape=(100, 224, 224, 3), dtype=tf.float32)

ds = tf.data.Dataset.from_tensor_slices(x).batch(10)

My desired output:

TensorShape([2240, 224, 3])

If I use tf.concatenate I get

ValueError: Cannot infer num from shape (None, 224, 224, 3)

Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143

1 Answers1

0

You could use tf.split() instead and build your new image using the following code.

import tensorflow as tf

x = tf.random.uniform(minval=0, maxval=1, shape=(100, 224, 224, 3), dtype=tf.float32)

ds = tf.data.Dataset.from_tensor_slices(x).batch(10)

ds = ds.map(lambda x: tf.concat(tf.split(x, 10, 0), axis=1))

output:

<MapDataset shapes: (None, 2240, 224, 3), types: tf.float32>
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
Srihari Humbarwadi
  • 2,532
  • 1
  • 10
  • 28
  • I'm really thankful for your answer. This unfortunately did not work for me because I had a `batch` operation before, and it gave me [this](https://stackoverflow.com/questions/43074435/unpackunstack-an-input-placeholder-with-one-none-dimension-in-tensorflow) error. What ended up working is: `map(lambda x, y: (tf.concat(tf.split(x, 10, 0), axis=1), y)` – Nicolas Gervais Jul 06 '20 at 11:39
  • You can update your question with the batch operation! – Srihari Humbarwadi Jul 06 '20 at 12:48
  • 1
    Excellent idea. I edited your answer too, because you answered well given my question, which needed more info. Feel free to double check, since I changed your solution! – Nicolas Gervais Jul 06 '20 at 12:56