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

unable to train VGG16 #28

Open
efferre99 opened this issue Oct 9, 2018 · 1 comment
Open

unable to train VGG16 #28

efferre99 opened this issue Oct 9, 2018 · 1 comment

Comments

@efferre99
Copy link

train_path='train'
valid_path='valid'
test_path='test'
#batches for train, valid and test set
train_batches=ImageDataGenerator(rescale =
1./255).flow_from_directory(train_path,target_size=(224,224),classes=
['dog','cat'], batch_size=10)
valid_batches=ImageDataGenerator(rescale =
1./255).flow_from_directory(valid_path,target_size=(224,224),classes=
['dog','cat'], batch_size=10)
test_batches=ImageDataGenerator(rescale =
1./255).flow_from_directory(test_path,target_size=(224,224),classes=
['dog','cat'], batch_size=10)
#build CNN
input_shape = (224, 224, 3)

model=Sequential()
model.add(Conv2D(64, (3, 3), input_shape=(224,224,3),
activation='relu',padding='same'))
model.add(Conv2D(64, (3, 3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, (3, 3),activation='relu',padding='same'))
model.add(Conv2D(128, (3, 3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3),activation='relu',padding='same'))
model.add(Conv2D(256, (3, 3),activation='relu',padding='same'))
model.add(Conv2D(256, (3, 3),activation='relu',padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3),activation='relu',padding='same'))
model.add(Conv2D(512, (3, 3),activation='relu',padding='same'))
model.add(Conv2D(512, (3, 3),activation='relu',padding='same'))
model.add(Flatten())
model.add(Dense(4096, activation='relu'))
model.add(Dense(4096, activation='relu'))

model.add(Dense(2,activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=
['accuracy'])

model.fit_generator(train_batches,steps_per_epoch=3,validation_data=valid_batches,validation_steps=3, epochs=5,verbose=2)
The code above is VGG16 model that classifies cats and dogs, but when I train the network I still get accuracy 0.5, why?

106s - loss: 3.9315 - acc: 0.4333 - val_loss: 8.0151 - val_acc: 0.5000
I've already used the pretrained model and it worked, but now it doesn't work

@martin-gorner
Copy link
Contributor

This collection of samples does not contain a sample of VGG16. Could you please add more information about the piece of code you are commenting on ? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants