Мне удалось воссоздать вашу проблему, используя приведенный ниже код для модели.
Примечание - Вы можете загрузить набор данных, который я использую в модели, из здесь .
Код для воссоздания проблемы -
%tensorflow_version 1.x
import tensorflow as tf
print(tf.__version__)
# MLP for Pima Indians Dataset saved to single file
import numpy as np
from numpy import loadtxt
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Input, Concatenate
# load pima indians dataset
dataset = np.loadtxt("/content/pima-indians-diabetes.csv", delimiter=",")
input1 = Input(shape=(1,))
input2 = Input(shape=(1,))
# define model
x1 = Dense(12, input_shape = (2,), activation='relu')(input1)
x2 = Dense(12, input_shape = (2,), activation='relu')(input2)
x = Concatenate()([x1, x2])
x = Dense(8, activation='relu')(x)
x = Dense(1, activation='sigmoid')(x)
model = Model(inputs=[input1, input2], outputs=x)
# compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Model Summary
model.summary()
X1 = dataset[:,0]
X2 = dataset[:,1]
Y = dataset[:,8]
# Fit the model
model.fit(x=[X1,X2], y=Y, epochs=150, batch_size=10, verbose=0)
# evaluate the model
scores = model.predict([[X1,X2]], verbose=0)
Вывод -
1.15.2
Model: "model_23"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_38 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
input_39 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
dense_92 (Dense) (None, 12) 24 input_38[0][0]
__________________________________________________________________________________________________
dense_93 (Dense) (None, 12) 24 input_39[0][0]
__________________________________________________________________________________________________
concatenate_12 (Concatenate) (None, 24) 0 dense_92[0][0]
dense_93[0][0]
__________________________________________________________________________________________________
dense_94 (Dense) (None, 8) 200 concatenate_12[0][0]
__________________________________________________________________________________________________
dense_95 (Dense) (None, 1) 9 dense_94[0][0]
==================================================================================================
Total params: 257
Trainable params: 257
Non-trainable params: 0
__________________________________________________________________________________________________
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-32-d6b7d46777c6> in <module>()
38
39 # evaluate the model
---> 40 scores = model.predict([[X1,X2]], verbose=0)
3 frames
/tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
527 'Expected to see ' + str(len(names)) + ' array(s), '
528 'but instead got the following list of ' +
--> 529 str(len(data)) + ' arrays: ' + str(data)[:200] + '...')
530 elif len(names) > 1:
531 raise ValueError('Error when checking model ' + exception_prefix +
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[ 6., 1., 8., ..., 5., 1., 1.],
[148., 85., 183., ..., 121., 126., 93.]])]...
Решение - Проблема заключается в скобках для данных, переданных в model.predict()
. Это должно быть похоже на передачу данных в model.fit()
. Поэтому я изменил model.predict([[X1,X2]], verbose=0)
на model.predict([X1,X2], verbose=0)
в своем коде, и он работал нормально. Поэтому в вашем случае вам нужно изменить model.predict([[user_id],[cloth_id]])
на model.predict([user_id,cloth_id])
, и он должен работать нормально.
Фиксированный код -
%tensorflow_version 1.x
import tensorflow as tf
print(tf.__version__)
# MLP for Pima Indians Dataset saved to single file
import numpy as np
from numpy import loadtxt
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Input, Concatenate
# load pima indians dataset
dataset = np.loadtxt("/content/pima-indians-diabetes.csv", delimiter=",")
input1 = Input(shape=(1,))
input2 = Input(shape=(1,))
# define model
x1 = Dense(12, input_shape = (2,), activation='relu')(input1)
x2 = Dense(12, input_shape = (2,), activation='relu')(input2)
x = Concatenate()([x1, x2])
x = Dense(8, activation='relu')(x)
x = Dense(1, activation='sigmoid')(x)
model = Model(inputs=[input1, input2], outputs=x)
# compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Model Summary
model.summary()
X1 = dataset[:,0]
X2 = dataset[:,1]
Y = dataset[:,8]
# Fit the model
model.fit(x=[X1,X2], y=Y, epochs=150, batch_size=10, verbose=0)
# evaluate the model
scores = model.predict([X1,X2], verbose=0)
Вывод -
1.15.2
Model: "model_24"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_40 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
input_41 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
dense_96 (Dense) (None, 12) 24 input_40[0][0]
__________________________________________________________________________________________________
dense_97 (Dense) (None, 12) 24 input_41[0][0]
__________________________________________________________________________________________________
concatenate_13 (Concatenate) (None, 24) 0 dense_96[0][0]
dense_97[0][0]
__________________________________________________________________________________________________
dense_98 (Dense) (None, 8) 200 concatenate_13[0][0]
__________________________________________________________________________________________________
dense_99 (Dense) (None, 1) 9 dense_98[0][0]
==================================================================================================
Total params: 257
Trainable params: 257
Non-trainable params: 0
__________________________________________________________________________________________________
Надеюсь, это ответит на ваш вопрос. Удачного обучения.