我知道这类问题已经得到解答(here或here),但所有答案对我都不起作用:
我的X是5000的矢量。
每个xi是一个大小稀疏的矩阵(190000,42) 并且y是大小为5000的向量,并且每个yi是大小为190000(稀疏)的向量
X =
array([ <191483x42 sparse matrix of type '<class 'numpy.float64'>'
with 75431 stored elements in Compressed Sparse Row format>,
<191483x42 sparse matrix of type '<class 'numpy.float64'>'
with 182015 stored elements in Compressed Sparse Row format>,
<191483x42 sparse matrix of type '<class 'numpy.float64'>',], dtype=object)
我想使用TimeDistributed制作一个非常简单的模型。 (当我的向量X中只有100个矩阵时,这个工作正常。)
我尝试使用fit_generator来解析每个矩阵,但这并不起作用。
def build_model():
model = Sequential()
model.add(TimeDistributed(Dense(1, bias=0, W_regularizer=regularizers.l1(0.01)), input_shape=(191483, 42)))
model.add(Activation("softmax"))
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
return model
print ('load model')
model = build_model()
def batch_generator(X, y):
for i in range(len(X)):
X_array = X[i].toarray()
y_array = y[i].toarray()
yield (X_array,y_array)
model.fit_generator(generator=batch_generator(X, y), samples_per_epoch=10000, nb_epoch=10)
我收到了这个错误:
ValueError: Error when checking model input: expected timedistributed_input_1 to have 3 dimensions, but got array with shape (191483, 42)
感谢您的帮助