Custom model w/ AlexeyAB darknet : export fine, load_weights issue
Closed this issue · 5 comments
Hello,
I trained a custom model with the c/cuda repo. model is (320,320,3)
- 3 classes - custom anchors. I'm able to export the model using the convert_darknet_weights.py
( after modified the INPUT_SHAPE
and NUM_CLASSES
). However when doing :
import tensorflow as tf
from tf2_yolov4.anchors import YOLOV4_ANCHORS
from tf2_yolov4.model import YOLOv4
model = YOLOv4(
input_shape=(320, 320, 3),
anchors=YOLOV4_ANCHORS,
num_classes=3,
training=False,
yolo_max_boxes=100,
yolo_iou_threshold=0.5,
yolo_score_threshold=0.5,
)
model.load_weights("....path-to-converted-weights.h5...")
This is what I get :
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-f6463dea2434> in <module>
----> 1 model.load_weights("./yolov4.h5")
5 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_shape.py in assert_is_compatible_with(self, other)
1115 """
1116 if not self.is_compatible_with(other):
-> 1117 raise ValueError("Shapes %s and %s are incompatible" % (self, other))
1118
1119 def most_specific_compatible_shape(self, other):
ValueError: Shapes (3, 3, 128, 256) and (1024, 512, 3, 3) are incompatible
Hi @MI-LA01, could you point to the .weights file you obtained with the darknet training?
Hello @RaphaelMeudec and thanks for your kind help. Pls find the google link
@MI-LA01 I just looked into it:
- output number of classes is hardcoded inside convert_darknet_weights (to 80), it makes the conversion fail on my computer
- after putting
num_classes=3
in the conversion script, the conversion is running fine - I have been able to load the .h5 file properly
On my side, I'll open a PR to make the number of classes configurable in the conversion script.
On your side, can you check that you have been converting the right .weights file? I don't understand why it didn't fail on your side.
Hi @RaphaelMeudec
Some pointers :
- I confirm this is the good weights file
- As mentioned in the issue, I already changed the
NUM_CLASSES
in the conversion script to reflect my number of class. ThusNUM_CLASSES=3
and later in the script :
model = YOLOv4(
input_shape=INPUT_SHAPE, num_classes=NUM_CLASSES, anchors=YOLOV4_ANCHORS
would be ok, reason why the conversion script works.
- I posted the outcome from the conversion script in the google drive, if you can look at it HERE?
- The screenshot below gives the output of the conversion script :
Found ; By installing the tf addons and specifically the mish() activation layer I was able to solve this issue. I was using a different implementation than the one supplied by tfa due to compat issues with the jetson/tx* environment.