Training, validation and test accuracy of model are fine.But all the predictions for test images results out...
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
add a comment |
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
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 isx1_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
add a comment |
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
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
python keras
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 isx1_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
add a comment |
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 isx1_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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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