Created
December 9, 2017 00:52
-
-
Save ruslangrimov/7a76dd9761205ea11354b27759070111 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from keras import optimizers | |
from keras import losses | |
import numpy as np | |
input_img_data = np.random.random((1,) + K.int_shape(model.inputs[0])[1:]) | |
input_img = K.variable(input_img_data) | |
inp = Input(tensor=input_img, batch_shape=input_img_data.shape) | |
out = model(inp) | |
y_true = np.zeros((1, 10,)) | |
y_true[:, 5] = 1.0 | |
loss = losses.categorical_crossentropy(y_true, out) | |
#loss = K.mean(K.square(out - y_true)) | |
opt = optimizers.SGD(nesterov=True, momentum=0.8, lr=10.0) | |
#opt = optimizers.Adam(lr=0.5) | |
updates = opt.get_updates([input_img], [], loss) | |
iterate = K.function([K.learning_phase()], [loss], updates) | |
for i in range(20): | |
loss_value = iterate([False])[0] | |
print('Current loss value:', loss_value) | |
input_img_data = K.get_value(input_img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment