av1 = GlobalAveragePooling2D()(model.output)
fc1 = Dense(256,activation=‘relu’)(av1)
d1 = Dropout(0.5)(fc1)
fc2 = Dense(4,activation=‘softmax’)(d1)
model_new = Model(inputs=model.input, outputs= fc2)
model_new.summary()
adam = Adam(lr=0.00003)
model_new.compile(loss=‘categorical_crossentropy’, optimizer=adam, metrics=[‘accuracy’])
hist = model_new.fit(X_train,Y_train,
shuffle = True,
batch_size = 16,
epochs = 5,
validation_split=0.20
)
from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
import matplotlib.pyplot as plt
img_path = ‘elephant.png’
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
plt.imshow(x[0])
preds = model_new.predict(x[0])
decode the results into a list of tuples (class, description, probability)
(one such list for each sample in the batch)
print(‘Predicted:’, decode_predictions(preds, top=3)[0])
why i am getting error shown below while predicting?
what should i do for predicting single image?
error:
ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (224, 224, 3)