qqwweee / keras-yolo3

A Keras implementation of YOLOv3 (Tensorflow backend)
MIT License
7.14k stars 3.44k forks source link

ValueError:Error when checking model input #750

Open mim201820 opened 3 years ago

mim201820 commented 3 years ago

After the training I saved my weights and I create a model with those weights with the function create_model(input_shape, anchors, num_classes, load_pretrained=True, freeze_body=2, weights_path='model_data/yolo_weights.h5'): After that I tried to predict with the model and with the following script:

model = load_model("./model_weights/test.h5", compile=False, custom_objects={'tf': tf, 'yolo_head': yolo_head, 'box_iou': box_iou})
img_path = './results/0_.jpg'
image = load_img(img_path, target_size=input_shape)
image_data = np.array(image, dtype="float32")
image_data /= 255.0
image_data = np.expand_dims(image_data, 0)

pred = model.predict(image_data)
print(pred)

But I got the following 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 4 array(s), but instead got the following list of 1 arrays: [array([[[[1., 1., 1.],
         [1., 1., 1.],
         [1., 1., 1.],
         ...,
         [1., 1., 1.],
         [1., 1., 1.],
         [1., 1., 1.]],

        [[1., 1., 1.],
         [1., 1., 1.],...

Does any one have any solution for this error?