PeterL1n / RobustVideoMatting

Robust Video Matting in PyTorch, TensorFlow, TensorFlow.js, ONNX, CoreML!
https://peterl1n.github.io/RobustVideoMatting/
GNU General Public License v3.0
8.32k stars 1.11k forks source link

About ONNX inference input #244

Closed ChusanTang closed 12 months ago

ChusanTang commented 12 months ago

Hi, there is a question that bothers me. this code

    for src in YOUR_VIDEO:
    io.bind_cpu_input('src', src)
    io.bind_ortvalue_input('r1i', rec[0])
    io.bind_ortvalue_input('r2i', rec[1])
    io.bind_ortvalue_input('r3i', rec[2])
    io.bind_ortvalue_input('r4i', rec[3])
    io.bind_ortvalue_input('downsample_ratio', downsample_ratio)
    sess.run_with_iobinding(io)  

in ONNX inference. What should i input in this value YOUR_VIDEO. Can you show me what kind of image or video data type should be inputed? Using cv2.imread() seems not work. Here is my code

YOUR_VIDEO = [cv2.imread('image.png').astype(np.float16)]
# Inference loop
for src in YOUR_VIDEO:
    io.bind_cpu_input('src', src)
    io.bind_ortvalue_input('r1i', rec[0])
    io.bind_ortvalue_input('r2i', rec[1])
    io.bind_ortvalue_input('r3i', rec[2])
    io.bind_ortvalue_input('r4i', rec[3])
    io.bind_ortvalue_input('downsample_ratio', downsample_ratio)

When it run to sess.run_with_iobinding(io),i got an error Invalid rank for input: src Got: 3 Expected: 4 Please fix either the inputs or the model.. The image data format of the picture is {ndarray:(1080, 1920, 3)}. IT seems that i should input a four-dimensional data.

ChusanTang commented 12 months ago

Done

img = cv2.imread('temp/img_344_65_714_624.png').astype(np.float16)
YOUR_VIDEO = [np.expand_dims(np.transpose(img, (2, 0, 1)), axis=0)/255]

it takes {ndarray:(1,3,h,w)}