Training, validation and test accuracy of model are fine.But all the predictions for test images results out...












0















I am working on creating a classifier to recognize the images belonging to a particular class. I have used transfer learning with ResNet50 to build my model. I have freezed all the layers and added the last layer. The total number of classes are 5. But all the test images give the prediction to be belonging to class 0. I am performing data augmentation on train and validation data before training.



base_model = ResNet50(weights='imagenet',include_top=False, input_shape = (img_width, img_height, 3)) 
# Top Model Block
u = base_model.output
u = GlobalAveragePooling2D()(u)
u = Dense(256, activation='relu', name='fc1')(u)
u = Dropout(0.5)(u)
predictions = Dense(nb_classes, activation='softmax', name='predictions')(u)

#freezing the layers
for layer in base_model.layers:
layer.trainable = False
#augmenting the train and validation data
train_datagen = ImageDataGenerator(rescale=1. / 255,

rotation_range=transformation_ratio,
shear_range=transformation_ratio,
zoom_range=transformation_ratio,
cval=transformation_ratio,
horizontal_flip=True,
vertical_flip=True)

validation_datagen = ImageDataGenerator(rescale=1. / 255)

#prediction report
predicted1 = model.predict(x1_test)

result: array([0, 0, 0, ..., 0, 0, 0])


My training accuracy is 72.9% and test accuracy is 72.6%
Note: Number of epochs = 10



Please advice me as to where am I going wrong!
Thanks in advance.










share|improve this question

























  • check how many no. of images belong to class 0. If more than 70% belongs to class 0, then model will do prediction like this. You should have a look on a concept 'Percision and Recall'.

    – Abdur Rehman
    Jan 2 at 9:24











  • I have 150 odd images belonging to class 0 out of 480 images. I have claculated the confusion matrix, according to which the precision is 1.0 and recall is 0.0. How can I solve this?

    – RB123
    Jan 2 at 9:40













  • I am not an expert in this. But one thing is, there is a trade-off between precision and recall. So, it all depends on your problem whether you want precision or recall to be high. Have a look at this article towardsdatascience.com/…

    – Abdur Rehman
    Jan 2 at 10:09











  • Provide more code, please. What is the model structure and the activations used? What is x1_test?

    – today
    Jan 2 at 19:07











  • I have stored the data in npy file and loaded the same and splitted the data into train,test and validation sets. x1 is the representation of the data. x1_train represents the training set.

    – RB123
    Jan 3 at 4:59
















0















I am working on creating a classifier to recognize the images belonging to a particular class. I have used transfer learning with ResNet50 to build my model. I have freezed all the layers and added the last layer. The total number of classes are 5. But all the test images give the prediction to be belonging to class 0. I am performing data augmentation on train and validation data before training.



base_model = ResNet50(weights='imagenet',include_top=False, input_shape = (img_width, img_height, 3)) 
# Top Model Block
u = base_model.output
u = GlobalAveragePooling2D()(u)
u = Dense(256, activation='relu', name='fc1')(u)
u = Dropout(0.5)(u)
predictions = Dense(nb_classes, activation='softmax', name='predictions')(u)

#freezing the layers
for layer in base_model.layers:
layer.trainable = False
#augmenting the train and validation data
train_datagen = ImageDataGenerator(rescale=1. / 255,

rotation_range=transformation_ratio,
shear_range=transformation_ratio,
zoom_range=transformation_ratio,
cval=transformation_ratio,
horizontal_flip=True,
vertical_flip=True)

validation_datagen = ImageDataGenerator(rescale=1. / 255)

#prediction report
predicted1 = model.predict(x1_test)

result: array([0, 0, 0, ..., 0, 0, 0])


My training accuracy is 72.9% and test accuracy is 72.6%
Note: Number of epochs = 10



Please advice me as to where am I going wrong!
Thanks in advance.










