'InputLayer'对象没有属性'activity_regularizer'

时间:2018-04-16 12:45:51

标签: python-3.x tensorflow keras

安装了最新版本的keras 2.1.5并在使用时 连接到模型的输出并将其添加为Dense层的输入

 Merged_out=add([fe.output,seq_model.output])
 output  = Dense(256,activation='softmax')(Merged_out)

和create model接受两个模型特征提取器和序列模型的输入

    #feature extractor model Dense_map this layer summarizes the contents in image
    fe  = Sequential()
    fe.add(Dense(256,input_shape=(4096,),activation='relu'))
    fe.add(Dropout(0.5))
     #sequence model
    seq_model = Sequential()
    seq_model.add(Embedding(input_dim =  max_length,input_length=vocab_size,output_dim=256))
    print(seq_model.add(GRU(256,return_sequences=True)))
    seq_model.add(GRU(256,return_sequences=True))
    seq_model.add(GRU(256,return_sequences=True

and added the inputs of two models as input of model and Dense layer is output of model  to the Model : 
 model = Model(inputs=[fe.input,seq_model.input],outputs=output)

When make compile by using model.compile : 
 model.compile(loss='categorical_crossentropy',optimizer='Adam')

错误InputLayer对象没有属性activity_regularizer 发生了 完整的错误是:

>--------------------------------------------------------------------------- AttributeError                            Traceback (most recent call
> last)  in ()
> 22 plot_model(model,to_file='image_Captioning_model.png',show_shapes=True,show_layer_names=True)
>      23     return model
> ---> 24 define_model(vocab_size,max_len)
> 
>  in define_model(vocab_size, max_length)
>      19     model = Model(inputs=[fe.input,seq_model.input],outputs=output)
>      20 
> ---> 21     model.compile(loss='categorical_crossentropy',optimizer='Adam')
>      22     plot_model(model,to_file='image_Captioning_model.png',show_shapes=True,show_layer_names=True)
>      23     return model
> 
> ~/.local/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/engine/training.py
> in compile(self, optimizer, loss, metrics, loss_weights,
> sample_weight_mode, weighted_metrics, target_tensors, **kwargs)
>     679 
>     680     # Prepare output masks.
> --> 681     masks = self.compute_mask(self.inputs, mask=None)
>     682     if masks is None:
>     683       masks = [None for _ in self.outputs]
> 
> ~/.local/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/engine/topology.py
> in compute_mask(self, inputs, mask)
>     785       return self._output_mask_cache[cache_key]
>     786     else:
> --> 787       _, output_masks = self._run_internal_graph(inputs, masks)
>     788       return output_masks
>     789 
> 
> ~/.local/lib/python3.6/site-packages/tensorflow/python/layers/network.py
> in _run_internal_graph(self, inputs, masks)
>     896 
>     897             # Apply activity regularizer if any:
> --> 898             if layer.activity_regularizer is not None:
>     899               regularization_losses = [
>     900                   layer.activity_regularizer(x) for x in computed_tensors
> 
> AttributeError: 'InputLayer' object has no attribute
> 'activity_regularizer'

0 个答案:

没有答案