Skip to content

Instantly share code, notes, and snippets.

@kgrm
Created April 25, 2017 08:15
Show Gist options
  • Save kgrm/141da3d672bb4ef01464ddcf070ddbd6 to your computer and use it in GitHub Desktop.
Save kgrm/141da3d672bb4ef01464ddcf070ddbd6 to your computer and use it in GitHub Desktop.
fixed theano deconv example
import numpy as np
from keras.models import Sequential
from keras.layers import Deconv2D, Lambda
def cropped_shape(inshape):
samples, ch, w, h = inshape
return (samples, ch, w - 2, h - 2)
mdl = Sequential()
mdl.add(Deconv2D(256, input_shape=(1, 7, 7), padding='valid', kernel_size=4, strides=2, data_format="channels_first"))
mdl.add(Lambda(lambda x: x[:, :, 1:-1, 1:-1], output_shape=cropped_shape))
mdl.summary()
mdl.compile(loss='mse', optimizer='sgd')
x = np.random.normal(size=(1,1,7,7))
y = mdl.predict_on_batch(x)
print y.shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment