Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow ValueError:两个形状中的尺寸0必须相等,但分别为10和1。形状为[10]和[1]_Tensorflow_Lstm - Fatal编程技术网

Tensorflow ValueError:两个形状中的尺寸0必须相等,但分别为10和1。形状为[10]和[1]

Tensorflow ValueError:两个形状中的尺寸0必须相等,但分别为10和1。形状为[10]和[1],tensorflow,lstm,Tensorflow,Lstm,我正在创建一个LSTM网络。虽然目标有10个不同的类值(1-10),但我的输入板顺序排列了形状数组(140017640)、掩码数组(140017640)和形状数组(1400)的y(目标数组)。 因此,我将10个单位的输出密集层和损耗定义为稀疏分类交叉熵。 LSTM网络代码:- pad_seq = np.random.rand(17640,1) def create_model(): #input 1 (pad sequence) input_layer1 = Input(shape=(176

我正在创建一个LSTM网络。虽然目标有10个不同的类值(1-10),但我的输入板顺序排列了形状数组(140017640)、掩码数组(140017640)和形状数组(1400)的y(目标数组)。 因此,我将10个单位的输出密集层和损耗定义为稀疏分类交叉熵。 LSTM网络代码:-

pad_seq = np.random.rand(17640,1)

def create_model():

#input 1 (pad sequence)
input_layer1 = Input(shape=(17640,1),name = 'input_layer',dtype='float32')

#input 2 (mask)
input_layer2 = Input(shape=(17640,),name='input_mask',dtype='bool')

#LSTM layer
LSTM_layer = LSTM(25,return_sequences=False,name = 'LSTM_layer')(input_layer1,mask = input_layer2)

#Dense layer
dense = Dense(50,activation='relu',kernel_initializer=he_normal(),kernel_regularizer=l2(0.0001),name = 'dense')(LSTM_layer)

#output layer
dense_1 = Dense(10, activation = 'softmax',name='dense_1')(dense)

#concat = concatenate([input_layer,input_mask])

model = Model([input_layer1, input_layer2],dense_1)

#compile
model.compile(loss='SparseCategoricalCrossentropy', optimizer=keras.optimizers.Adam(lr=0.001,decay = 1e-4),metrics=[tfa.metrics.F1Score(num_classes = 10)])

return model
但在拟合模型时,我得到了一个值错误:

ValueError: Dimension 0 in both shapes must be equal, but are 10 and 1. Shapes are [10] and [1]. for '{{node AssignAddVariableOp_5}} = AssignAddVariableOp[dtype=DT_FLOAT](AssignAddVariableOp_5/resource, Cast_6)' with input shapes: [], [1].

哪两个输入形状相互比较,哪两个输入形状应该匹配才能拟合模型请使用
np.random.rand(17640,1)
提供虚拟输入,以便我们可以复制粘贴您的代码并再现错误。@Nicolas Gervais我已经编辑了代码。请使用
np.random.rand(17640,1)提供虚拟输入
这样我们就可以复制粘贴您的代码并重现错误。@NicolasGervais我已经编辑了代码。