share|improve this question

























  • check how many no. of images belong to class 0. If more than 70% belongs to class 0, then model will do prediction like this. You should have a look on a concept 'Percision and Recall'.

    – Abdur Rehman
    Jan 2 at 9:24











  • I have 150 odd images belonging to class 0 out of 480 images. I have claculated the confusion matrix, according to which the precision is 1.0 and recall is 0.0. How can I solve this?

    – RB123
    Jan 2 at 9:40













  • I am not an expert in this. But one thing is, there is a trade-off between precision and recall. So, it all depends on your problem whether you want precision or recall to be high. Have a look at this article towardsdatascience.com/…

    – Abdur Rehman
    Jan 2 at 10:09











  • Provide more code, please. What is the model structure and the activations used? What is x1_test?

    – today
    Jan 2 at 19:07











  • I have stored the data in npy file and loaded the same and splitted the data into train,test and validation sets. x1 is the representation of the data. x1_train represents the training set.

    – RB123
    Jan 3 at 4:59














0












0








0








I am working on creating a classifier to recognize the images belonging to a particular class. I have used transfer learning with ResNet50 to build my model. I have freezed all the layers and added the last layer. The total number of classes are 5. But all the test images give the prediction to be belonging to class 0. I am performing data augmentation on train and validation data before training.



base_model = ResNet50(weights='imagenet',include_top=False, input_shape = (img_width, img_height, 3)) 
# Top Model Block
u = base_model.output
u = GlobalAveragePooling2D()(u)
u = Dense(256, activation='relu', name='fc1')(u)
u = Dropout(0.5)(u)
predictions = Dense(nb_classes, activation='softmax', name='predictions')(u)

#freezing the layers
for layer in base_model.layers:
layer.trainable = False
#augmenting the train and validation data
train_datagen = ImageDataGenerator(rescale=1. / 255,

rotation_range=transformation_ratio,
shear_range=transformation_ratio,
zoom_range=transformation_ratio,
cval=transformation_ratio,
horizontal_flip=True,
vertical_flip=True)

validation_datagen = ImageDataGenerator(rescale=1. / 255)

#prediction report
predicted1 = model.predict(x1_test)

result: array([0, 0, 0, ..., 0, 0, 0])


My training accuracy is 72.9% and test accuracy is 72.6%
Note: Number of epochs = 10



Please advice me as to where am I going wrong!
Thanks in advance.










share|improve this question
















I am working on creating a classifier to recognize the images belonging to a particular class. I have used transfer learning with ResNet50 to build my model. I have freezed all the layers and added the last layer. The total number of classes are 5. But all the test images give the prediction to be belonging to class 0. I am performing data augmentation on train and validation data before training.



base_model = ResNet50(weights='imagenet',include_top=False, input_shape = (img_width, img_height, 3)) 
# Top Model Block
u = base_model.output
u = GlobalAveragePooling2D()(u)
u = Dense(256, activation='relu', name='fc1')(u)
u = Dropout(0.5)(u)
predictions = Dense(nb_classes, activation='softmax', name='predictions')(u)

#freezing the layers
for layer in base_model.layers:
layer.trainable = False
#augmenting the train and validation data
train_datagen = ImageDataGenerator(rescale=1. / 255,

rotation_range=transformation_ratio,
shear_range=transformation_ratio,
zoom_range=transformation_ratio,
cval=transformation_ratio,
horizontal_flip=True,
vertical_flip=True)

validation_datagen = ImageDataGenerator(rescale=1. / 255)

#prediction report
predicted1 = model.predict(x1_test)

result: array([0, 0, 0, ..., 0, 0, 0])


My training accuracy is 72.9% and test accuracy is 72.6%
Note: Number of epochs = 10



Please advice me as to where am I going wrong!
Thanks in advance.







python keras






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 10:23







RB123

















asked Jan 2 at 9:05









RB123RB123

32




