ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 4 array(s), but instead got the following list of 1 arrays: [array([[115., 23., 37., 27., 60., 35., 77., 50., 104., 134., 99.,
59., 52., 179., 77., 85.],
[495., 457., 601., 602., 586., 549., 558., 627., 552., 500., 524.,
587....
Это ошибка, которую я получаю, когда запускаю следующий код :
inp = Input((480,640,3))
x = Dense(13, activation = 'relu')(inp)
out1 = Dense(1 , activation = 'linear')(x)
out2 = Dense(1 , activation = 'linear')(x)
out3 = Dense(1 , activation = 'linear')(x)
out4 = Dense(1 , activation = 'linear')(x)
model = Model(inp , [out1,out2,out3,out4])
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit_generator(generator = imageLoader(train_can , 16) , steps_per_epoch = 14000/16 , epochs = 1)
Функция imageLoader выглядит следующим образом:
def imageLoader(files, batch_size = 16):
L = len(files)
#this line is just to make the generator infinite, keras needs that
while True:
batch_start = 0
batch_end = batch_size
while batch_start < L:
limit = min(batch_end, L)
X = someMethodToLoadImages(files[batch_start:limit])
Y = rearrange(train_y[batch_start:limit])
yield (X,Y) #a tuple with two numpy arrays with batch_size samples
batch_start += batch_size
batch_end += batch_size
Функция someMethodToLoadImages имеет следующий вид:
def someMethodToLoadImages(files ):
images = np.empty((0,480,640,3) , float)
for file in files:
img = image.load_img(os.path.join("G:/flipkart/images" , file ) ) #no target size required as all images are of same size
images = np.append(images , image.img_to_array(img).reshape(1,480,640,3), axis = 0)
return images/255.0
Функция переставить выглядит следующим образом:
def rearrange(arr):
length = arr.shape[0]
arr_ = np.ones((4,length))
for i,sample in enumerate(arr):
for index,number in enumerate(sample):
arr_[index,i] = number
return arr_
Как решить эту проблему?Я проверил подобные вопросы в стеке, но я все еще не могу найти решение.
---------------------------------------- UPDATE -------------------------------
inp = Input((480,640,3))
#x = Dense(13, activation = 'relu')(inp)
x = Conv2D(filters = 10, kernel_size = (3,3), strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)(inp)
x1 = Flatten()(x)
out1 = Dense(1 , activation = 'linear')(x1)
out2 = Dense(1 , activation = 'linear')(x1)
out3 = Dense(1 , activation = 'linear')(x1)
out4 = Dense(1 , activation = 'linear')(x1)
model = Model(inp , [out1,out2,out3,out4])
model.compile(loss='mean_squared_error', optimizer='adam')
print(model.summary())
Это сводка модели :
При запуске:
model.fit_generator(generator = imageLoader(train_can , 16) , steps_per_epoch = 14000/16 , epochs = 1)
Я получил:
ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 4 array(s), but instead got the following list of 1 arrays: [array([[115., 23., 37., 27., 60., 35., 77., 50., 104., 134., 99.,
59., 52., 179., 77., 85.],
[495., 457., 601., 602., 586., 549., 558., 627., 552., 500., 524.,
587....