zzh8829/yolov3-tf2

Converting a custom yolov3 model

Hatem-Jr opened this issue · 0 comments

I am trying to convert this yolov3 custom model: https://drive.google.com/drive/folders/17jysPykGMkNw66lDMd0kryybCvGOesKi?usp=sharing
with this .cfg file: https://github.com/heltonmaia/ECT-proj-cnn-mice/blob/master/cfg/yolov3.cfg

into tensorflow format that already worked on the model that was linked in the video (for checking purposes and it worked 😄) however I tried to take the same approach to a custom trained model that detects "mice" (for test analysis purposes) and I get this error:

in load_darknet_weights
conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 4607 into shape (18,256,1,1)

so is there a way to solve this issue?

So then I added these lines in utils.py:
conv_shape = (math.floor(filters), math.floor(in_dim), size, size)
conv_weights = np.fromfile(wf, dtype=np.float32, count=np.product(conv_shape))
if conv_weights.shape[0]<filters*in_dim:
conv_weights = np.append(conv_weights,[0])

before: conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])

and it worked but when it came time to run object_tracker.py (yes a file from another repo but has the same convert.py and utils.py) I had this error:

tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: Input to reshape is a tensor with 3042 values, but the requested shape requires a multiple of 43095
[[{{node yolo_output_0/lambda/Reshape}}]]
[[yolo_nms/Reshape_9/_1477]]
(1) Invalid argument: Input to reshape is a tensor with 3042 values, but the requested shape requires a multiple of 43095
[[{{node yolo_output_0/lambda/Reshape}}]]