32













  • check how many no. of images belong to class 0. If more than 70% belongs to class 0, then model will do prediction like this. You should have a look on a concept 'Percision and Recall'.

    – Abdur Rehman
    Jan 2 at 9:24











  • I have 150 odd images belonging to class 0 out of 480 images. I have claculated the confusion matrix, according to which the precision is 1.0 and recall is 0.0. How can I solve this?

    – RB123
    Jan 2 at 9:40













  • I am not an expert in this. But one thing is, there is a trade-off between precision and recall. So, it all depends on your problem whether you want precision or recall to be high. Have a look at this article towardsdatascience.com/…

    – Abdur Rehman
    Jan 2 at 10:09











  • Provide more code, please. What is the model structure and the activations used? What is x1_test?

    – today
    Jan 2 at 19:07











  • I have stored the data in npy file and loaded the same and splitted the data into train,test and validation sets. x1 is the representation of the data. x1_train represents the training set.

    – RB123
    Jan 3 at 4:59



















  • check how many no. of images belong to class 0. If more than 70% belongs to class 0, then model will do prediction like this. You should have a look on a concept 'Percision and Recall'.

    – Abdur Rehman
    Jan 2 at 9:24











  • I have 150 odd images belonging to class 0 out of 480 images. I have claculated the confusion matrix, according to which the precision is 1.0 and recall is 0.0. How can I solve this?

    – RB123
    Jan 2 at 9:40













  • I am not an expert in this. But one thing is, there is a trade-off between precision and recall. So, it all depends on your problem whether you want precision or recall to be high. Have a look at this article towardsdatascience.com/…

    – Abdur Rehman
    Jan 2 at 10:09











  • Provide more code, please. What is the model structure and the activations used? What is x1_test?

    – today
    Jan 2 at 19:07











  • I have stored the data in npy file and loaded the same and splitted the data into train,test and validation sets. x1 is the representation of the data. x1_train represents the training set.

    – RB123
    Jan 3 at 4:59

















check how many no. of images belong to class 0. If more than 70% belongs to class 0, then model will do prediction like this. You should have a look on a concept 'Percision and Recall'.

– Abdur Rehman
Jan 2 at 9:24





check how many no. of images belong to class 0. If more than 70% belongs to class 0, then model will do prediction like this. You should have a look on a concept 'Percision and Recall'.

– Abdur Rehman
Jan 2 at 9:24













I have 150 odd images belonging to class 0 out of 480 images. I have claculated the confusion matrix, according to which the precision is 1.0 and recall is 0.0. How can I solve this?

– RB123
Jan 2 at 9:40







I have 150 odd images belonging to class 0 out of 480 images. I have claculated the confusion matrix, according to which the precision is 1.0 and recall is 0.0. How can I solve this?

– RB123
Jan 2 at 9:40















I am not an expert in this. But one thing is, there is a trade-off between precision and recall. So, it all depends on your problem whether you want precision or recall to be high. Have a look at this article towardsdatascience.com/…

– Abdur Rehman
Jan 2 at 10:09





I am not an expert in this. But one thing is, there is a trade-off between precision and recall. So, it all depends on your problem whether you want precision or recall to be high. Have a look at this article towardsdatascience.com/…

– Abdur Rehman
Jan 2 at 10:09













Provide more code, please. What is the model structure and the activations used? What is x1_test?

– today
Jan 2 at 19:07





Provide more code, please. What is the model structure and the activations used? What is x1_test?

– today
Jan 2 at 19:07













I have stored the data in npy file and loaded the same and splitted the data into train,test and validation sets. x1 is the representation of the data. x1_train represents the training set.

– RB123
Jan 3 at 4:59





I have stored the data in npy file and loaded the same and splitted the data into train,test and validation sets. x1 is the representation of the data. x1_train represents the training set.

– RB123
Jan 3 at 4:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003642%2ftraining-validation-and-test-accuracy-of-model-are-fine-but-all-the-predictions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003642%2ftraining-validation-and-test-accuracy-of-model-are-fine-but-all-the-predictions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith