rnn

Tensorflow之RNN,LSTM

青春壹個敷衍的年華 提交于 2019-12-25 00:33:48
Tensorflow之RNN,LSTM #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ tensorflow之RNN 循环神经网络做手写数据集分类 """ import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #设置随机数来比较两种计算结果 tf.set_random_seed(1) #导入手写数据集 mnist = input_data.read_data_sets('MNIST_data', one_hot=True) #设置参数 lr = 0.001 training_iters = 100000 batch_size = 128 n_inputs = 28 # MNIST 输入为图片(img shape: 28*28)对应到图片像素的一行 n_steps = 28 # time steps 对应到图片有多少列 n_hidden_units = 128 # 隐藏层神经元个数 n_classes = 10 # MNIST分类结果为10 #定义权重 weights = { #(28,128) 'in': tf.Variable(tf.random_normal([n_inputs, n_hidden_units]))

Setting up the input on an RNN in Keras

十年热恋 提交于 2019-12-23 04:29:12
问题 So I had a specific question with setting up the input in Keras. I understand that the sequence length refers to the window length of the longest sequence that you are looking to model with the rest being padded by 0's. However, how do I set up something that is already in a time series array? For example, right now I have an array that is 550k x 28. So there are 550k rows each with 28 columns (27 features and 1 target). Do I have to manually split the array into (550k- sequence length)

Setting up the input on an RNN in Keras

主宰稳场 提交于 2019-12-23 04:29:08
问题 So I had a specific question with setting up the input in Keras. I understand that the sequence length refers to the window length of the longest sequence that you are looking to model with the rest being padded by 0's. However, how do I set up something that is already in a time series array? For example, right now I have an array that is 550k x 28. So there are 550k rows each with 28 columns (27 features and 1 target). Do I have to manually split the array into (550k- sequence length)

implementing RNN with numpy

我只是一个虾纸丫 提交于 2019-12-22 04:04:35
问题 I'm trying to implement the recurrent neural network with numpy. My current input and output designs are as follow: x is of shape: (sequence length, batch size, input dimension) h : (number of layers, number of directions, batch size, hidden size) initial weight : (number of directions, 2 * hidden size, input size + hidden size) weight : (number of layers -1, number of directions, hidden size, directions*hidden size + hidden size) bias : (number of layers, number of directions, hidden size) I

tensorflow static_rnn error: input must be a sequence

萝らか妹 提交于 2019-12-21 20:36:57
问题 I'm trying to feed my own 3D data to a LSTM. The data have: height = 365, width = 310, time = unknown / inconsistent, consist of 0 and 1, each block of data that produce an output are separated to a single file. import tensorflow as tf import os from tensorflow.contrib import rnn filename = "C:/Kuliah/EmotionRecognition/Train1/D2N2Sur.txt" hm_epochs = 10 n_classes = 12 n_chunk = 443 n_hidden = 500 data = tf.placeholder(tf.bool, name='data') cat = tf.placeholder("float", [None, n_classes])

【tensorflow】static_rnn与dynamic_rnn的区别

断了今生、忘了曾经 提交于 2019-12-19 05:00:58
static_rnn和dynamic_rnn的区别主要在于实现不同。 static_rnn会把RNN展平,用空间换时间。 gpu会吃不消(个人测试结果) dynamic_rnn则是使用for或者while循环。 调用static_rnn实际上是生成了rnn按时间序列展开之后的图。打开tensorboard你会看到sequence_length个rnn_cell stack在一起,只不过这些cell是share weight的。因此,sequence_length就和图的拓扑结构绑定在了一起,因此也就限制了每个batch的sequence_length必须是一致。 调用dynamic_rnn不会将rnn展开,而是利用tf.while_loop这个api,通过Enter, Switch, Merge, LoopCondition, NextIteration等这些control flow的节点,生成一个可以执行循环的图(这个图应该还是静态图,因为图的拓扑结构在执行时是不会变化的)。在tensorboard上,你只会看到一个rnn_cell, 外面被一群control flow节点包围着。对于dynamic_rnn来说,sequence_length仅仅代表着循环的次数,而和图本身的拓扑没有关系,所以每个batch可以有不同sequence_length。 static_rnn 导包

RNN(LSTM)的Tensorflow实现源码

倾然丶 夕夏残阳落幕 提交于 2019-12-19 04:24:22
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the

Keras reports TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

匆匆过客 提交于 2019-12-18 06:06:42
问题 I'm a beginner in Keras and just write a toy example. It reports a TypeError . The code and error are as follows: Code: inputs = keras.Input(shape=(3, )) cell = keras.layers.SimpleRNNCell(units=5, activation='softmax') label = keras.layers.RNN(cell)(inputs) model = keras.models.Model(inputs=inputs, outputs=label) model.compile(optimizer='rmsprop', loss='mae', metrics=['acc']) data = np.array([[1, 2, 3], [3, 4, 5]]) labels = np.array([1, 2]) model.fit(x=data, y=labels) Error: Traceback (most

tf.nn.dynamic_rnn的输出outputs和state含义

好久不见. 提交于 2019-12-16 21:53:45
tf.nn.dynamic_rnn的输出outputs和state含义 一、 tf.nn.dynamic_rnn的输出 tf.nn.dynamic_rnn( cell, inputs, sequence_length=None, initial_state=None, dtype=None, parallel_iterations=None, swap_memory=False, time_major=False, scope=None ) 一、 tf.nn.dynamic_rnn的输出 tf.nn.dynamic_rnn的输入参数如下 tf.nn.dynamic_rnn( cell, inputs, sequence_length= None , initial_state= None , dtype= None , parallel_iterations= None , swap_memory= False , time_major= False , scope= None ) tf.nn.dynamic_rnn的返回值有两个:outputs和state 为了描述输出的形状,先介绍几个变量,batch_size是输入的这批数据的数量,max_time就是这批数据中序列的最长长度,如果输入的三个句子,那max_time对应的就是最长句子的单词数量,cell.output

详解从 Seq2Seq模型、RNN结构、Encoder-Decoder模型 到 Attention模型

不羁岁月 提交于 2019-12-15 18:53:35
欢迎点击参观我的 ——> 个人学习网站 注:本文的所有模型只涉及自然语言处理领域,同时本文不涉及太多复杂公式推导。 一、 Seq2Seq 模型 1. 简介 Sequence-to-sequence (seq2seq) 模型,顾名思义,其输入是一个序列,输出也是一个序列,例如输入是英文句子,输出则是翻译的中文。 seq2seq 可以用在很多方面:机器翻译、 QA 系统、文档摘要生成、 Image Captioning (图片描述生成器)。 2. 基本框架 第一种结构 [参考1]论文中提出的 seq2seq 模型可简单理解为由三部分组成: Encoder、Decoder 和连接两者的 State Vector (中间状态向量) C 。 上图中 Encoder 和 Decoder 可以是一个 RNN ,但通常是其变种 LSTM 或者 GRU 。 Encoder 和 Decoder 具体介绍请见第三部分。 第二种结构 该结构是最简单的结构,和第一种结构相似,只是 Decoder 的第一个时刻只用到了 Encoder 最后输出的中间状态变量 : 应用: 在英文翻译中,将英文输入到 Encoder 中, Decoder 输出中文。 参考1:-原创翻译- 基于RNNEncoder–Decoder的机器翻译L(earning Phrase Representations using RNN