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
Avataryug-hs opened this issue Apr 25, 2024 · 3 comments
Open
Assignees
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@Avataryug-hs
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.

@Avataryug-hs
Copy link
Author

Avataryug-hs commented Apr 25, 2024 via email

@td-jakubl
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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