CVHub520 / X-AnyLabeling

Effortless data labeling with AI support from Segment Anything and other awesome models.
GNU General Public License v3.0
3.02k stars 342 forks source link

分类标注的相关问题 #480

Closed elichan5168 closed 1 day ago

elichan5168 commented 4 days ago

你好,

我想问一些问题。

  1. 我有一个数据集图片需要先分类,想问X-Anylabeling能不能只做图片分类的标签,而不用把物体定位框(bbox)画出来呢?我没找到直接打标签的地方? (现在版本似乎必需要先定位才能选择分类标签) 和https://github.com/cvat-ai/cvat/issues/1465 (这个问题比较类似)

  2. 我还有另一个数据集,这个数据集只做了分类的标签,所以我想用X-Anylabeling先导入这部分已经分类好的分类标签,然后我再手动进行定位框的操作。这可以做到吗?(由于数据量太大,如果可以能节省很多时间)

  3. 另外我还发现一个bug. 在win10上我用的requirements-gpu.txt安装后加载模型会闪退。ubuntu不会。

    
    PS D:\X-AnyLabeling> python .\anylabeling\app.py
    Traceback (most recent call last):
    File "D:\X-AnyLabeling\anylabeling\utils.py", line 15, in run
    self.func(*self.args, **self.kwargs)
    File "D:\X-AnyLabeling\anylabeling\services\auto_labeling\model_manager.py", line 687, in _load_model
    from .grounding_dino import Grounding_DINO
    File "D:\X-AnyLabeling\anylabeling\services\auto_labeling\grounding_dino.py", line 18, in <module>
    from .engines.build_onnx_engine import OnnxBaseModel
    File "D:\X-AnyLabeling\anylabeling\services\auto_labeling\engines\__init__.py", line 1, in <module>
    from .build_onnx_engine import OnnxBaseModel
    File "D:\X-AnyLabeling\anylabeling\services\auto_labeling\engines\build_onnx_engine.py", line 3, in <module>
    import onnxruntime as ort
    File "C:\Users\elich\AppData\Local\Programs\Python\Python311\Lib\site-packages\onnxruntime\__init__.py", line 57, in <module>
    raise import_capi_exception
    File "C:\Users\elich\AppData\Local\Programs\Python\Python311\Lib\site-packages\onnxruntime\__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\elich\AppData\Local\Programs\Python\Python311\Lib\site-packages\onnxruntime\capi\_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ImportError: DLL load failed while importing onnxruntime_pybind11_state: 动态链接库(DLL)初始化例程失败。

然后我win10把onnxruntime-gpu降到1.16.0版本就解决了.

谢谢。
CVHub520 commented 1 day ago

Regarding your queries about X-AnyLabeling:

  1. Direct Image Classification Without Bounding Boxes: Currently, X-AnyLabeling does not provide a direct option for image classification without drawing bounding boxes. However, a workaround exists where you can use a rectangle covering the entire image to assign a category. This rectangle effectively serves as a bounding box for the whole image, allowing you to specify its classification through the label assigned to it.
  2. Importing Pre-Classified Labels: If you already have a dataset classified with labels but no bounding boxes, you can automate the creation of JSON files for each image, which contain the necessary information for X-AnyLabeling to recognize the classification. These JSON files should include details like the image path, dimensions, and a rectangle that covers the entire image area, tagged with the respective classification label. After creating these JSON files, you can import them into X-AnyLabeling, which will then recognize the classifications and allow you to add bounding boxes or other annotations as needed.
  3. onnxruntime-gpu Crash on Win10: The crash you experienced with onnxruntime-gpu on Windows 10 was likely due to version incompatibility. Downgrading to version 1.16.0 resolved the issue, indicating that there might have been conflicts with newer versions in your specific environment. It's essential to ensure that the CUDA version installed on your system matches the version required by onnxruntime-gpu to prevent such issues.

For your convenience, here's a Python script snippet to generate JSON files for importing pre-classified images into X-AnyLabeling:

import cv2
import json

def create_annotation_json(image_path, label, image_width, image_height):
    annotation = {
        "version": "2.3.5",
        "flags": {},
        "shapes": [
            {
                "label": label,
                "points": [[0, 0], [image_width, 0], [image_width, image_height], [0, image_height]],
                "group_id": None,
                "shape_type": "rectangle",
                "flags": {}
            }
        ],
        "imagePath": image_path,
        "imageData": None,
        "imageHeight": image_height,
        "imageWidth": image_width
    }
    return annotation

# Example usage:
image_path = "path_to_your_image.jpg"
label = "your_label"
image  = cv2.imread(image_path)
image_height, image_width, _ =  image.shape()

annotation = create_annotation_json(image_path, label, image_width, image_height)

# Save the JSON to a file
with open("path_to_save_annotation.json", "w") as f:
    json.dump(annotation, f, indent=4)

Remember to replace "path_to_your_image.jpg" and "your_label" with the actual path to your image and its corresponding classification label. Repeat this process for each image in your dataset.

This script generates a JSON file for each image, which you can then import into X-AnyLabeling. By doing so, you'll be able to leverage the existing classification labels while adding additional annotations as required.

Should you have further inquiries or require assistance with any other aspects of using X-AnyLabeling, feel free to ask. I'm here to help you make the most of this powerful annotation tool.

elichan5168 commented 1 day ago

@CVHub520 Thx, the issue is resolved. Looking forward to you adding the image classification mode in the future.