voxel51 / fiftyone

The open-source tool for building high-quality datasets and computer vision models
https://fiftyone.ai
Apache License 2.0
7.92k stars 521 forks source link

[BUG] Can not display Polylines Label in Fiftyone App #2810

Closed stevezkw1998 closed 1 year ago

stevezkw1998 commented 1 year ago

System information

Describe the problem

files image

fiftyone App image No labels displayed

Sample in fiftyone App image No labels displayed

Code to reproduce issue

polygons.json

[
    {
        "filepath": "./Sensor1_2023-01-09_10-29-09-610.png",
        "annotations": [
            {
                "label": "floor",
                "points": [
                    [
                        0.6787330316742128,
                        287.78280542986425
                    ],
                    [
                        45.022624434389144,
                        286.4253393665158
                    ],
                    [
                        49.09502262443439,
                        288.235294117647
                    ],
                    [
                        64.93212669683257,
                        288.235294117647
                    ],
                    [
                        75.79185520361992,
                        285.0678733031674
                    ],
                    [
                        98.86877828054298,
                        283.710407239819
                    ],
                    [
                        140.49773755656108,
                        280.0904977375565
                    ],
                    [
                        154.07239819004528,
                        279.18552036199094
                    ],
                    [
                        162.66968325791854,
                        282.35294117647055
                    ],
                    [
                        173.07692307692307,
                        278.2805429864253
                    ],
                    [
                        178.95927601809953,
                        281.447963800905
                    ],
                    [
                        192.98642533936655,
                        283.2579185520362
                    ],
                    [
                        202.94117647058826,
                        279.18552036199094
                    ],
                    [
                        207.0135746606335,
                        274.6606334841629
                    ],
                    [
                        240.04524886877826,
                        274.6606334841629
                    ],
                    [
                        241.4027149321267,
                        282.80542986425337
                    ],
                    [
                        258.1447963800905,
                        284.6153846153846
                    ],
                    [
                        354.52488687782807,
                        280.99547511312215
                    ],
                    [
                        405.2036199095023,
                        274.6606334841629
                    ],
                    [
                        430.0904977375566,
                        267.8733031674208
                    ],
                    [
                        439.59276018099547,
                        267.8733031674208
                    ],
                    [
                        447.2850678733031,
                        272.39819004524884
                    ],
                    [
                        456.3348416289592,
                        273.75565610859724
                    ],
                    [
                        458.1447963800905,
                        280.99547511312215
                    ],
                    [
                        468.939393939394,
                        281.8181818181818
                    ],
                    [
                        470.81447963800906,
                        274.6606334841629
                    ],
                    [
                        615.6108597285067,
                        269.683257918552
                    ],
                    [
                        621.0407239819004,
                        276.9230769230769
                    ],
                    [
                        635.0678733031674,
                        276.9230769230769
                    ],
                    [
                        638.2352941176471,
                        268.3257918552036
                    ],
                    [
                        712.89592760181,
                        256.56108597285066
                    ],
                    [
                        725.5656108597285,
                        254.75113122171948
                    ],
                    [
                        753.6199095022624,
                        247.96380090497738
                    ],
                    [
                        761.3122171945702,
                        231.67420814479638
                    ],
                    [
                        760.4072398190045,
                        217.64705882352942
                    ],
                    [
                        799.0,
                        214.04942863716545
                    ],
                    [
                        799.0,
                        599.0
                    ],
                    [
                        0.0,
                        599.0
                    ]
                ]
            }
        ]
    },
    {
        "filepath": "./Sensor1_2023-01-09_10-29-38-351.png",
        "annotations": [
            {
                "label": "floor",
                "points": [
                    [
                        0.0,
                        300.5050505050505
                    ],
                    [
                        559.8484848484849,
                        261.6161616161616
                    ],
                    [
                        668.0995475113122,
                        262.4434389140271
                    ],
                    [
                        734.6153846153846,
                        254.29864253393666
                    ],
                    [
                        799.0,
                        254.29864253393666
                    ],
                    [
                        799.0,
                        599.0
                    ],
                    [
                        0.0,
                        599.0
                    ]
                ]
            }
        ]
    }
]

Run Script script.py

import json
import fiftyone as fo  # Load the JSON file
with open("./polygons.json", "r") as f:
 data = json.load(f)  # Create an empty dataset
# Populate the dataset with samples and annotations

dataset = fo.Dataset(name="my_polygon_dataset")
for item in data:
 filepath = item["filepath"]
 annotations = item["annotations"]  # Create a FiftyOne sample with the image
 # Convert the annotations to FiftyOne format
 sample = None
 sample = fo.Sample(filepath=filepath)
 polylines = []
 for ann in annotations:
    label = ann["label"]
    points = ann["points"]  # Add the polygon annotation'
    points = [[(float(x), float(y))] for x, y in points]
    # Add the polygons to the sample
    polyline = fo.Polyline(label=label, points=points, closed=True, filled=True, color="red")
    polylines.append(polyline)
 polylines = fo.Polylines(polylines=polylines)
 sample['ground_truth'] = polylines  # Add the sample to the dataset
 dataset.add_sample(sample.copy())  # Launch the FiftyOne App
session = fo.launch_app(dataset)

Other info/logs

One sample's JSON

{
  "_id": "64150d0d1f860b967f14aa18",
  "filepath": "C:\\code\\Kneron\\example_images\\example_images\\labelme_json\\Sensor1_2023-01-09_10-29-09-610.png",
  "tags": [],
  "_media_type": "image",
  "_rand": 0.9998944533671889,
  "ground_truth": {
    "_cls": "Polylines",
    "polylines": [
      {
        "_id": "64150d0d1f860b967f14aa17",
        "_cls": "Polyline",
        "attributes": {},
        "tags": [],
        "label": "floor",
        "points": [
          [
            [
              0.6787330316742128,
              287.78280542986425
            ]
          ],
          [
            [
              45.022624434389144,
              286.4253393665158
            ]
          ],
          [
            [
              49.09502262443439,
              288.235294117647
            ]
          ],
          [
            [
              64.93212669683257,
              288.235294117647
            ]
          ],
          [
            [
              75.79185520361992,
              285.0678733031674
            ]
          ],
          [
            [
              98.86877828054298,
              283.710407239819
            ]
          ],
          [
            [
              140.49773755656108,
              280.0904977375565
            ]
          ],
          [
            [
              154.07239819004528,
              279.18552036199094
            ]
          ],
          [
            [
              162.66968325791854,
              282.35294117647055
            ]
          ],
          [
            [
              173.07692307692307,
              278.2805429864253
            ]
          ],
          [
            [
              178.95927601809953,
              281.447963800905
            ]
          ],
          [
            [
              192.98642533936655,
              283.2579185520362
            ]
          ],
          [
            [
              202.94117647058826,
              279.18552036199094
            ]
          ],
          [
            [
              207.0135746606335,
              274.6606334841629
            ]
          ],
          [
            [
              240.04524886877826,
              274.6606334841629
            ]
          ],
          [
            [
              241.4027149321267,
              282.80542986425337
            ]
          ],
          [
            [
              258.1447963800905,
              284.6153846153846
            ]
          ],
          [
            [
              354.52488687782807,
              280.99547511312215
            ]
          ],
          [
            [
              405.2036199095023,
              274.6606334841629
            ]
          ],
          [
            [
              430.0904977375566,
              267.8733031674208
            ]
          ],
          [
            [
              439.59276018099547,
              267.8733031674208
            ]
          ],
          [
            [
              447.2850678733031,
              272.39819004524884
            ]
          ],
          [
            [
              456.3348416289592,
              273.75565610859724
            ]
          ],
          [
            [
              458.1447963800905,
              280.99547511312215
            ]
          ],
          [
            [
              468.939393939394,
              281.8181818181818
            ]
          ],
          [
            [
              470.81447963800906,
              274.6606334841629
            ]
          ],
          [
            [
              615.6108597285067,
              269.683257918552
            ]
          ],
          [
            [
              621.0407239819004,
              276.9230769230769
            ]
          ],
          [
            [
              635.0678733031674,
              276.9230769230769
            ]
          ],
          [
            [
              638.2352941176471,
              268.3257918552036
            ]
          ],
          [
            [
              712.89592760181,
              256.56108597285066
            ]
          ],
          [
            [
              725.5656108597285,
              254.75113122171948
            ]
          ],
          [
            [
              753.6199095022624,
              247.96380090497738
            ]
          ],
          [
            [
              761.3122171945702,
              231.67420814479638
            ]
          ],
          [
            [
              760.4072398190045,
              217.64705882352942
            ]
          ],
          [
            [
              799,
              214.04942863716545
            ]
          ],
          [
            [
              799,
              599
            ]
          ],
          [
            [
              0,
              599
            ]
          ]
        ],
        "closed": true,
        "filled": true,
        "color": "red"
      }
    ]
  },
  "_label_tags": {}
}

What areas of FiftyOne does this bug affect?

Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the FiftyOne codebase?

brimoor commented 1 year ago

Hi @stevezkw1998 👋

FiftyOne requires polyline and bounding box coordinates to be provided as relative values in [0, 1]: https://docs.voxel51.com/user_guide/using_datasets.html#polylines-and-polygons

stevezkw1998 commented 1 year ago

Hi @stevezkw1998 👋

FiftyOne requires polyline and bounding box coordinates to be provided as relative values in [0, 1]: https://docs.voxel51.com/user_guide/using_datasets.html#polylines-and-polygons /

Hi @brimoor Thank you for your comments, I've converted the points to range (0, 1), but still couldn't see the polylines image image modified

import json
import fiftyone as fo  # Load the JSON file
with open("./polygons.json", "r") as f:
 data = json.load(f)  # Create an empty dataset
# Populate the dataset with samples and annotations

dataset = fo.Dataset(name="my_polygon_dataset")
for item in data:
    filepath = item["filepath"]
    annotations = item["annotations"]  # Create a FiftyOne sample with the image
    image_height = item["imageHeight"]
    image_width = item["imageWidth"]
    # Convert the annotations to FiftyOne format
    sample = None
    sample = fo.Sample(filepath=filepath)
    polylines = []
    for ann in annotations:
        label = ann["label"]
        points = ann["points"]  # Add the polygon annotation'
        points = [[(float(x)/image_width, float(y)/image_height)] for x, y in points]
        # Add the polygons to the sample
        polyline = fo.Polyline(label=label, points=points, closed=True, filled=True, color="red")
        polylines.append(polyline)
    polylines = fo.Polylines(polylines=polylines)
    sample['ground_truth'] = polylines  # Add the sample to the dataset
    dataset.add_sample(sample.copy())  # Launch the FiftyOne App
session = fo.launch_app(dataset)
stevezkw1998 commented 1 year ago

Hi @brimoor , Polylines visualization issue was fixed, after I calibrated the format by myself, FYI image Original: points = [[(float(x)/image_width, float(y)/image_height)] for x, y in points] After change: points = [[(float(x)/image_width, float(y)/image_height) for x, y in points]]