我正在尝试制作LSTM,LSTM(EMBEDDING),DNN的concat网络 解决分类问题
但是我得到了这个错误。 请参见下面的代码:
# Shared Feature Extraction Layer
from keras.utils import plot_model
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
from keras.layers.recurrent import LSTM
from keras.layers.merge import concatenate
# define input
visible = Input(shape=(190,1))
visible1 = Input(shape=(3000,1))
# feature extraction
extract1 = LSTM(50, return_sequences=False)(visible)
extract2 = LSTM(50, return_sequences=False)(visible1)
# merge interpretation
merge = concatenate([extract1, extract2])
# output
output = Dense(1, activation='sigmoid')(merge)
model = Model(inputs=[visible,visible1], outputs=output)
# summarize layers
print(model.summary())
model.compile(optimizer = "adam", loss = 'binary_crossentropy', metrics=
['accuracy'])
print("test",data.shape)
print("test2",data_.shape)
# model.fit([data,data_], y, epochs=20, verbose=1)
但出现此错误: -------------------------------------------------- ------------------------- AttributeError Traceback(最近一次调用 最后)在() ----> 1个model.fit([data,data_],y,历元= 350,batch_size = 64)
/etc/anaconda3/lib/python3.6/site-packages/keras/engine/training.py在 fit(self,x,y,batch_size,epochs,verbose,callbacks, validate_split,validation_data,随机播放,class_weight, sample_weight,initial_epoch,steps_per_epoch,validation_steps, ** kwargs)1628 sample_weight = sample_weight,1629 class_weight = class_weight, -> 1630 batch_size = batch_size)1631#准备验证数据。 1632 do_validation = False
/etc/anaconda3/lib/python3.6/site-packages/keras/engine/training.py在 _standardize_user_data(自身,x,y,sample_weight,class_weight,check_array_lengths,batch_size)1478
output_shapes,1479年
check_batch_axis = False, -> 1480 exception_prefix ='目标')1481 sample_weights = _standardize_sample_weights(sample_weight,1482 self._feed_output_names)/etc/anaconda3/lib/python3.6/site-packages/keras/engine/training.py在 _standardize_input_data(数据,名称,形状,check_batch_axis,exception_prefix) 74数据=数据。如果有数据。类。名称 =='DataFrame'否则为数据 75数据= [数据] ---> 76数据= [np.expand_dims(x,1),如果x不为None并且x.ndim == 1否则x表示数据中的x] 77 78如果len(data)!= len(names):
/etc/anaconda3/lib/python3.6/site-packages/keras/engine/training.py在 (.0) 74数据=数据。如果有数据。类。名称 =='DataFrame'否则为数据 75数据= [数据] ---> 76数据= [np.expand_dims(x,1),如果x不为None并且x.ndim == 1否则x表示数据中的x] 77 78如果len(data)!= len(names):
AttributeError:'Tensor'对象没有属性'ndim'
请帮助我:)
答案 0 :(得分:0)
visible = Input(shape=(190,1))
visible1 = Input(shape=(3000,1))
model = Model(inputs=[visible,visible1], outputs=output)
然后您尝试运行model.fit([data,data_], y, epochs = 350, batch_size = 64)
。然后,您应该有data_.shape == (*, 3000, 1)
,但是您有data_.shape = (*, 190, 1)
。那行不通。
但是摘要显示(None, 190, 1)
。所以我想你已经纠正了。进行此更正后,网络可以正确地训练,我没有任何错误。
您的y
的形状是什么?