简体   繁体   中英

Keras - model.predict() returns list instead of numpy array

I am using model.predict() on a testing tensor, which has the same size of the input used for training, (N_tr*70,1025,11,3)

The model is trained by regression, with three outputs as ground-truth, each of size (N_te*70,1025).

For information, when testing the model N_te=180.

According to the documentation, the output of model.predict() should be a numpy tensor, instead I get a list of three elements, each with shape (N_te*70,1025). I am afraid that the output might have been somehow shuffled (which would explain my unexpected results).

Do you have any advice to get a numpy array which is compatible to the one I used as ground-truth? If not, do you know any other work-around?

EDIT: added the neural network code

input_img = Input(shape=(1025, 11, 3 ) )
x = ( Flatten())(input_img)

for i in range(0,4):
    x = ( Dense(1024*3))(x)
    x = ( BatchNormalization() )(x)
    x = ( LeakyReLU())(x)
o0 = ( Dense(1025, activation='sigmoid'))(x)
o1 = ( Dense(1025, activation='sigmoid'))(x)
o2 = ( Dense(1025, activation='sigmoid'))(x)

Model prediction:

output = model.predict(X_in, batch_size = batch_size, verbose=1)

It is expected that in a multi-output model, predict returns a list of numpy arrays, with each element being the corresponding output. Remember that loss is computed individually between each output and the ground truth, so this format is already ideas for that purpose.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM