Closed gabrielcustodio closed 6 months ago
Hello, have you tried to format coordinates according to expected top-left oriented bounding box format ?
Specifically, I assume you have to change your script for:
x = x_min
y = y_max
Olá, você tentou formatar as coordenadas de acordo com o formato esperado da caixa delimitadora orientada para o canto superior esquerdo ?
Especificamente, presumo que você precise alterar seu script para:
x = x_min y = y_max
I'm currently testing like this:
def xywh_to_ls(bbox_ultralytics_result, original_width, original_height):
x, y, w, h = bbox_ultralytics_result
x_norm = 100 * x / original_width
y_norm = 100 * y / original_height
w_norm = 100 * w / original_width
h_norm = 100 * h / original_height
return x_norm, y_norm, w_norm, h_norm
detections = []
for i, box in enumerate(result.boxes.xywh):
bbox = box.tolist()
label = result.names[result.boxes.cls.tolist()[i]]
original_width = result.orig_img.shape[1]
original_height = result.orig_img.shape[0]
x_normalized, y_normalized, width_normalized, height_normalized = xywh_to_ls(bbox, original_width, original_height)
Ultralytics boxes:
ultralytics.engine.results.Boxes object with attributes:
cls: tensor([9., 9., 9., 7., 9., 3., 9., 7., 7., 3., 9., 7., 3., 9., 4., 9., 7., 7., 5., 9., 3., 9., 3., 9., 3., 7., 9., 9.], device='cuda:0')
conf: tensor([0.9167, 0.9137, 0.8963, 0.8511, 0.8300, 0.8073, 0.7630, 0.7490, 0.7433, 0.7355, 0.6967, 0.6671, 0.6372, 0.6344, 0.5937, 0.5654, 0.5649, 0.5233, 0.5055, 0.4506, 0.4270, 0.4175, 0.4159, 0.3761, 0.3645, 0.3453, 0.3300, 0.2910], device='cuda:0')
data: tensor([[6.6103e+01, 4.1246e+02, 4.1573e+02, 4.4840e+02, 9.1671e-01, 9.0000e+00],
[6.6274e+01, 4.7640e+02, 4.1664e+02, 5.3017e+02, 9.1369e-01, 9.0000e+00],
[6.4793e+01, 1.0896e+02, 4.1708e+02, 1.3592e+02, 8.9630e-01, 9.0000e+00],
[6.5888e+01, 1.4498e+02, 2.7720e+02, 1.5459e+02, 8.5109e-01, 7.0000e+00],
[6.6257e+01, 3.5752e+02, 4.1628e+02, 4.0268e+02, 8.3002e-01, 9.0000e+00],
[6.5197e+01, 2.6787e+02, 4.1539e+02, 2.8642e+02, 8.0733e-01, 3.0000e+00],
[6.5983e+01, 5.4946e+02, 4.1597e+02, 5.8520e+02, 7.6295e-01, 9.0000e+00],
[6.5751e+01, 9.9946e+01, 2.4232e+02, 1.0919e+02, 7.4900e-01, 7.0000e+00],
[6.8400e+01, 3.4850e+02, 3.0790e+02, 3.5770e+02, 7.4328e-01, 7.0000e+00],
[6.6393e+01, 1.9816e+02, 4.1599e+02, 2.1588e+02, 7.3549e-01, 3.0000e+00],
[6.5502e+01, 8.1790e+01, 3.4366e+02, 9.0375e+01, 6.9675e-01, 9.0000e+00],
[6.6488e+01, 7.2069e+01, 2.6415e+02, 8.1756e+01, 6.6708e-01, 7.0000e+00],
[6.5391e+01, 2.1577e+02, 4.1652e+02, 2.6821e+02, 6.3715e-01, 3.0000e+00],
[6.5677e+01, 1.6322e+02, 4.1638e+02, 1.9815e+02, 6.3439e-01, 9.0000e+00],
[6.5471e+01, 6.0457e+02, 2.7216e+02, 6.1335e+02, 5.9370e-01, 4.0000e+00],
[6.5878e+01, 3.2203e+02, 4.1436e+02, 3.3896e+02, 5.6540e-01, 9.0000e+00],
[6.6811e+01, 4.5824e+02, 3.6414e+02, 4.6693e+02, 5.6491e-01, 7.0000e+00],
[6.8107e+01, 5.4027e+02, 2.8671e+02, 5.4898e+02, 5.2332e-01, 7.0000e+00],
[4.3955e+02, 5.9928e+02, 4.4831e+02, 6.1653e+02, 5.0554e-01, 5.0000e+00],
[6.5121e+01, 3.0415e+02, 3.7609e+02, 3.1249e+02, 4.5062e-01, 9.0000e+00],
[6.5641e+01, 1.6310e+02, 4.1635e+02, 1.9819e+02, 4.2699e-01, 3.0000e+00],
[6.6029e+01, 1.5434e+02, 2.7844e+02, 1.6295e+02, 4.1747e-01, 9.0000e+00],
[6.5385e+01, 3.0419e+02, 3.7572e+02, 3.1261e+02, 4.1594e-01, 3.0000e+00],
[6.4910e+01, 5.4165e+01, 2.0841e+02, 6.3736e+01, 3.7608e-01, 9.0000e+00],
[1.0812e+02, 2.8548e+02, 3.4789e+02, 2.9467e+02, 3.6451e-01, 3.0000e+00],
[6.5026e+01, 5.3653e+01, 2.1026e+02, 6.3768e+01, 3.4526e-01, 7.0000e+00],
[6.8176e+01, 2.8556e+02, 3.0793e+02, 2.9466e+02, 3.3000e-01, 9.0000e+00],
[6.7369e+01, 4.5836e+02, 3.6256e+02, 4.6700e+02, 2.9095e-01, 9.0000e+00]], device='cuda:0')
id: None
is_track: False
orig_shape: (640, 480)
shape: torch.Size([28, 6])
xywh: tensor([[240.9149, 430.4289, 349.6242, 35.9363],
[241.4559, 503.2850, 350.3636, 53.7660],
[240.9347, 122.4383, 352.2844, 26.9566],
[171.5444, 149.7842, 211.3135, 9.6095],
[241.2698, 380.1006, 350.0247, 45.1614],
[240.2940, 277.1457, 350.1942, 18.5416],
[240.9749, 567.3312, 349.9835, 35.7407],
[154.0358, 104.5684, 176.5699, 9.2449],
[188.1510, 353.1001, 239.5015, 9.1981],
[241.1929, 207.0205, 349.5989, 17.7244],
[204.5826, 86.0824, 278.1608, 8.5853],
[165.3209, 76.9128, 197.6664, 9.6873],
[240.9580, 241.9916, 351.1334, 52.4418],
[241.0279, 180.6803, 350.7014, 34.9299],
[168.8179, 608.9608, 206.6939, 8.7793],
[240.1215, 330.4929, 348.4865, 16.9290],
[215.4732, 462.5850, 297.3251, 8.6917],
[177.4067, 544.6261, 218.6003, 8.7130],
[443.9305, 607.9051, 8.7640, 17.2546],
[220.6069, 308.3215, 310.9727, 8.3423],
[240.9976, 180.6438, 350.7142, 35.0915],
[172.2325, 158.6430, 212.4079, 8.6135],
[220.5535, 308.4035, 310.3365, 8.4172],
[136.6578, 58.9508, 143.4961, 9.5713],
[228.0035, 290.0759, 239.7738, 9.1925],
[137.6447, 58.7105, 145.2382, 10.1155],
[188.0539, 290.1083, 239.7565, 9.0975],
[214.9634, 462.6798, 295.1891, 8.6309]], device='cuda:0')
xywhn: tensor([[0.5019, 0.6725, 0.7284, 0.0562],
[0.5030, 0.7864, 0.7299, 0.0840],
[0.5019, 0.1913, 0.7339, 0.0421],
[0.3574, 0.2340, 0.4402, 0.0150],
[0.5026, 0.5939, 0.7292, 0.0706],
[0.5006, 0.4330, 0.7296, 0.0290],
[0.5020, 0.8865, 0.7291, 0.0558],
[0.3209, 0.1634, 0.3679, 0.0144],
[0.3920, 0.5517, 0.4990, 0.0144],
[0.5025, 0.3235, 0.7283, 0.0277],
[0.4262, 0.1345, 0.5795, 0.0134],
[0.3444, 0.1202, 0.4118, 0.0151],
[0.5020, 0.3781, 0.7315, 0.0819],
[0.5021, 0.2823, 0.7306, 0.0546],
[0.3517, 0.9515, 0.4306, 0.0137],
[0.5003, 0.5164, 0.7260, 0.0265],
[0.4489, 0.7228, 0.6194, 0.0136],
[0.3696, 0.8510, 0.4554, 0.0136],
[0.9249, 0.9499, 0.0183, 0.0270],
[0.4596, 0.4818, 0.6479, 0.0130],
[0.5021, 0.2823, 0.7307, 0.0548],
[0.3588, 0.2479, 0.4425, 0.0135],
[0.4595, 0.4819, 0.6465, 0.0132],
[0.2847, 0.0921, 0.2990, 0.0150],
[0.4750, 0.4532, 0.4995, 0.0144],
[0.2868, 0.0917, 0.3026, 0.0158],
[0.3918, 0.4533, 0.4995, 0.0142],
[0.4478, 0.7229, 0.6150, 0.0135]], device='cuda:0')
xyxy: tensor([[ 66.1028, 412.4607, 415.7270, 448.3970],
[ 66.2741, 476.4020, 416.6376, 530.1680],
[ 64.7925, 108.9600, 417.0769, 135.9166],
[ 65.8876, 144.9795, 277.2011, 154.5890],
[ 66.2574, 357.5200, 416.2822, 402.6813],
[ 65.1969, 267.8749, 415.3911, 286.4165],
[ 65.9831, 549.4609, 415.9666, 585.2016],
[ 65.7508, 99.9460, 242.3207, 109.1908],
[ 68.4003, 348.5010, 307.9018, 357.6991],
[ 66.3935, 198.1583, 415.9924, 215.8827],
[ 65.5022, 81.7897, 343.6631, 90.3750],
[ 66.4876, 72.0691, 264.1541, 81.7564],
[ 65.3913, 215.7707, 416.5247, 268.2125],
[ 65.6772, 163.2153, 416.3785, 198.1452],
[ 65.4709, 604.5712, 272.1649, 613.3505],
[ 65.8782, 322.0284, 414.3647, 338.9574],
[ 66.8106, 458.2392, 364.1358, 466.9308],
[ 68.1065, 540.2696, 286.7068, 548.9826],
[439.5485, 599.2778, 448.3125, 616.5324],
[ 65.1205, 304.1504, 376.0932, 312.4927],
[ 65.6405, 163.0981, 416.3547, 198.1895],
[ 66.0285, 154.3362, 278.4364, 162.9497],
[ 65.3852, 304.1949, 375.7217, 312.6121],
[ 64.9098, 54.1651, 208.4059, 63.7365],
[108.1166, 285.4797, 347.8904, 294.6722],
[ 65.0255, 53.6528, 210.2638, 63.7682],
[ 68.1756, 285.5596, 307.9322, 294.6571],
[ 67.3688, 458.3644, 362.5579, 466.9952]], device='cuda:0')
xyxyn: tensor([[0.1377, 0.6445, 0.8661, 0.7006],
[0.1381, 0.7444, 0.8680, 0.8284],
[0.1350, 0.1703, 0.8689, 0.2124],
[0.1373, 0.2265, 0.5775, 0.2415],
[0.1380, 0.5586, 0.8673, 0.6292],
[0.1358, 0.4186, 0.8654, 0.4475],
[0.1375, 0.8585, 0.8666, 0.9144],
[0.1370, 0.1562, 0.5048, 0.1706],
[0.1425, 0.5445, 0.6415, 0.5589],
[0.1383, 0.3096, 0.8667, 0.3373],
[0.1365, 0.1278, 0.7160, 0.1412],
[0.1385, 0.1126, 0.5503, 0.1277],
[0.1362, 0.3371, 0.8678, 0.4191],
[0.1368, 0.2550, 0.8675, 0.3096],
[0.1364, 0.9446, 0.5670, 0.9584],
[0.1372, 0.5032, 0.8633, 0.5296],
[0.1392, 0.7160, 0.7586, 0.7296],
[0.1419, 0.8442, 0.5973, 0.8578],
[0.9157, 0.9364, 0.9340, 0.9633],
[0.1357, 0.4752, 0.7835, 0.4883],
[0.1368, 0.2548, 0.8674, 0.3097],
[0.1376, 0.2412, 0.5801, 0.2546],
[0.1362, 0.4753, 0.7828, 0.4885],
[0.1352, 0.0846, 0.4342, 0.0996],
[0.2252, 0.4461, 0.7248, 0.4604],
[0.1355, 0.0838, 0.4380, 0.0996],
[0.1420, 0.4462, 0.6415, 0.4604],
[0.1404, 0.7162, 0.7553, 0.7297]], device='cuda:0')
@niklub I fix it, thank you Now I'm normalizing correctly
Solution:
def xyxy_to_ls(bbox_ultralytics_result, original_width, original_height):
x_min, y_min, x_max, y_max = bbox_ultralytics_result
width = x_max - x_min
height = y_max - y_min
pixel_x = x_min / original_width * 100
pixel_y = y_min / original_height * 100
pixel_width = width / original_width * 100
pixel_height = height / original_height * 100
return pixel_x, pixel_y, pixel_width, pixel_height
Just to keep it documented, I got in touch via slack and received support there from Nikolai, thank you
I used LabelStudio converter in my folder dataset from YoloV8 Ultralytics for object detection.
label-studio-converter import yolo -i yolo_path -o ls-tasks.json
and return this structure:
I copy and paste on LabelStudio interface config.
Using this function to LabelStudio boxes. from xyxy (yolo ultralytics) I converted using:
Ok here.
Problem: My bounding boxes not working on LabelStudio. But my model infers correctly.![image](https://github.com/HumanSignal/label-studio/assets/26432437/fd7419ff-3f76-485a-a1b9-c8db064d6392)
Using this data to import task on LabelStudio