{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using TensorFlow backend.\n" ] } ], "source": [ "import numpy as np\n", "from keras.models import Model\n", "from keras.layers import Input\n", "from keras.layers.core import RepeatVector\n", "from keras import backend as K" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def format_decimal(arr, places=6):\n", " return [round(x * 10**places) / 10**places for x in arr]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### RepeatVector" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**[core.RepeatVector.0] repeat vector, shape [6] -> [7, 6]**" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "in: [0, 0.2, 0.5, -0.1, 1, 2]\n", "in shape: (6,)\n", "out shape: (7, 6)\n", "out: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0]\n" ] } ], "source": [ "layer_0 = Input(shape=(6,))\n", "layer_1 = RepeatVector(7)(layer_0)\n", "model = Model(input=layer_0, output=layer_1)\n", "\n", "data_in = [0, 0.2, 0.5, -0.1, 1, 2]\n", "data_in_shape = (6,)\n", "print('in:', data_in)\n", "print('in shape:', data_in_shape)\n", "arr_in = np.array(data_in, dtype='float32').reshape(data_in_shape)\n", "result = model.predict(np.array([arr_in]))\n", "arr_out = result[0]\n", "print('out shape:', arr_out.shape)\n", "data_out = format_decimal(arr_out.ravel().tolist())\n", "print('out:', data_out)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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": 0 }