david8862 / keras-YOLOv3-model-set

end-to-end YOLOv4/v3/v2 object detection pipeline, implemented on tf.keras with different technologies
MIT License
640 stars 222 forks source link

yolo3_darknet_spp model fails to load with yolo.py #70

Open bsugerman opened 4 years ago

bsugerman commented 4 years ago

I followed your instructions in the README.me to download and convert weights files for yolov3 and yolov3-spp. I've successfully run yolo.py using the standard yolov3 as follows:

$ curl https://pjreddie.com/media/files/yolov3.weights -o weights/yolov3.weights
$ python tools/convert.py cfg/yolov3.cfg ../weights/yolov3.weights weights/yolov3.h5
$ python yolo.py --image --model_type=yolo3_darknet --weights_path=weights/yolov3.h5

and it works perfectly. But when I try this for yolov3-spp:

$ curl https://pjreddie.com/media/files/yolov3-spp.weights -o weights/yolov3-spp.weights
$ python tools/convert.py cfg/yolov3-spp.cfg ../weights/yolov3-spp.weights weights/yolov3-spp.h5
$ python yolo.py --image --model_type=yolo3_darknet_spp --weights_path=weights/yolov3-spp.h5

I get this error message:

ValueError('Layer #207 (named "conv2d_60"), weight <tf.Variable \'conv2d_60/kernel:0\' shape=(1, 1, 768, 256) dtype=float32, numpy=\narray([[[[ 0.02679576, -0.07150556, -0.07347696, ..., -0.02756389,\n -0.02545156, -0.06959445],\n [-0.04717658, 0.02249254, -0.00447319, ..., -0.02719363,\n 0.01210598, 0.06080437],\n [-0.01835743, 0.02954972, 0.00888053, ..., 0.01113752,\n -0.01169422, -0.04855689],\n ...,\n [ 0.04739171, -0.03856181, -0.02176232, ..., 0.06746078,\n -0.02833465, -0.05058649],\n [-0.03101221, -0.02032788, -0.0133861 , ..., -0.0142144 ,\n 0.04930516, -0.07231824],\n [-0.02280887, -0.0695509 , 0.05289441, ..., -0.05584659,\n 0.06272969, 0.02378166]]]], dtype=float32)> has shape (1, 1, 768, 256), but the saved weight has shape (256, 512, 1, 1).') Traceback (most recent call last): File "yolo.py", line 84, in _generate_model yolomodel, = get_yolo3_model(self.model_type, num_feature_layers, num_anchors, num_classes, input_shape=self.model_image_size + (3,), model_pruning=self.pruning_model) File "C:\Users\M43259\Documents\yolo\falcon\yolo3\model.py", line 174, in get_yolo3_model model_body = model_function(input_tensor, num_anchors//3, num_classes, weights_path=weights_path) File "C:\Users\M43259\Documents\yolo\falcon\yolo3\models\yolo3_darknet.py", line 136, in custom_yolo3_spp_body base_model.load_weights(weights_path, by_name=True) File "C:\Users\M43259\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 234, in load_weights return super(Model, self).load_weights(filepath, by_name, skip_mismatch) File "C:\Users\M43259\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1220, in load_weights f, self.layers, skip_mismatch=skip_mismatch) File "C:\Users\M43259\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 777, in load_weights_from_hdf5_group_by_name str(weight_values[i].shape) + '.') ValueError: Layer #207 (named "conv2d_60"), weight <tf.Variable 'conv2d_60/kernel:0' shape=(1, 1, 768, 256) dtype=float32, numpy= array([[[[ 0.02679576, -0.07150556, -0.07347696, ..., -0.02756389, -0.02545156, -0.06959445], [-0.04717658, 0.02249254, -0.00447319, ..., -0.02719363, 0.01210598, 0.06080437], [-0.01835743, 0.02954972, 0.00888053, ..., 0.01113752, -0.01169422, -0.04855689], ..., [ 0.04739171, -0.03856181, -0.02176232, ..., 0.06746078, -0.02833465, -0.05058649], [-0.03101221, -0.02032788, -0.0133861 , ..., -0.0142144 , 0.04930516, -0.07231824], [-0.02280887, -0.0695509 , 0.05289441, ..., -0.05584659, 0.06272969, 0.02378166]]]], dtype=float32)> has shape (1, 1, 768, 256), but the saved weight has shape (256, 512, 1, 1).

david8862 commented 4 years ago

@bsugerman It's a yolo3_darknet_spp model definition issue break by some recently commit. I've fix it and you can try on latest code. Sorry for the trouble.