hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

Model and weights file do not match #9

Closed ImanHosseini closed 4 years ago

ImanHosseini commented 4 years ago

I installed yolov4 from PyPI, and attempting to run the 1st example I get "Model and weights file do not match" [I am using "yolov4.weights" file from the link in the description]

hhk7734 commented 4 years ago
from yolov4.tf import YOLOv4

yolo = YOLOv4()

yolo.classes = "coco.names"

print(len(yolo.classes))

The result should be 80.

ImanHosseini commented 4 years ago

It is 80. ("coco.names" is the correct file)

hhk7734 commented 4 years ago

yolov4.weights size is 246 MB (257,717,640 bytes). Is that right?

ImanHosseini commented 4 years ago

My bad: The file ("coco.names") is correct, and has 80 lines BUT 'yolo.classes' becomes 159 ! I am running this on windows, and I'm guessing this has to do with line-endings?

ImanHosseini commented 4 years ago

Indeed it is, I added a print here:

def read_classes_names(classes_name_path):
    names = {}
    with open(classes_name_path, "r") as data:
        for ID, name in enumerate(data):
            print("N:"+name)
            names[ID] = name.strip("\n")
    return names

And I get:

N:ÿþperson

N:

N:bicycle

N:
...
hhk7734 commented 4 years ago

I changed the environment with Windows and tested it. https://github.com/hhk7734/tensorflow-yolov4/blob/master/test/coco.names file works fine.

ImanHosseini commented 4 years ago

This is my file: coco.names (And python version is 3.7.7)

hhk7734 commented 4 years ago

it seems to be an encoding problem.

hhk7734 commented 4 years ago
def read_classes_names(classes_name_path):
    names = {}
    with open(classes_name_path, "r", encoding="utf-16") as data:
        for ID, name in enumerate(data):
            names[ID] = name.strip("\n")
    return names

This solved it.

hhk7734 commented 4 years ago

However, it does not seem to be a good solution.

ImanHosseini commented 4 years ago

Yes! It does help someone who might do the same, but not worth it as you said! Hopefully he googles the error and lands at this issue now :) I had copy+pasted from the raw github file, and the result had weird encoding (2 byte per character, '\x61' -> '\x61\x00') Thank You.