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

Add VGG-like convnet primitive #149

Closed
Hector-hedb12 opened this issue Apr 4, 2019 · 0 comments · Fixed by #152
Closed

Add VGG-like convnet primitive #149

Hector-hedb12 opened this issue Apr 4, 2019 · 0 comments · Fixed by #152
Assignees
Labels
approved The issue is approved and someone can start working on it new primitives A new primitive is being requested
Milestone

Comments

@Hector-hedb12
Copy link
Contributor

Related to #121

The architecture would be:

Conv2D (relu) ---> Conv2D (relu) --> MaxPooling2D --> Dropout -->
  Conv2D (relu) ---> Conv2D (relu) --> MaxPooling2D --> Dropout -->
    Flatten --> Dense(relu) --> Dropout --> Dense (softmax)

You can find an example of this here in the VGG-like convnet section:

import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.optimizers import SGD

# Generate dummy data
x_train = np.random.random((100, 100, 100, 3))
y_train = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)
x_test = np.random.random((20, 100, 100, 3))
y_test = keras.utils.to_categorical(np.random.randint(10, size=(20, 1)), num_classes=10)

model = Sequential()
# input: 100x100 images with 3 channels -> (100, 100, 3) tensors.
# this applies 32 convolution filters of size 3x3 each.
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100, 3)))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd)

model.fit(x_train, y_train, batch_size=32, epochs=10)
score = model.evaluate(x_test, y_test, batch_size=32)
@csala csala added approved The issue is approved and someone can start working on it new primitives A new primitive is being requested labels Apr 4, 2019
@csala csala modified the milestones: 0.1.8, 0.1.9 Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved The issue is approved and someone can start working on it new primitives A new primitive is being requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants