Created
January 5, 2017 20:51
-
-
Save rjpower/21440c04d147773e646e13dfadfcb7a5 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import keras.backend as K\n", | |
"from keras.models import Model\n", | |
"from keras.layers import Layer, Input" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 41, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"class MultiOutputLayer(Layer):\n", | |
" def get_output_shape_for(self, input_shape):\n", | |
" return [input_shape, input_shape]\n", | |
" \n", | |
" def compute_mask(self, inputs, masks):\n", | |
" return [None, None]\n", | |
"\n", | |
" def call(self, x, mask=None):\n", | |
" return [x + 1, x - 1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 45, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"input = Input(shape=(10,))\n", | |
"parts = MultiOutputLayer(name='2-output')(input)\n", | |
"model = Model(name='foo', input=[input], output=parts)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 46, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[array([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]], dtype=float32),\n", | |
" array([[-1., 0., 1., 2., 3., 4., 5., 6., 7., 8.]], dtype=float32)]" | |
] | |
}, | |
"execution_count": 46, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"model.predict([np.arange(10).reshape((1, 10))])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment