{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "<img width=\"800px\" src=\"../fidle/img/header.svg\"></img>\n", "\n", "# <!-- TITLE --> [K3LSTM1] - Basic Keras LSTM Layer\n", "<!-- DESC --> A small example of an LSTM layer in Keras\n", "\n", "<!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.environ['KERAS_BACKEND'] = 'torch'\n", "\n", "import keras\n", "\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "input = keras.random.normal( [32, 20, 8] )\n", "\n", "lstm = keras.layers.LSTM(16)\n", "output = lstm(input)\n", "\n", "print('input shape is : ',input.shape)\n", "print('output shape is : ',output.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "input = keras.random.normal( [32, 20, 8] )\n", "\n", "lstm = keras.layers.LSTM(18, return_sequences=True, return_state=True)\n", "output, memory_state, carry_state = lstm(input)\n", "\n", "print('input shape : ',input.shape)\n", "print('output shape : ',output.shape)\n", "print('memory_state : ', memory_state.shape)\n", "print('carry_state : ', memory_state.shape)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "<img width=\"80px\" src=\"../fidle/img/logo-paysage.svg\"></img>" ] } ], "metadata": { "kernelspec": { "display_name": "fidle-env", "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.9.2" } }, "nbformat": 4, "nbformat_minor": 2 }