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 Multilayer Perceptron (MLP) primitive for multi-class softmax classification #139

Closed
Hector-hedb12 opened this issue Mar 26, 2019 · 2 comments
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

@Hector-hedb12
Copy link
Contributor Author

I would like to work on this

@Hector-hedb12 Hector-hedb12 changed the title Add MLP primitive for multi-class softmax classification Add Multilayer Perceptron (MLP) primitive for multi-class softmax classification Mar 26, 2019
@csala csala added new primitives A new primitive is being requested approved The issue is approved and someone can start working on it labels Mar 26, 2019
@Hector-hedb12
Copy link
Contributor Author

Hector-hedb12 commented Mar 26, 2019

The architecture would be:

Dense (ReLU) layer ---> Dropout layer --> Dense (ReLU) layer ---> Dropout layer --> Dense (softmax) layer

You can find an example of this here in the Multilayer Perceptron (MLP) for multi-class softmax classification section:

import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD

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

model = Sequential()
# Dense(64) is a fully-connected layer with 64 hidden units.
# in the first layer, you must specify the expected input data shape:
# here, 20-dimensional vectors.
model.add(Dense(64, activation='relu', input_dim=20))
model.add(Dropout(0.5))
model.add(Dense(64, 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,
              metrics=['accuracy'])

model.fit(x_train, y_train,
          epochs=20,
          batch_size=128)
score = model.evaluate(x_test, y_test, batch_size=128)

@csala csala closed this as completed in #142 Apr 1, 2019
@csala csala added this to the 0.1.8 milestone Apr 1, 2019
@csala csala modified the milestones: 0.1.8, 0.1.9 Apr 25, 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

No branches or pull requests

2 participants