Validation Accuracy shown during epochs much higher than what I actually get
I am new to Keras and CNN and therefore struggling with the following.
When I train using image dataset using the follwing code:
train_batches = gen1.flow_from_directory(train_path, target_size=(224,224),classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
valid_batches = gen1.flow_from_directory(valid_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
test_batches = gen1.flow_from_directory(test_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=( 224, 224, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(3))
model.add(Activation('softmax'))
model.compile(optimizer=Adam(lr=.0001), loss= 'categorical_crossentropy', metrics = ['accuracy'])
history = model.fit_generator(train_batches, steps_per_epoch =training_data_size//batch, validation_data = valid_batches, validation_steps=validation_data_size//batch, epochs=5, verbose=2)
model.save_weights('Try1.h5')
I get the 77% validation accuracy after 5 epochs as can be seen in the pic :
enter image description here
But when I try to create a confusion matrix for it using I get 35% validation accuracy:
predictions = model.predict_generator(valid_batches, steps=validation_data_size//batch,verbose=1)
conf_mat2 = confusion_matrix(valid_batches.classes, np.argmax(predictions,axis=1))
keras conv-neural-network
add a comment |
I am new to Keras and CNN and therefore struggling with the following.
When I train using image dataset using the follwing code:
train_batches = gen1.flow_from_directory(train_path, target_size=(224,224),classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
valid_batches = gen1.flow_from_directory(valid_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
test_batches = gen1.flow_from_directory(test_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=( 224, 224, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(3))
model.add(Activation('softmax'))
model.compile(optimizer=Adam(lr=.0001), loss= 'categorical_crossentropy', metrics = ['accuracy'])
history = model.fit_generator(train_batches, steps_per_epoch =training_data_size//batch, validation_data = valid_batches, validation_steps=validation_data_size//batch, epochs=5, verbose=2)
model.save_weights('Try1.h5')
I get the 77% validation accuracy after 5 epochs as can be seen in the pic :
enter image description here
But when I try to create a confusion matrix for it using I get 35% validation accuracy:
predictions = model.predict_generator(valid_batches, steps=validation_data_size//batch,verbose=1)
conf_mat2 = confusion_matrix(valid_batches.classes, np.argmax(predictions,axis=1))
keras conv-neural-network
add a comment |
I am new to Keras and CNN and therefore struggling with the following.
When I train using image dataset using the follwing code:
train_batches = gen1.flow_from_directory(train_path, target_size=(224,224),classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
valid_batches = gen1.flow_from_directory(valid_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
test_batches = gen1.flow_from_directory(test_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=( 224, 224, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(3))
model.add(Activation('softmax'))
model.compile(optimizer=Adam(lr=.0001), loss= 'categorical_crossentropy', metrics = ['accuracy'])
history = model.fit_generator(train_batches, steps_per_epoch =training_data_size//batch, validation_data = valid_batches, validation_steps=validation_data_size//batch, epochs=5, verbose=2)
model.save_weights('Try1.h5')
I get the 77% validation accuracy after 5 epochs as can be seen in the pic :
enter image description here
But when I try to create a confusion matrix for it using I get 35% validation accuracy:
predictions = model.predict_generator(valid_batches, steps=validation_data_size//batch,verbose=1)
conf_mat2 = confusion_matrix(valid_batches.classes, np.argmax(predictions,axis=1))
keras conv-neural-network
I am new to Keras and CNN and therefore struggling with the following.
When I train using image dataset using the follwing code:
train_batches = gen1.flow_from_directory(train_path, target_size=(224,224),classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
valid_batches = gen1.flow_from_directory(valid_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
test_batches = gen1.flow_from_directory(test_path, target_size=(224,224), classes = ['garbage', 'recycled', 'organic'], batch_size = batch)
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=( 224, 224, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(3))
model.add(Activation('softmax'))
model.compile(optimizer=Adam(lr=.0001), loss= 'categorical_crossentropy', metrics = ['accuracy'])
history = model.fit_generator(train_batches, steps_per_epoch =training_data_size//batch, validation_data = valid_batches, validation_steps=validation_data_size//batch, epochs=5, verbose=2)
model.save_weights('Try1.h5')
I get the 77% validation accuracy after 5 epochs as can be seen in the pic :
enter image description here
But when I try to create a confusion matrix for it using I get 35% validation accuracy:
predictions = model.predict_generator(valid_batches, steps=validation_data_size//batch,verbose=1)
conf_mat2 = confusion_matrix(valid_batches.classes, np.argmax(predictions,axis=1))
keras conv-neural-network
keras conv-neural-network
asked Nov 11 at 15:47
vaibhav gupta
11
11
add a comment |
add a comment |
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%2f53250410%2fvalidation-accuracy-shown-during-epochs-much-higher-than-what-i-actually-get%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53250410%2fvalidation-accuracy-shown-during-epochs-much-higher-than-what-i-actually-get%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