Skip to content
Advertisement

Reshaping problem (Input to reshape is a tensor with 10 values, but the requested shape has 1)

I’m trying to recreate this work using my own dataset: https://www.kaggle.com/code/amyjang/tensorflow-pneumonia-classification-on-x-rays/notebook

I’ve made some slight tweaks to the code to accommodate my data but I don’t think that is what is causing an issue here; it could be though of course.

My code:

JavaScript

And the error:

JavaScript

I can gather from the error that I have a mismatch in resizing, I believe it is pointing to the wrong place though and it is something to do with the line resizedImage = tf.image.resize(img, IMAGE_SIZE)

I’ve looked through the docs and on SO but I can’t find anything that might help me. I’ve tried debugging as best I can by printing things out on screen. I also tried changing the IMAGE_SIZE but that made no difference.

On the images, they are different sizes on disk, in JPG form. I expected that not to matter as we can use this step tot resize them for processing by the model later.

Other useful information is that I’m working on the pro version of Google Collab and the files are stored in a Google drive location. Again I don’t think that’s a problem or cause of anything; I’m trying to write things pre-emptively that people might ask.

Finally there is a prepare_for_training function in Amy’s code on Kaggle that is called before the last line I provided in my code above. I can trigger the same error without calling that function so I omitted it intentionally to help keep the example code cleaner. If you want to see it, here is a quick link to it in the notebook: https://www.kaggle.com/code/amyjang/tensorflow-pneumonia-classification-on-x-rays?scriptVersionId=39162263&cellId=26

Advertisement

Answer

May be the problem come from the get_label(path) method, since you are splitting path according the sep, it will return a list of many elements, make sure that you select only one element to perform test, try this :

JavaScript

i assume that the last element is the label, you just replace this index by the position of the label in this list.

Advertisement