Skip to content
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

Single-channel YOLOv4 Tiny inference with use OpenVINO #56

Open
susanin1970 opened this issue Oct 25, 2021 · 0 comments
Open

Single-channel YOLOv4 Tiny inference with use OpenVINO #56

susanin1970 opened this issue Oct 25, 2021 · 0 comments

Comments

@susanin1970
Copy link

Hi!
I have trained on single-channel images YOLOv4 TIny .weights file

Then I got frozen_darknet_yolov4_model.pb file of this model with use follow command:

python .\convert_weights_pb.py --class_names "D:\Repositories\isocontainercodes-training\pipeline\yolo\names.list" --weights_file "D:\Repositories\isocontainercodes-training\pipeline\yolo\yolov4-tiny-mixed_y8-v3.weights" --data_format NHWC --tiny

Before that, I changed the line in convert_weights_pb.py so that there were not 3 channels, but 1:

    # placeholder for detector inputs
    inputs = tf.placeholder(tf.float32, [None, FLAGS.size, FLAGS.size, 1], "inputs")

Then I got .bin and .xml files of OpenVINO IR model with use following command:

"C:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\model_optimize\mo.py" --input_model .\frozen_darknet_yolov4_model.pb --transformations_config .\yolo_v4_tiny.json --batch 1 --reverse_input_channels

When I tried to run inference:

python .\pythondemo\2021.3\object_detection_demo_yolov3_async.py -i "C:\Users\Reutov\Desktop\test_nmtp_video_4.mp4" -m .\frozen_darknet_yolov4_model.xml -d CPU

I got this:

image

Before that I changed code of object_detection_demo_yolov3_async.py:

def resize(image, size, keep_aspect_ratio, interpolation=cv2.INTER_LINEAR):
    if not keep_aspect_ratio:
        return cv2.resize(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), size, interpolation=interpolation)

    iw, ih = image.shape[0:2][::-1]
    w, h = size
    scale = min(w/iw, h/ih)
    nw = int(iw*scale)
    nh = int(ih*scale)
    image = cv2.resize(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), (nw, nh), interpolation=interpolation)
    new_image = np.full((size[1], size[0], 3), 128, dtype=np.uint8)
    dx = (w-nw)//2
    dy = (h-nh)//2
    new_image[dy:dy+nh, dx:dx+nw, :] = image
    return new_image  
# Read and pre-process input images
    if net.input_info[input_blob].input_data.shape[1] == 3:
        input_height, input_width = net.input_info[input_blob].input_data.shape[2:]
        nchw_shape = True
    else:
        input_height, input_width = net.input_info[input_blob].input_data.shape[2:]
        nchw_shape = False  

.weights model YOLOv4 Tiny works in darknet normally:
image

What should I do to make the YOLOv4 Tiny single-channel model give correct detections using OpenVINO?
Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant