小编V1n*_*3nt的帖子

在没有填充的情况下改变Keras中的序列长度

我有一个关于Keras中LSTM序列长度不同的问题.我将大小为200的批次和可变长度序列(= x)与序列中每个对象(=> [200,x,100])的100个特征传递到LSTM:

LSTM(100, return_sequences=True, stateful=True, input_shape=(None, 100), batch_input_shape=(200, None, 100))
Run Code Online (Sandbox Code Playgroud)

我将模型拟合到以下随机创建的矩阵中:

x_train = np.random.random((1000, 50, 100))
x_train_2 = np.random.random((1000, 10,100))
Run Code Online (Sandbox Code Playgroud)

据我所知,LSTM(和Keras实现)正确,x应该指LSTM单元的数量.对于每个LSTM单元,必须学习状态和三个矩阵(用于单元的输入,状态和输出).如何在不填充最大值的情况下将不同的序列长度传递到LSTM中.指定长度,就像我一样?代码正在运行,但它实际上不应该(在我的理解中).甚至可以在之后传递另一个序列长度为60的x_train_3,但是不应该有额外的10个单元格的状态和矩阵.

顺便说一句,我使用Keras版本1.0.8和Tensorflow GPU 0.9.

这是我的示例代码:

from keras.models import Sequential
from keras.layers import LSTM, Dense
import numpy as np
from keras import backend as K

with K.get_session():

    # create model
    model = Sequential()
    model.add(LSTM(100, return_sequences=True, stateful=True, input_shape=(None, 100),
             batch_input_shape=(200, None, 100)))
    model.add(LSTM(100))
    model.add(Dense(2, activation='softmax'))
    model.compile(loss='categorical_crossentropy',
                  optimizer='rmsprop',
                  metrics=['accuracy'])

    # Generate dummy training data
    x_train = np.random.random((1000, 50, 100))
    x_train_2 = np.random.random((1000, …
Run Code Online (Sandbox Code Playgroud)

padding sequence lstm keras recurrent-neural-network

8
推荐指数
1
解决办法
4257
查看次数

在keras的LSTM中使用隐藏状态而不是输出

我想使用Yang等人的注意机制的实现..我发现了一个自定义图层的工作实现,它在这里使用了这种注意力机制.而不是使用我的LSTM的输出值:

my_lstm = LSTM(128, input_shape=(a, b), return_sequences=True)
my_lstm = AttentionWithContext()(my_lstm)
out = Dense(2, activation='softmax')(my_lstm)
Run Code Online (Sandbox Code Playgroud)

我想使用LSTM的隐藏状态:

my_lstm = LSTM(128, input_shape=(a, b), return_state=True)
my_lstm = AttentionWithContext()(my_lstm)
out = Dense(2, activation='softmax')(my_lstm)
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

TypeError:只能将元组(不是"int")连接到元组

我尝试将它与return_sequences结合使用但到目前为止我尝试过的所有内容都失败了.如何修改返回的张量以便像返回的输出序列一样使用它?

谢谢!

python neural-network deep-learning lstm keras

6
推荐指数
1
解决办法
3816
查看次数

Android通过AT命令与HFP设备通信

我试图通过Android中的HFP(免提配置文件)控制具有振动功能的蓝牙手链。我已经能够连接到手镯并访问输入和输出流。

我的目标是模拟来电,以便蓝牙手镯开始振动(这似乎是唯一的方法)。为此,即时通讯使用AT命令。在第22页的https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193的蓝牙规范中,您可以看到建立服务级别连接的握手。我需要建立此连接才能使用“ + CIEV”命令(请参见握手第48页)。

但是当我的手镯返回命令“ AT + CIND =?”时 我不知道该如何回应。我找不到有关如何使用“ CIND:”命令回答的任何提示。我也不知道如何发送确认(只是“ OK”?)。

这甚至可能是完全错误的方法。每个建议都表示赞赏。我只找到一个职位上的计算器,帮助我在某些方面,我找到了帖子的其余悬而未决。顺便说一句,即时通讯使用的智能手机与Android 4.1.2。手链支持HFP和HSP。提前致谢。

更新10/29/2014

服务水平连接步骤

=====此时通过RFCOMM套接字建立的连接=====

        // read AT+BRSF=0 from device
        byte[] buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

        //write answer BRSF: ...
        mBluetoothSocket.getOutputStream().write("+BRSF=20\r".getBytes());
        mBluetoothSocket.getOutputStream().write("OK\r".getBytes());

        // read AT+CIND=? command
        buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

        //write answer CIND: ...
        mBluetoothSocket.getOutputStream().write("+CIND: (\"battchg\",(0-5)),(\"signal\",(0-5)),
           (\"service\",(0,1)),(\"call\",(0,1)),(\"callsetup\",(0-3)),
           (\"callheld\",(0-2)),(\"roam\",(0,1))".getBytes());
        mBluetoothSocket.getOutputStream().write("OK".getBytes());

        // read AT+CIND?
        buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());
Run Code Online (Sandbox Code Playgroud)

按照协议的程序,我应该收到“ AT + CIND?” 命令,然后我可以发送命令“ + CIND:5,5,1,0,0,0,0”,但是...我没有收到“ AT …

android bluetooth at-command hfp

5
推荐指数
1
解决办法
4340
查看次数