Skip to content

Issue about keras.model.predict_classes #1

@ghost

Description

Hello, I'm currently working on making the algorithm working, still I have an issue at the end of the program about the predict_classes function in the last input.

I didn't change anything to the original code and imported all the modules specified in the requirement.
This is so the last input of the program.

folderName = "imdb_crop_resized128*128" 
fileNames =  glob.glob(folderName+"/*.jpg")
NumberOfFileToBetested = 500

x_batch,y_batch = turnToNumpy(fileNames[:NumberOfFileToBetested])

predictedAGE = model.predict_classes(x_batch)

realAGE = []
imagesCount = 0
os.mkdir('testImages')

for eachFilename in fileNames[:NumberOfFileToBetested]:
    realAGE = getRealAge(eachFilename)
    #saving Images
    x = load_image(eachFilename)
    x = x.reshape(x.shape[1],x.shape[2],x.shape[0])
    renamedImage = "testImages/"+str(realAGE)+"_"+str(predictedAGE[imagesCount])+".jpg"                                 
    imsave(renamedImage, x)
    imagesCount = imagesCount + 1

And there is the error specified. I don't know how to resolve this.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-7f653efe2f7b> in <module>()
      7 x_batch,y_batch = turnToNumpy(fileNames[:NumberOfFileToBetested])
      8 
----> 9 predictedAGE = model.predict_classes(x_batch)
     10 
     11 realAGE = []

~/Téléchargements/anaconda3/lib/python3.6/site-packages/keras/models.py in predict_classes(self, x, batch_size, verbose)
    824             A numpy array of class predictions.
    825         '''
--> 826         proba = self.predict(x, batch_size=batch_size, verbose=verbose)
    827         if proba.shape[-1] > 1:
    828             return proba.argmax(axis=-1)

~/Téléchargements/anaconda3/lib/python3.6/site-packages/keras/models.py in predict(self, x, batch_size, verbose)
    714         if self.model is None:
    715             self.build()
--> 716         return self.model.predict(x, batch_size=batch_size, verbose=verbose)
    717 
    718     def predict_on_batch(self, x):

~/Téléchargements/anaconda3/lib/python3.6/site-packages/keras/engine/training.py in predict(self, x, batch_size, verbose)
   1199         x = standardize_input_data(x, self.input_names,
   1200                                    self.internal_input_shapes,
-> 1201                                    check_batch_dim=False)
   1202         if self.stateful:
   1203             if x[0].shape[0] > batch_size and x[0].shape[0] % batch_size != 0:

~/Téléchargements/anaconda3/lib/python3.6/site-packages/keras/engine/training.py in standardize_input_data(data, names, shapes, check_batch_dim, exception_prefix)
     99                                  ' to have ' + str(len(shapes[i])) +
    100                                  ' dimensions, but got array with shape ' +
--> 101                                  str(array.shape))
    102             for j, (dim, ref_dim) in enumerate(zip(array.shape, shapes[i])):
    103                 if not j and not check_batch_dim:

ValueError: Error when checking : expected zeropadding2d_input_1 to have 4 dimensions, but got array with shape (0, 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions