I am trying to fit my inputs to the keras model I have prepared. The input layers of my network are:
path_source_token_input = Input(shape=(MAX_CONTEXTS,), dtype=tf.int32)
path_input = Input(shape=(MAX_CONTEXTS,), dtype=tf.int32)
path_target_token_input = Input(shape=(MAX_CONTEXTS,), dtype=tf.int32)
And I specify the input this way:
inputs = (path_source_token_input, path_input, path_target_token_input)
model = tf.keras.Model(inputs=inputs, outputs=learned) # outputs not important at this point
Then I load my data from a csv file, do the appropriate preprocessing and create a dataset object which looks like this in debug:
Now my model compiles, all is good and then I try to fit it to the data:
model_x.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
history = model_x.fit(context_paths, epochs=20, verbose=2)
But it throws this error:
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 3 array(s), for inputs ['input_1', 'input_2', 'input_3'] but instead got the following list of 1 arrays: []...
At this point I am not sure what is wrong, because in debug it seems that my dataset is a tuple of length 3 (the way I want it and specify as 'input') but something goes wrong. I would appreciate any help, thank you.
You built the model to get three different inputs: (path_source_token_input, path_input, path_target_token_input)
.
You need data that is a list of 3 arrays. One array for path_source_token_input
, another array for path_input
, and a third array for path_target_token_input
.
context_paths = [array1, array2, array3]
.
Where:
array1.shape == (anything, MAX_CONTEXTS)
array2.shape == (anything, MAX_CONTEXTS)
array3.shape == (anything, MAX_CONTEXTS)
Don't think that the outputs are not important, you cannot fit without outputs if you didn't prepare a model with a special loss for this.
Just create the arrays, don't use a dataset:
def loadFile(filename):
with open(filename, 'r') as file:
lines = file.readlines()
triplets = [l.split(" ") for l in lines] #(16000, 430)
singles = [[t.split(',') for t in line] for line in triplets] #(16000, 430, 3)
data = np.array(singles).astype(np.int32)
data_source = data[:,:,0]
data_path = data[:,:,1]
data_target = data[:,:,2]
return [data_source, data_path, data_target]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.