Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]why can't I open my own datasets in yolov8 format? #4691

Open
2 tasks
Edward-YS opened this issue Aug 16, 2024 · 1 comment
Open
2 tasks

[BUG]why can't I open my own datasets in yolov8 format? #4691

Edward-YS opened this issue Aug 16, 2024 · 1 comment
Labels
bug Bug fixes

Comments

@Edward-YS
Copy link

Edward-YS commented Aug 16, 2024

Describe the problem

HELLO! I'm just a new guy to use the fiftyone which is a good tool. I want to open my own datasets in yolov8 format and see the marked rectangle box. It can add sample to my dataset but turn to be wrong when it opens the fiftyone website and report an error "No dataset selected"

Code to reproduce issue

import glob
import os
import fiftyone as fo
from fiftyone import Sample, Detection, Dataset

图片和YOLO标注文件的路径

images_dir = r"D:/auto_Detection/鸟类检测/数据集/fiftyone下载10000/train/images"
annotations_dir = r"D:/auto_Detection/鸟类检测/数据集/fiftyone下载10000/train/labels"

支持的类别

classes = ["bird"] # 根据你的数据集替换类别列表

获取所有图片路径

images_patt = os.path.join(images_dir, "*.jpg") # 假设图片是.jpg格式
image_paths = glob.glob(images_patt)

创建数据集

dataset_name = "bird_dataset"
dataset = Dataset(name=dataset_name)

遍历所有图片

for image_path in image_paths:
# 生成YOLO标注文件的完整路径
annotation_path = os.path.join(annotations_dir, os.path.splitext(os.path.basename(image_path))[0] + ".txt")

# 初始化一个空的样本
sample = Sample(filepath=image_path)

# 读取YOLO标注文件
if os.path.isfile(annotation_path):
    with open(annotation_path, "r") as f:
        lines = f.readlines()
        detections = []
        for line in lines:
            # YOLO格式通常为 <class_index> <x> <y> <width> <height>
            parts = line.strip().split()
            if len(parts) < 5:
                continue
            class_index = int(parts[0])
            x, y, width, height = map(float, parts[1:5])
            # 转换为(x_min, y_min, x_max, y_max)格式
            x_min = x - width / 2
            y_min = y - height / 2
            x_max = x + width / 2
            y_max = y + height / 2
            label = classes[class_index]
            
            # 创建检测标注并添加到样本中
            detection = Detection(
                label=label,
                bounding_box=[x_min, y_min, x_max - x_min, y_max - y_min],
                confidence=1.0  # 假设分数为1.0
            )
            detections.append(detection)

# 将检测标注添加到样本
sample["ground_truth"] = fo.Detections(detections=detections)

# 将样本添加到数据集
dataset.add_sample(sample)

启动FiftyOne App并可视化标注的矩形框

session= fo.launch_app(dataset)
session.wait()

![LFZH0)P897HT5F4KW}P(X$U](https://github.com/user-attachments/assets/8c55c177-ee98-4037-bc56-34a030b36376)

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 22.04):Windows
  • Python version (python --version):3.10.14
  • FiftyOne version (fiftyone --version):0.24.1
  • FiftyOne installed from (pip or source):pip

Other info/logs

Include any logs or source code that would be helpful to diagnose the problem.
If including tracebacks, please include the full traceback. Large logs and
files should be attached. Please do not use screenshots for sharing text. Code
snippets should be used instead when providing tracebacks, logs, etc.

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?

  • Yes. I can contribute a fix for this bug independently
  • [√ ] Yes. I would be willing to contribute a fix for this bug with guidance
    from the FiftyOne community
  • No. I cannot contribute a bug fix at this time
@Edward-YS Edward-YS added the bug Bug fixes label Aug 16, 2024
@benjaminpkane
Copy link
Contributor

benjaminpkane commented Aug 16, 2024

Hi @Edward-YS 👋 This FAQ might help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants