Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Wrong output even though vgg16 model showing 95% val_accuracy #19612

Open
novabyte-games opened this issue Apr 25, 2024 · 4 comments
Open
Assignees
Labels
stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@novabyte-games
Copy link

In this project i have been trying to classify 3 hairstyles - Braided , curly and straight …i am using transfer learning to classify the images … vvg16 model is giving roughly same training and testing accuracy … but when trying to predict actual image , its giving wrong result ( predicting different class)…
My Dataset is roughly 400 images for training and 100 for testing ( all are evenly divided )

Please suggest something , and help me out
Attaching model code -
`from keras.applications import VGG16

Load the pre-trained VGG16 model without the top (fully connected) layers

base_model = VGG16(weights='imagenet', include_top=False, input_shape=(224, 224, 3))

Freeze the base model layers so they are not trainable

for layer in base_model.layers:
layer.trainable = False

Create a new model by adding custom top layers on top of the base model

model = Sequential()
model.add(base_model)
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.20))
model.add(Dense(3, activation='softmax')) # Assuming 3 classes

Compile the model

model.compile(optimizer='Adam', loss='categorical_crossentropy', metrics=['accuracy'])

Print the model summary

model.summary()`

@SuryanarayanaY SuryanarayanaY added the type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. label Apr 25, 2024
@SuryanarayanaY
Copy link
Collaborator

Hi @Avataryug-hs ,

Since you are using same dataset for training and testing and getting good val_accuracy also I would except the model to perform well. If you are using a new dataset for predictions and not getting good accuracy that means either the new dataset is having different probability distribution or trained model might be overfitting.

@novabyte-games
Copy link
Author

novabyte-games commented Apr 25, 2024 via email

@td-jakubl
Copy link
Contributor

Could you provide code for loading and creating datasets and for model's predictions?

@SuryanarayanaY
Copy link
Collaborator

Hi I am not using same dataset for training and testing, both contain different images, also trained model is not overfitting by the graph i got , loss functions are seeming to decrease .. attaching the screenshot . [cid:5480370a-567d-47b4-acd3-d894c58cbced]

________________________________ From: Surya @.> Sent: 25 April 2024 09:52 AM To: keras-team/keras @.> Cc: Harsh Shinde @.>; Mention @.> Subject: Re: [keras-team/keras] Getting Wrong output even though vgg16 model showing 95% val_accuracy (Issue #19612) Hi @Avataryug-hshttps://github.com/Avataryug-hs , Since you are using same dataset for training and testing and getting good val_accuracy also I would except the model to perform well. If you are using a new dataset for predictions and not getting good accuracy that means either the new dataset is having different probability distribution or trained model might be overfitting. — Reply to this email directly, view it on GitHub<#19612 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BG7XZS44RUKSAK5VPAKCZY3Y7CAJHAVCNFSM6AAAAABGYCGWKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZWGMZTEMRVGU. You are receiving this because you were mentioned.Message ID: @.***>

Could you please provide some dummy dataset along with reproducible code snippet?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

3 participants