alianse777 / darknet-rust

A Rust wrapper for Darknet, an open source neural network framework written in C and CUDA.
http://pjreddie.com/darknet/
MIT License
33 stars 8 forks source link

Is the input for the darknet model RGB or BGR, ranging in [0.0, 1.0] or [0, 255]? #13

Closed wuhanstudio closed 3 years ago

wuhanstudio commented 3 years ago

Hi,

I'm trying to construct an image for the darknet model inference.

But I'm not sure if the sequence of the raw image data for the darknet input is RGB or BGR.

And is the range of the pixel value [0.0, 1.0] or [0, 255]

// Create an empty image
let dimg = unsafe { darknet_sys::make_image(640, 480, 3) };

// Fill the data with RGB ranging from [0, 1]
let slice = unsafe { slice::from_raw_parts_mut(dimg.data, 640*480*3) }; 
for i in 0..640*480*3 {
    slice[i] = v.data[i] as f32 / 255.0;
}

// let d_img = unsafe { darknet_sys::resize_image(dimg, 416, 416) };

let img = darknet::Image {
    image: d_img
};

// Make prediction
let detections = net.lock().unwrap().predict(&img, 0.25, 0.5, 0.45, true);

Thanks for your help.

wuhanstudio commented 3 years ago

I see from the example that the input is RGB [0.0, 1.0].

Everything works if I load the image from file. But if I construct the image using raw RGB [0.0, 1.0] from the camera, nothing is detected.

alianse777 commented 3 years ago

The network itself sees [0.0, 1.0]. Are you trying to construct DynamicImage first, then convert to darknet Image? If not, use DynamicImage as it is part of stable API.

wuhanstudio commented 3 years ago

Thanks for your reply.

I construct an image using darknet_sys::make_image

let dimg = unsafe { darknet_sys::make_image(width, height, channel) };

Filling the data, then pass it to darknet::Image:

let img = darknet::Image {
    image: d_img
};

I'll try DynamicImage, thanks for your help.

This is the full project that detects objects using images from ROS Camera:

https://github.com/wuhanstudio/rust-ros-detection