efficientvit icon indicating copy to clipboard operation
efficientvit copied to clipboard

tensorRT multiple point inference bug fixed

Open ghm666 opened this issue 11 months ago • 0 comments

I encountered this problem in #85

https://github.com/mit-han-lab/efficientvit/issues/85#issuecomment-2002749929

python trt_inference.py --model xl1 --encoder_engine ./xl1_encoder.engine --decoder_engine ./xl1_decoder.engine --mode point --point [[[510,356,1],[749,748,0],[100,100,1]]] --img_path ./images/test_3.JPEG --out_path ./vit_trt_img.png

I performed a 3-point inference using the tensorRT model, and the following error occurred

[03/18/2024-09:53:16] [TRT] [E] 3: [executionContext.cpp::validateInputBindings::2016] Error Code 3: API Usage Error (Parameter check failed at: runtime/api/executionContext.cpp::validateInputBindings::2016, condition: profileMaxDims.d[i] >= dimensions.d[i]. Supplied binding dimension [1,3,2] for bindings[1] exceed min ~ max range at index 1, maximum dimension in profile is 2, minimum dimension in profile is 1, but supplied dimension is 3. )

[03/18/2024-09:53:16] [TRT] [E] 3: [executionContext.cpp::validateInputBindings::2016] Error Code 3: API Usage Error (Parameter check failed at: runtime/api/executionContext.cpp::validateInputBindings::2016, condition: profileMaxDims.d[i] >= dimensions.d[i]. Supplied binding dimension [1,3] for bindings[2] exceed min ~ max range at index 1, maximum dimension in profile is 2, minimum dimension in profile is 1, but supplied dimension is 3. )

I use the following code to solve this problem

deployment/sam/tensorrt/inference.py

 if args.mode == "point":
        H, W, _ = raw_img.shape
        point = np.array(yaml.safe_load(args.point or f"[[[{W // 2}, {H // 2}, {1}]]]"), dtype=np.float32)
        point_coords = point[..., :2]
        point_labels = point[..., 2]
        orig_point_coords = deepcopy(point_coords)
        orig_point_labels = deepcopy(point_labels)
        point_coords = apply_coords(point_coords, origin_image_size, input_size).astype(np.float32)

modify

 if args.mode == "point":
        H, W, _ = raw_img.shape
        point = np.array(yaml.safe_load(args.point or f"[[[{W // 2}, {H // 2}, {1}]]]"), dtype=np.float32)
        point_coords = point[..., :2].transpose(1,0,2)
        point_labels = point[..., 2].transpose(1,0)
        orig_point_coords = deepcopy(point_coords)
        orig_point_labels = deepcopy(point_labels)
        point_coords = apply_coords(point_coords, origin_image_size, input_size).astype(np.float32)

Here the problem is solved

ghm666 avatar Mar 18 '24 04:03 ghm666