Skip to content

Conversation

@Jiei-S
Copy link
Contributor

@Jiei-S Jiei-S commented Sep 6, 2023

概要

データセットをPython SDKから登録できる - dataset_objects
https://github.com/fastlabel/roadmap/issues/2

関連

https://github.com/fastlabel/fastlabel-application/pull/4376

テスト

Create

正常 - タグ_2件、アノテーション_セグメンテーション

create_dataset_object.txt
response.txt

スクリーンショット 2023-09-11 11 16 35
スクリーンショット 2023-09-11 11 13 31
※ 左から二つ目と同じアノテーションを付与

正常 - タグ_2件、アノテーション_矩形

dataset_object = client.create_dataset_object(
    dataset="test3",
    name="01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01562.JPG",
    file_path="examples/01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01562.JPG",
    tags=["cat", "dog"],
    annotations=[
        {
            "type": "bbox",
            "value": "class1",
            "points": [2815.73, 640.94, 3766.56, 1353.03],
            "attributes": [
                {
                    "key": "switch",
                    "value": "0",
                },
                {
                    "key": "select",
                    "value": "select2",
                },
            ],
            "keypoints": [
                {
                    "key": "key3",
                    "value": [],
                },
                {
                    "key": "key1",
                    "value": [3219.11, 731.5, 1],
                },
                {
                    "key": "key2",
                    "value": [],
                },
            ],
            "rotation": 0,
            "confidenceScore": -1,
        },
        {
            "type": "bbox",
            "value": "class1",
            "points": [835.87, 476.29, 1461.52, 1398.31],
            "attributes": [
                {
                    "key": "text",
                    "value": "value",
                },
                {
                    "key": "select",
                    "value": "select2",
                },
                {
                    "key": "switch",
                    "value": "1",
                },
            ],
            "keypoints": [
                {
                    "key": "key2",
                    "value": [1095.19, 1015.51, 1],
                },
                {
                    "key": "key3",
                    "value": [1317.46, 723.26, 1],
                },
                {
                    "key": "key1",
                    "value": [1074.6, 653.29, 1],
                },
            ],
            "rotation": 0,
            "confidenceScore": -1,
        },
        {
            "type": "bbox",
            "value": "class2",
            "points": [1494.45, 1830.5, 2799.27, 2814.26],
            "attributes": [
                {
                    "key": "check",
                    "value": ["check1", "check2"],
                }
            ],
            "keypoints": [],
            "rotation": 0,
            "confidenceScore": -1,
        },
    ],
)
{'annotations': [{'attributes': [{'key': 'check',
                                  'name': 'check',
                                  'type': 'checkbox',
                                  'value': ['check1', 'check2']}],
                  'color': '#FF0000',
                  'confidenceScore': -1,
                  'id': 'fc7b50f4-4c98-4557-b909-a405a939e6b8',
                  'keypoints': [],
                  'points': [1494.45, 1830.5, 2799.27, 2814.26],
                  'rotation': 0,
                  'title': 'class2',
                  'type': 'bbox',
                  'value': 'class2'},
                 {'attributes': [{'key': 'switch',
                                  'name': 'switch',
                                  'type': 'switch',
                                  'value': '1'},
                                 {'key': 'select',
                                  'name': 'select',
                                  'type': 'select',
                                  'value': 'select2'},
                                 {'key': 'text',
                                  'name': 'text',
                                  'type': 'text',
                                  'value': 'value'}],
                  'color': '#0033CC',
                  'confidenceScore': -1,
                  'id': '2fd68be5-0f88-4074-9ef6-b9c99209b332',
                  'keypoints': [{'edges': ['key1', 'key3'],
                                 'key': 'key2',
                                 'name': 'key2',
                                 'value': [1095.19, 1015.51, 1]},
                                {'edges': ['key1', 'key2'],
                                 'key': 'key3',
                                 'name': 'key3',
                                 'value': [1317.46, 723.26, 1]},
                                {'edges': ['key2', 'key3'],
                                 'key': 'key1',
                                 'name': 'key1',
                                 'value': [1074.6, 653.29, 1]}],
                  'points': [835.87, 476.29, 1461.52, 1398.31],
                  'rotation': 0,
                  'title': 'class1',
                  'type': 'bbox',
                  'value': 'class1'},
                 {'attributes': [{'key': 'select',
                                  'name': 'select',
                                  'type': 'select',
                                  'value': 'select2'},
                                 {'key': 'switch',
                                  'name': 'switch',
                                  'type': 'switch',
                                  'value': '0'}],
                  'color': '#0033CC',
                  'confidenceScore': -1,
                  'id': 'f897852a-7d87-4089-98e1-7ade28b24410',
                  'keypoints': [{'edges': ['key2', 'key3'],
                                 'key': 'key1',
                                 'name': 'key1',
                                 'value': [3219.11, 731.5, 1]},
                                {'edges': ['key1', 'key2'],
                                 'key': 'key3',
                                 'name': 'key3',
                                 'value': []},
                                {'edges': ['key1', 'key3'],
                                 'key': 'key2',
                                 'name': 'key2',
                                 'value': []}],
                  'points': [2815.73, 640.94, 3766.56, 1353.03],
                  'rotation': 0,
                  'title': 'class1',
                  'type': 'bbox',
                  'value': 'class1'}],
 'createdAt': '2023-09-11T01:40:37.809Z',
 'height': 3200,
 'id': 'f33c6230-eac5-4813-8987-10e3eac44a1a',
 'name': '01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01562.JPG',
 'size': 1035249,
 'tags': ['cat', 'dog'],
 'updatedAt': '2023-09-11T01:40:37.809Z',
 'width': 4800}

