STDC分割网络:onnx推理

def STDCProcess(img):
    mean = [0.485, 0.456, 0.406]
    std = [0.229, 0.224, 0.225]
    img = cv2.resize(img, (256, 256))
    img = img.astype(np.float32)
    img = img[:, :, ::-1]#  BGR2RGB
    img = (img / 255.0 - mean) / std
    img = np.transpose(img, [2, 0, 1])
    img = np.ascontiguousarray(img)
    img = img.astype(np.float32)
    img = img[np.newaxis, :, :, :]
    return img


def stdcOnnxInfer():
    session = onnxruntime.InferenceSession("D:\\onnx\\danzhizhen-model-2022-01-15.onnx")
    # for root, dirs, files in os.walk("/home/tetra/data/validation/1"):cp
    img = cv2.imread('D:\\images\\youweiji.png')
    cv2.imshow('raw',img)
    img = STDCProcess(img)
    output = session.run(None, {"input": img})[0][0]
    #cv2.imwrite("seg.jpg",output)
    cv2.imshow('sg0',output[0])
    cv2.imshow('sg1', output[1])
    # print(output)
    cv2.waitKey(0)

你可能感兴趣的:(深度学习,语义分割,opencv,语义分割)