Last active
August 16, 2016 20:35
-
-
Save bwallace/25d34f65ec4ea8f8e540eeb2edc27176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = Input(shape=(2,)) | |
probs = Dense(2, activation='softmax', name='probs')(input) | |
probs = Dropout(1e-100)(probs) | |
model = Model(input=input, output=probs) | |
model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy']) | |
from keras.utils.np_utils import to_categorical | |
X, y = np.array([[1, 2], [3, 4]]), to_categorical([1, 0]) | |
model.fit(X, y, validation_data=[X, y]) | |
probas = model.get_layer('probs') | |
import keras.backend as K | |
f = K.function(inputs=model.inputs + [K.learning_phase()], outputs=[probas.output]) | |
# test mode = 0, train mode = 1 | |
f(inputs=[X, 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment