Last active
March 4, 2019 06:23
-
-
Save MTDzi/bb0908f5d7b46df47394159071d1854e to your computer and use it in GitHub Desktop.
Definition of the LeNet-like embedder
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
| def get_lenet_like_embedder( | |
| input_shape, | |
| act='elu', l2_reg=1e-3, filter_sz=5, num_filters=24, num_dense_neurons=512, | |
| ): | |
| """ | |
| Returns a 2-tuple of (input, embedding_layer) that can later be used | |
| to create a model that builds on top of the embedding_layer. | |
| """ | |
| inp = Input(input_shape) | |
| x = Conv2D(num_filters, (filter_sz, filter_sz), | |
| padding='same', kernel_regularizer=l2(l2_reg), | |
| activation=act)(inp) | |
| x = MaxPooling2D(2, 2)(x) | |
| x = Conv2D(2*num_filters, (filter_sz, filter_sz), | |
| padding='same', kernel_regularizer=l2(l2_reg), | |
| activation=act)(x) | |
| x = MaxPooling2D(2, 2)(x) | |
| x = Conv2D(4*num_filters, (filter_sz, filter_sz), | |
| padding='same', kernel_regularizer=l2(l2_reg), | |
| activation=act)(x) | |
| x = MaxPooling2D(2, 2)(x) | |
| x = Dropout(.5)(x) | |
| x = Flatten()(x) | |
| x = Dense(num_dense_neurons, kernel_regularizer=l2(l2_reg), activation=act)(x) | |
| x = Dropout(.5)(x) | |
| x = Dense(num_dense_neurons//2, kernel_regularizer=l2(l2_reg), activation=act)(x) | |
| emb = Dropout(.5)(x) | |
| return inp, emb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment