Deep learning Keras--关于掩蔽层,然后是重塑层

Deep learning Keras--关于掩蔽层,然后是重塑层,deep-learning,keras,reshape,lstm,Deep Learning,Keras,Reshape,Lstm,我想在LSTM之前使用掩模,但LSTM的输出必须被整形为4维。 所以我的代码是: main_input = Input(shape=(96,1000), name='main_input') pre_input = BatchNormalization()(main_input) aaa= Masking(mask_value=0)(pre_input) recurrent1 = LSTM(256,return_sequences=True)(aaa) r_out= Reshape((1

我想在LSTM之前使用掩模,但LSTM的输出必须被整形为4维。 所以我的代码是:

main_input = Input(shape=(96,1000), name='main_input')

pre_input = BatchNormalization()(main_input)

aaa= Masking(mask_value=0)(pre_input)

recurrent1 = LSTM(256,return_sequences=True)(aaa)

r_out= Reshape((1,96,256))(recurrent1)`
但它运行时出错: [![在此处输入图像描述][1][1]

    ---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-2-d1107015501b> in <module>()
     17 recurrent1 = LSTM(256,return_sequences=True)(aaa)
     18 
---> 19 r_out= Reshape((1,96,256))(recurrent1)

/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in __call__(self, x, mask)
    512         if inbound_layers:
    513             # this will call layer.build() if necessary
--> 514             self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
    515             input_added = True
    516 

/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in add_inbound_node(self, inbound_layers, node_indices, tensor_indices)
    570         # creating the node automatically updates self.inbound_nodes
    571         # as well as outbound_nodes on inbound layers.
--> 572         Node.create_node(self, inbound_layers, node_indices, tensor_indices)
    573 
    574     def get_output_shape_for(self, input_shape):

/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices)
    148         if len(input_tensors) == 1:
    149             output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
--> 150             output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0]))
    151             # TODO: try to auto-infer shape if exception is raised by get_output_shape_for
    152             output_shapes = to_list(outbound_layer.get_output_shape_for(input_shapes[0]))

/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in compute_mask(self, input, input_mask)
    605                 else:
    606                     raise Exception('Layer ' + self.name + ' does not support masking, ' +
--> 607                                     'but was passed an input_mask: ' + str(input_mask))
    608             # masking not explicitly supported: return None as mask
    609             return None

Exception: Layer reshape_1 does not support masking, but was passed an input_mask: Any{2}.0
---------------------------------------------------------------------------
异常回溯(最后一次最近调用)
在()
17复发1=LSTM(256,返回序列=True)(aaa)
18
--->19 r_out=重塑((1,96256))(复发1)
/调用中的usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc(self,x,mask)
512如果入站\u层:
513#这将在必要时调用layer.build()
-->514 self.添加\u入站\u节点(入站\u层、节点\u索引、张量\u索引)
515添加的输入=真
516
/添加入站节点(self、入站层、节点索引、张量索引)中的usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc
570#创建节点会自动更新self.inbound_节点
571#以及入站层上的出站#节点。
-->572节点。创建节点(自身、入站层、节点索引、张量索引)
573
574 def get_output_shape_(自我、输入_shape):
/创建节点(cls、出站层、入站层、节点索引、张量索引)中的usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc
148如果len(输入张量)==1:
149输出\张量=到\列表(出站\层.调用(输入\张量[0],掩码=输入\掩码[0]))
-->150输出\u掩码=到\u列表(出站\u层.计算\u掩码(输入\u张量[0],输入\u掩码[0]))
151#TODO:如果get#u output_shape_为引发异常,请尝试自动推断形状
152输出形状=到列表(出站层。获取输出形状(输入形状[0]))
/计算掩码(self、输入、输入掩码)中的usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc
605其他:
606引发异常('Layer'+self.name+'不支持掩蔽,'+
-->607'但传递了一个输入屏蔽:'+str(输入屏蔽))
608#未明确支持屏蔽:将无作为屏蔽返回
609返回无
异常:层重塑_1不支持屏蔽,但传递了一个输入_屏蔽:Any{2}。0
我已经打印出来了,复发1的外形是(96256)


我该怎么做?

请将您的实际控制台输出以代码格式粘贴,不要发布控制台的屏幕截图。我的意思是编辑您的问题以替换控制台输出。我编辑了我的问题