我需要一些帮助,因为我无法在张量流中使用正则化。我今天安装了它,这是我的新手。这是我的代码:
def buildmodel(dim,neurons_on_layers,X,Y,ep,batch):
le=len(neurons_on_layers)
ne=neurons_on_layers
model = Sequential()
model.add(Dense(ne[0], input_dim=dim, kernel_regularizer=regularizers.l2(0),
activity_regularizer=regularizers.l1(0)
activation='relu')) #change from 'relu'
for j in list(range(1,le)):
model.add(Dense(ne[j],
activation='relu')) ##changed from 'relu' 'tan'
model.add(Dense(2, activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy']) ##normal
model.fit(X, Y, epochs=ep, batch_size=batch)
return model
当我编译它时,它返回:
'float' object has no attribute 'dtype'
进入“ _handle_activity_regularization”功能。
当我删除正则化代码时,代码就可以工作(但是如果没有正则化,我的算法将一无所知)。有人知道要对我的代码进行惩罚的技巧吗?
谢谢