Неверный входной аргумент для функции an ano: "установка элемента массива с помощью последовательности".

Я использую Keras с бэкэндом Theano. Следующий код выдает ошибку, как указано в заголовке.

from keras.models import Sequential
from keras.layers import Dense
import theano
import theano.tensor as T

seed = 150
np.random.seed(seed)

# Define Model 

model = Sequential()
model.add(Dense(500, input_dim=6, init='uniform', activation='relu'))
model.add(Dense(6, init='uniform', activation='softmax'))

def customObjective(y_true, y_pred):
    cce = T.nnet.categorical_crossentropy(y_pred, y_true)
    return cce


model.compile(loss=customObjective, optimizer='adam',metrics=    ["hinge"])
kf = KFold(n_splits=5)
Y = trainData['label'].as_matrix()
X = trainData[['input','feat1','feat2','feat3','feat4','feat5']].as_matrix()

for train, test in kf.split(trainData):
    trainX = X[train]
    print trainX.shape
    trainY = Y[train]
    print trainY.shape
    testX = X[test]
    testY = Y[test]
    **model.fit(trainX, trainY, nb_epoch=25, batch_size=1)**  # Error on this line
    print("[INFO] evaluating on testing set...")
    (loss, accuracy) = model.evaluate(testData, testLabels,  batch_size=128, verbose=1)
    print("[INFO] loss={:.4f}, accuracy: {:.4f}%".format(loss,accuracy * 100))

Сгенерированная ошибка выглядит так:

ValueError: ('Bad input argument to theano function with name "/home/krishna/anaconda2/lib/python2.7/site-packages/keras/backend/theano_backend.py:653"  at index 0(0-based)', 'setting an array element with a sequence.')

Чтобы дать вам представление о размерах X и Y.

"""Every cell in X is a np.array with shape (300,) with float type"""
"""Dimension X = 1542x6x300"""
X = trainData[['input','feat1','feat2','feat3','feat4','feat5']]
for val in X.iloc[0].values:
    print val.shape

> (300,)
> (300,)
> (300,)
> (300,)
> (300,)
> (300,)

""" Every cell in Y is a np.array with shape (19,) with float type, Basically a one-hot vector representing one of the 19 classes """
""" Dimension Y = 1542x6x19 """

Я был бы очень признателен за любую помощь. Благодарю.

0 ответов

Другие вопросы по тегам