スクリーンショット 2023-09-11 10 43 39
スクリーンショット 2023-09-08 18 33 48
※ 一番左と同じアノテーション付与

異常 - タグ_文字数超過

dataset_object = client.create_dataset_object(
    dataset="test2",
    name="01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01561.JPG",
    file_path="examples/01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01561.JPG",
    tags=["cat", "dogdogdogdogdogdogdogdog"],
fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Dataset object tag is too long. Please use less than 20 characters.

異常 - タグ_件数超過

dataset_object = client.create_dataset_object(
    dataset="test2",
    name="01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01561.JPG",
    file_path="examples/01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01561.JPG",
    tags=["cat", "dog", "bird", "person", "car", "bicycle"],
fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Dataset object tags are too many. Please use less than 5 tags.

異常 - アノテーション_件数超過

fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Annotations must be 1200 annotations or less.

異常 - アノテーション_クラスなし

fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Annotation value (test) not found. Please create an annotation class at first.

異常 - アノテーション属性_キーなし

fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Attribute key (test) not found in annotation class (0). Please create an attribute at first.

異常 - アノテーション属性_値なし

fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Attribute value () must not be empty in attribute key (switch).

異常 - アノテーション属性_セレクトオプションなし

fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Attribute value (test) not found in attribute key (select) options. Please create options at first.

異常 - アノテーションキーポイント_キーなし

fastlabel.exceptions.FastLabelInvalidException: <Response [422]> Keypoint key (test) not found in annotation class (). Please create an keypoint at first.

Get

スクリーンショット 2023-09-11 12 22 07

正常 - バージョン

dataset_objects = client.get_dataset_objects(dataset="test3", version="1")
[{'annotations': [{'attributes': [{'key': 'switch',
                                   'name': 'switch',
                                   'type': 'switch',
                                   'value': '0'},
                                  {'key': 'text',
                                   'name': 'text',
                                   'type': 'text',
                                   'value': ''},
                                  {'key': 'select',
                                   'name': 'select',
                                   'type': 'select',
                                   'value': 'select2'}],
                   'color': '#0033CC',
                   'confidenceScore': -1,
                   'id': '0aa5d1c2-0161-4954-aba2-2362e3c916cb',
                   'keypoints': [{'edges': ['key1', 'key2'],
                                  'key': 'key3',
                                  'name': 'key3',
                                  'value': []},
                                 {'edges': ['key2', 'key3'],
                                  'key': 'key1',
                                  'name': 'key1',
                                  'value': [3219.11, 731.5, 1]},
                                 {'edges': ['key1', 'key3'],
                                  'key': 'key2',
                                  'name': 'key2',
                                  'value': []}],
                   'points': [2815.73, 640.94, 3766.56, 1353.03],
                   'rotation': 0,
                   'title': 'class1',
                   'type': 'bbox',
                   'value': 'class1'},
                  {'attributes': [{'key': 'text',
                                   'name': 'text',
                                   'type': 'text',
                                   'value': 'value'},
                                  {'key': 'select',
                                   'name': 'select',
                                   'type': 'select',
                                   'value': 'select2'},
                                  {'key': 'switch',
                                   'name': 'switch',
                                   'type': 'switch',
                                   'value': '1'}],
                   'color': '#0033CC',
                   'confidenceScore': -1,
                   'id': '30c96da4-abe9-45dc-9ade-6279e873098d',
                   'keypoints': [{'edges': ['key1', 'key3'],
                                  'key': 'key2',
                                  'name': 'key2',
                                  'value': [1095.19, 1015.51, 1]},
                                 {'edges': ['key1', 'key2'],
                                  'key': 'key3',
                                  'name': 'key3',
                                  'value': [1317.46, 723.26, 1]},
                                 {'edges': ['key2', 'key3'],
                                  'key': 'key1',
                                  'name': 'key1',
                                  'value': [1074.6, 653.29, 1]}],
                   'points': [835.87, 476.29, 1461.52, 1398.31],
                   'rotation': 0,
                   'title': 'class1',
                   'type': 'bbox',
                   'value': 'class1'},
                  {'attributes': [{'key': 'check',
                                   'name': 'check',
                                   'type': 'checkbox',
                                   'value': ['check1', 'check2']}],
                   'color': '#FF0000',
                   'confidenceScore': -1,
                   'id': '913e0c30-50a3-4345-a67c-2f55807f4e00',
                   'keypoints': [],
                   'points': [1494.45, 1830.5, 2799.27, 2814.26],
                   'rotation': 0,
                   'title': 'class2',
                   'type': 'bbox',
                   'value': 'class2'}],
  'createdAt': '2023-09-08T09:22:00.321Z',
  'height': 3200,
  'id': 'f9892005-f21f-4296-b54c-6d1d927cb548',
  'name': '01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01561.JPG',
  'size': 1008552,
  'tags': [],
  'updatedAt': '2023-09-08T09:22:00.321Z',
  'width': 4800},
 {'annotations': [{'attributes': [{'key': 'switch',
                                   'name': 'switch',
                                   'type': 'switch',
                                   'value': '1'},
                                  {'key': 'select',
                                   'name': 'select',
                                   'type': 'select',
                                   'value': 'select2'},
                                  {'key': 'text',
                                   'name': 'text',
                                   'type': 'text',
                                   'value': 'value'}],
                   'color': '#0033CC',
                   'confidenceScore': -1,
                   'id': '2fd68be5-0f88-4074-9ef6-b9c99209b332',
                   'keypoints': [{'edges': ['key1', 'key3'],
                                  'key': 'key2',
                                  'name': 'key2',
                                  'value': [1095.19, 1015.51, 1]},
                                 {'edges': ['key1', 'key2'],
                                  'key': 'key3',
                                  'name': 'key3',
                                  'value': [1317.46, 723.26, 1]},
                                 {'edges': ['key2', 'key3'],
                                  'key': 'key1',
                                  'name': 'key1',
                                  'value': [1074.6, 653.29, 1]}],
                   'points': [835.87, 476.29, 1461.52, 1398.31],
                   'rotation': 0,
                   'title': 'class1',
                   'type': 'bbox',
                   'value': 'class1'},
                  {'attributes': [{'key': 'select',
                                   'name': 'select',
                                   'type': 'select',
                                   'value': 'select2'},
                                  {'key': 'switch',
                                   'name': 'switch',
                                   'type': 'switch',
                                   'value': '0'}],
                   'color': '#0033CC',
                   'confidenceScore': -1,
                   'id': 'f897852a-7d87-4089-98e1-7ade28b24410',
                   'keypoints': [{'edges': ['key2', 'key3'],
                                  'key': 'key1',
                                  'name': 'key1',
                                  'value': [3219.11, 731.5, 1]},
                                 {'edges': ['key1', 'key2'],
                                  'key': 'key3',
                                  'name': 'key3',
                                  'value': []},
                                 {'edges': ['key1', 'key3'],
                                  'key': 'key2',
                                  'name': 'key2',
                                  'value': []}],
                   'points': [2815.73, 640.94, 3766.56, 1353.03],
                   'rotation': 0,
                   'title': 'class1',
                   'type': 'bbox',
                   'value': 'class1'},
                  {'attributes': [{'key': 'check',
                                   'name': 'check',
                                   'type': 'checkbox',
                                   'value': ['check1', 'check2']}],
                   'color': '#FF0000',
                   'confidenceScore': -1,
                   'id': 'fc7b50f4-4c98-4557-b909-a405a939e6b8',
                   'keypoints': [],
                   'points': [1494.45, 1830.5, 2799.27, 2814.26],
                   'rotation': 0,
                   'title': 'class2',
                   'type': 'bbox',
                   'value': 'class2'}],
  'createdAt': '2023-09-11T01:40:37.809Z',
  'height': 3200,
  'id': 'f33c6230-eac5-4813-8987-10e3eac44a1a',
  'name': '01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01562.JPG',
  'size': 1035249,
  'tags': ['cat', 'dog'],
  'updatedAt': '2023-09-11T01:40:37.809Z',
  'width': 4800},
 {'annotations': [],
  'createdAt': '2023-09-08T09:22:00.321Z',
  'height': 1434,
  'id': 'fa95d33f-c31c-4f19-9603-33dda1d44761',
  'name': '10206001384.jpg',
  'size': 209607,
  'tags': [],
  'updatedAt': '2023-09-08T09:22:00.321Z',
  'width': 2150}]

正常 - バージョン_なし

dataset_objects = client.get_dataset_objects(dataset="test3", version="2")
[]

正常 - タグ

dataset_objects = client.get_dataset_objects(dataset="test3", version="1", tags=["cat"])
[{'annotations': [{'attributes': [{'key': 'switch',
                                   'name': 'switch',
                                   'type': 'switch',
                                   'value': '1'},
                                  {'key': 'select',
                                   'name': 'select',
                                   'type': 'select',
                                   'value': 'select2'},
                                  {'key': 'text',
                                   'name': 'text',
                                   'type': 'text',
                                   'value': 'value'}],
                   'color': '#0033CC',
                   'confidenceScore': -1,
                   'id': '2fd68be5-0f88-4074-9ef6-b9c99209b332',
                   'keypoints': [{'edges': ['key1', 'key3'],
                                  'key': 'key2',
                                  'name': 'key2',
                                  'value': [1095.19, 1015.51, 1]},
                                 {'edges': ['key1', 'key2'],
                                  'key': 'key3',
                                  'name': 'key3',
                                  'value': [1317.46, 723.26, 1]},
                                 {'edges': ['key2', 'key3'],
                                  'key': 'key1',
                                  'name': 'key1',
                                  'value': [1074.6, 653.29, 1]}],
                   'points': [835.87, 476.29, 1461.52, 1398.31],
                   'rotation': 0,
                   'title': 'class1',
                   'type': 'bbox',
                   'value': 'class1'},
                  {'attributes': [{'key': 'select',
                                   'name': 'select',
                                   'type': 'select',
                                   'value': 'select2'},
                                  {'key': 'switch',
                                   'name': 'switch',
                                   'type': 'switch',
                                   'value': '0'}],
                   'color': '#0033CC',
                   'confidenceScore': -1,
                   'id': 'f897852a-7d87-4089-98e1-7ade28b24410',
                   'keypoints': [{'edges': ['key2', 'key3'],
                                  'key': 'key1',
                                  'name': 'key1',
                                  'value': [3219.11, 731.5, 1]},
                                 {'edges': ['key1', 'key2'],
                                  'key': 'key3',
                                  'name': 'key3',
                                  'value': []},
                                 {'edges': ['key1', 'key3'],
                                  'key': 'key2',
                                  'name': 'key2',
                                  'value': []}],
                   'points': [2815.73, 640.94, 3766.56, 1353.03],
                   'rotation': 0,
                   'title': 'class1',
                   'type': 'bbox',
                   'value': 'class1'},
                  {'attributes': [{'key': 'check',
                                   'name': 'check',
                                   'type': 'checkbox',
                                   'value': ['check1', 'check2']}],
                   'color': '#FF0000',
                   'confidenceScore': -1,
                   'id': 'fc7b50f4-4c98-4557-b909-a405a939e6b8',
                   'keypoints': [],
                   'points': [1494.45, 1830.5, 2799.27, 2814.26],
                   'rotation': 0,
                   'title': 'class2',
                   'type': 'bbox',
                   'value': 'class2'}],
  'createdAt': '2023-09-11T01:40:37.809Z',
  'height': 3200,
  'id': 'f33c6230-eac5-4813-8987-10e3eac44a1a',
  'name': '01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01562.JPG',
  'size': 1035249,
  'tags': ['cat', 'dog'],
  'updatedAt': '2023-09-11T01:40:37.809Z',
  'width': 4800}]

正常 - タグ_なし

dataset_objects = client.get_dataset_objects(
    dataset="test3", version="1", tags=["test"]
)
[]

Find

dataset_object = client.find_dataset_object(
    dataset_object_id="f33c6230-eac5-4813-8987-10e3eac44a1a"
)
{'annotations': [{'attributes': [{'key': 'switch',
                                  'name': 'switch',
                                  'type': 'switch',
                                  'value': '1'},
                                 {'key': 'select',
                                  'name': 'select',
                                  'type': 'select',
                                  'value': 'select2'},
                                 {'key': 'text',
                                  'name': 'text',
                                  'type': 'text',
                                  'value': 'value'}],
                  'color': '#0033CC',
                  'confidenceScore': -1,
                  'id': '2fd68be5-0f88-4074-9ef6-b9c99209b332',
                  'keypoints': [{'edges': ['key1', 'key3'],
                                 'key': 'key2',
                                 'name': 'key2',
                                 'value': [1095.19, 1015.51, 1]},
                                {'edges': ['key1', 'key2'],
                                 'key': 'key3',
                                 'name': 'key3',
                                 'value': [1317.46, 723.26, 1]},
                                {'edges': ['key2', 'key3'],
                                 'key': 'key1',
                                 'name': 'key1',
                                 'value': [1074.6, 653.29, 1]}],
                  'points': [835.87, 476.29, 1461.52, 1398.31],
                  'rotation': 0,
                  'title': 'class1',
                  'type': 'bbox',
                  'value': 'class1'},
                 {'attributes': [{'key': 'select',
                                  'name': 'select',
                                  'type': 'select',
                                  'value': 'select2'},
                                 {'key': 'switch',
                                  'name': 'switch',
                                  'type': 'switch',
                                  'value': '0'}],
                  'color': '#0033CC',
                  'confidenceScore': -1,
                  'id': 'f897852a-7d87-4089-98e1-7ade28b24410',
                  'keypoints': [{'edges': ['key2', 'key3'],
                                 'key': 'key1',
                                 'name': 'key1',
                                 'value': [3219.11, 731.5, 1]},
                                {'edges': ['key1', 'key2'],
                                 'key': 'key3',
                                 'name': 'key3',
                                 'value': []},
                                {'edges': ['key1', 'key3'],
                                 'key': 'key2',
                                 'name': 'key2',
                                 'value': []}],
                  'points': [2815.73, 640.94, 3766.56, 1353.03],
                  'rotation': 0,
                  'title': 'class1',
                  'type': 'bbox',
                  'value': 'class1'},
                 {'attributes': [{'key': 'check',
                                  'name': 'check',
                                  'type': 'checkbox',
                                  'value': ['check1', 'check2']}],
                  'color': '#FF0000',
                  'confidenceScore': -1,
                  'id': 'fc7b50f4-4c98-4557-b909-a405a939e6b8',
                  'keypoints': [],
                  'points': [1494.45, 1830.5, 2799.27, 2814.26],
                  'rotation': 0,
                  'title': 'class2',
                  'type': 'bbox',
                  'value': 'class2'}],
 'createdAt': '2023-09-11T01:40:37.809Z',
 'height': 3200,
 'id': 'f33c6230-eac5-4813-8987-10e3eac44a1a',
 'name': '01_寄りかかり_01_屋内_1F_2.5m_カメラB_モデルA_DSC01562.JPG',
 'size': 1035249,
 'tags': ['cat', 'dog'],
 'updatedAt': '2023-09-11T01:40:37.809Z',
 'width': 4800}

Delete

client.delete_dataset_object(dataset_object_id="f33c6230-eac5-4813-8987-10e3eac44a1a")

スクリーンショット 2023-09-11 12 22 07

スクリーンショット 2023-09-11 12 41 27

@Jiei-S Jiei-S self-assigned this Sep 6, 2023
@Jiei-S Jiei-S marked this pull request as ready for review September 11, 2023 03:51
@Jiei-S Jiei-S requested a review from ueno-k-work September 11, 2023 03:59
@ueno-k-work ueno-k-work merged commit 5e4ae0b into main Sep 12, 2023
@ueno-k-work ueno-k-work deleted the feature/dataset-objects-api branch September 12, 2023 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants