I am trying to call tf.image.random_crop(image, size=INPUT_SHAPE)
and I get this error:
ValueError: Dimensions must be equal, but are 4 and 3 for '{{node random_crop/GreaterEqual}} = GreaterEqual[T=DT_INT32](random_crop/Shape, random_crop/size)' with input shapes: [4], [3].
So while I was trying to understand what was going on, I tried printing the shape of my dataset with
print(len(train_dataset), train_dataset)
and I got this:
23 <BatchDataset element_spec=(TensorSpec(shape=(None, 160, 160, 1), dtype=tf.float32, name=None), TensorSpec(shape=(None,), dtype=tf.int32, name=None))>
First, I don't understand the number 23 and more concerning is the TensorSpec(shape=(None, 160, 160, 1). My INPUT_SHAPE is (160, 160, 1) so I am wondering if that's what's causing the problem.
I saw a thread that said I should change the batch size to 1 but that didn't work out for me. Right now, I have no batch size for the dataset at all
CodePudding user response:
Looks like you are applying random_crop
after batch. For the above to work you need to set INPUT_SHAPE = (batch_size, 120, 120,3)
or you can batch after applying random_crop
.