Python can';t将我的输入数据与培训模型相匹配
我有17个班级要分类。我想用RBF神经网络来做这件事,但我的数据无法与模型相匹配。 这是代码:Python can';t将我的输入数据与培训模型相匹配,python,tensorflow,keras,data-fitting,Python,Tensorflow,Keras,Data Fitting,我有17个班级要分类。我想用RBF神经网络来做这件事,但我的数据无法与模型相匹配。 这是代码: from keras.layers import Layer from keras import backend as K class RBFLayer(Layer): def __init__(self, units, gamma, **kwargs): super(RBFLayer, self).__init__(**kwargs) self.units = units
from keras.layers import Layer
from keras import backend as K
class RBFLayer(Layer):
def __init__(self, units, gamma, **kwargs):
super(RBFLayer, self).__init__(**kwargs)
self.units = units
self.gamma = K.cast_to_floatx(gamma)
def build(self, input_shape):
self.mu = self.add_weight(name='mu',
shape=(int(input_shape[1]), self.units),
initializer='uniform',
trainable=True)
super(RBFLayer, self).build(input_shape)
def call(self, inputs):
diff = K.expand_dims(inputs) - self.mu
l2 = K.sum(K.pow(diff,2), axis=1)
res = K.exp(-1 * self.gamma * l2)
return res
def compute_output_shape(self, input_shape):
return (input_shape[0], self.units)
拟合数据:
from keras.layers import *
model = Sequential()
model.add(Dense(17, input_shape=(187,)))
model.add(RBFLayer(187, 0.5))
model.compile(loss='mean_squared_error',
optimizer=RMSprop())
model.fit(X, y,
batch_size=32,
epochs=200,
verbose=1)
'''
我的数据的形状是:
X:(4900187)
y:(187,17)请添加错误消息和调用堆栈