-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BGR or RGB order for image reading in darknet? #427
Comments
RGB, it can be seen in image.c:load_image_cv |
@hemp110 Thanks~~ 😀 |
@hemp110 Hi I was looking for this in the code and as far is I understand the OpenCV documentation an image is read in the order BGR. Could you point me to the line where the order is flipped? How is it if I have not compiled darknet with OpenCV? |
Easy: That function in darknet uses OpenCV as an "image loader" to read images from disk. And OpenCV always reads images into BGR in RAM. Look at the final lines of that code: if (out.c > 1)
rgbgr_image(out); Meaning: If there are more than 1 channel (grayscale), run the function That function flips the Blue and Red channels. In other words it converts BGR (the data read from disk by OpenCV) into RGB (the format that Darknet wants). |
But wait, let's get more proof! OpenCV has a built-in implementation of Darknet's algorithms (it does not use any darknet source code). They are able to load Darknet models. Here's how they define Darknet importer: https://github.com/opencv/opencv/blob/631b246881f04021dfcdb2f6be03c6c108f82163/samples/dnn/models.yml yolo:
model: "yolov3.weights"
config: "yolov3.cfg"
mean: [0, 0, 0]
scale: 0.00392
width: 416
height: 416
rgb: true
classes: "object_detection_classes_yolov3.txt"
sample: "object_detection" They use that information as follows: https://github.com/opencv/opencv/blob/5115e5decbef657ceb234d21ad8e8e33a6c96ca4/samples/dnn/classification.py blob = cv.dnn.blobFromImage(frame, args.scale, (inpWidth, inpHeight), args.mean, args.rgb, crop=False) So the "rgb: true/false" ( So, what conclusions can we get from how OpenCV implements Darknet:
|
Lastly, you can simply use OpenCV and try their darknet engine. If you feed it a BGR image of an object which has significant blue or red color, the "detection certainty" will be LOWER than if you feed it a proper RGB image of that object. This proves that the neural network weights are tuned for RGB. For example. I have a network trained on blue and red balls (precisely the channels that differ in BGR vs RGB). If I feed a BGR image to it, I get The neural network weights then decide how it reacts to each color channel. As you can see, the weights (trained by the official So yes, in every way, it is conclusively proven: Darknet is RGB-based, and the weights are RGB-based. |
Oh and wait, there's even more proof! Read this implementation of the actual Darknet library as a Python module: madhawav/YOLO3-4-Py#67 So yes, Darknet = RGB. |
No description provided.
The text was updated successfully, but these errors were encountered: