Skip to content

Commit 539e807

Browse files
authored
Merge pull request #77 from fastlabel/develop
Merge to main
2 parents 598325f + b1a2814 commit 539e807

File tree

5 files changed

+777
-8
lines changed

5 files changed

+777
-8
lines changed

README.md

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ _If you are using FastLabel prototype, please install version 0.2.2._
2222
- [Pascal VOC](#pascal-voc)
2323
- [labelme](#labelme)
2424
- [Segmentation](#segmentation)
25+
- [Converter to FastLabel format](#converter-to-fastlabel-format)
2526

2627
## Installation
2728

@@ -942,6 +943,303 @@ tasks = client.get_image_tasks(project="YOUR_PROJECT_SLUG")
942943
client.export_semantic_segmentation(tasks)
943944
```
944945

946+
## Converter to FastLabel format
947+
948+
### Response
949+
950+
Example of a converted annotations
951+
952+
```python
953+
{
954+
'sample1.jpg': [
955+
{
956+
'points': [
957+
100,
958+
100,
959+
200,
960+
200
961+
],
962+
'type': 'bbox',
963+
'value': 'cat'
964+
}
965+
],
966+
'sample2.jpg': [
967+
{
968+
'points': [
969+
100,
970+
100,
971+
200,
972+
200
973+
],
974+
'type': 'bbox',
975+
'value': 'cat'
976+
}
977+
]
978+
}
979+
```
980+
981+
In the case of YOLO, Pascal VOC, and labelme, the key is the tree structure if the tree structure is multi-level.
982+
983+
```
984+
dataset
985+
├── sample1.jpg
986+
├── sample1.txt
987+
└── sample_dir
988+
├── sample2.jpg
989+
└── sample2.txt
990+
```
991+
992+
```python
993+
{
994+
'sample1.jpg': [
995+
{
996+
'points': [
997+
100,
998+
100,
999+
200,
1000+
200
1001+
],
1002+
'type': 'bbox',
1003+
'value': 'cat'
1004+
}
1005+
],
1006+
'sample_dir/sample2.jpg': [
1007+
{
1008+
'points': [
1009+
100,
1010+
100,
1011+
200,
1012+
200
1013+
],
1014+
'type': 'bbox',
1015+
'value': 'cat'
1016+
}
1017+
]
1018+
}
1019+
```
1020+
1021+
### COCO
1022+
1023+
Supported bbox or polygon annotation type.
1024+
1025+
Convert annotation file of [COCO format](https://cocodataset.org/#format-data) as a Fastlabel format and create task.
1026+
1027+
file_path: COCO annotation json file path
1028+
1029+
```python
1030+
annotations_map = client.convert_coco_to_fastlabel(file_path="./sample.json")
1031+
task_id = client.create_image_task(
1032+
project="YOUR_PROJECT_SLUG",
1033+
name="sample.jpg",
1034+
file_path="./sample.jpg",
1035+
annotations=annotations_map.get("sample.jpg")
1036+
)
1037+
```
1038+
1039+
Example of converting annotations to create multiple tasks.
1040+
1041+
In the case of the following tree structure.
1042+
1043+
```
1044+
dataset
1045+
├── annotation.json
1046+
├── sample1.jpg
1047+
└── sample2.jpg
1048+
```
1049+
1050+
Example source code.
1051+
1052+
```python
1053+
import fastlabel
1054+
1055+
project = "YOUR_PROJECT_SLUG"
1056+
input_file_path = "./dataset/annotation.json"
1057+
input_dataset_path = "./dataset/"
1058+
1059+
annotations_map = client.convert_coco_to_fastlabel(file_path=input_file_path)
1060+
for image_file_path in glob.iglob(os.path.join(input_dataset_path, "**/**.jpg"), recursive=True):
1061+
time.sleep(1)
1062+
name = image_file_path.replace(os.path.join(*[input_dataset_path, ""]), "")
1063+
file_path = image_file_path
1064+
annotations = annotations_map.get(name) if annotations_map.get(name) is not None else []
1065+
task_id = client.create_image_task(
1066+
project=project,
1067+
name=name,
1068+
file_path=file_path,
1069+
annotations=annotations
1070+
)
1071+
```
1072+
1073+
### YOLO
1074+
1075+
Supported bbox annotation type.
1076+
1077+
Convert annotation file of YOLO format as a Fastlabel format and create task.
1078+
1079+
classes_file_path: YOLO classes text file path
1080+
dataset_folder_path: Folder path containing YOLO Images and annotation
1081+
1082+
```python
1083+
annotations_map = client.convert_yolo_to_fastlabel(
1084+
classes_file_path="./classes.txt",
1085+
dataset_folder_path="./dataset/"
1086+
)
1087+
task_id = client.create_image_task(
1088+
project="YOUR_PROJECT_SLUG",
1089+
name="sample.jpg",
1090+
file_path="./dataset/sample.jpg",
1091+
annotations=annotations_map.get("sample.jpg")
1092+
)
1093+
```
1094+
1095+
Example of converting annotations to create multiple tasks.
1096+
1097+
In the case of the following tree structure.
1098+
1099+
```
1100+
yolo
1101+
├── classes.txt
1102+
└── dataset
1103+
├── sample1.jpg
1104+
├── sample1.txt
1105+
├── sample2.jpg
1106+
└── sample2.txt
1107+
```
1108+
1109+
Example source code.
1110+
1111+
```python
1112+
import fastlabel
1113+
1114+
project = "YOUR_PROJECT_SLUG"
1115+
input_file_path = "./classes.txt"
1116+
input_dataset_path = "./dataset/"
1117+
annotations_map = client.convert_yolo_to_fastlabel(
1118+
classes_file_path=input_file_path,
1119+
dataset_folder_path=input_dataset_path
1120+
)
1121+
for image_file_path in glob.iglob(os.path.join(input_dataset_path, "**/**.jpg"), recursive=True):
1122+
time.sleep(1)
1123+
name = image_file_path.replace(os.path.join(*[input_dataset_path, ""]), "")
1124+
file_path = image_file_path
1125+
annotations = annotations_map.get(name) if annotations_map.get(name) is not None else []
1126+
task_id = client.create_image_task(
1127+
project=project,
1128+
name=name,
1129+
file_path=file_path,
1130+
annotations=annotations
1131+
)
1132+
```
1133+
1134+
### Pascal VOC
1135+
1136+
Supported bbox annotation type.
1137+
1138+
Convert annotation file of Pascal VOC format as a Fastlabel format and create task.
1139+
1140+
folder_path: Folder path including pascal VOC format annotation files
1141+
1142+
```python
1143+
annotations_map = client.convert_pascalvoc_to_fastlabel(folder_path="./dataset/")
1144+
task_id = client.create_image_task(
1145+
project="YOUR_PROJECT_SLUG",
1146+
name="sample.jpg",
1147+
file_path="./dataset/sample.jpg",
1148+
annotations=annotations_map.get("sample.jpg")
1149+
)
1150+
```
1151+
1152+
Example of converting annotations to create multiple tasks.
1153+
1154+
In the case of the following tree structure.
1155+
1156+
```
1157+
dataset
1158+
├── sample1.jpg
1159+
├── sample1.xml
1160+
├── sample2.jpg
1161+
└── sample2.xml
1162+
```
1163+
1164+
Example source code.
1165+
1166+
```python
1167+
import fastlabel
1168+
1169+
project = "YOUR_PROJECT_SLUG"
1170+
input_dataset_path = "./dataset/"
1171+
1172+
annotations_map = client.convert_pascalvoc_to_fastlabel(folder_path=input_dataset_path)
1173+
for image_file_path in glob.iglob(os.path.join(input_dataset_path, "**/**.jpg"), recursive=True):
1174+
time.sleep(1)
1175+
name = image_file_path.replace(os.path.join(*[input_dataset_path, ""]), "")
1176+
file_path = image_file_path
1177+
annotations = annotations_map.get(name) if annotations_map.get(name) is not None else []
1178+
task_id = client.create_image_task(
1179+
project=project,
1180+
name=name,
1181+
file_path=file_path,
1182+
annotations=annotations
1183+
)
1184+
```
1185+
1186+
### labelme
1187+
1188+
support the following annotation types.
1189+
1190+
- bbox
1191+
- polygon
1192+
- points
1193+
- line
1194+
1195+
Convert annotation file of labelme format as a Fastlabel format and create task.
1196+
1197+
folder_path: Folder path including labelme format annotation files
1198+
1199+
```python
1200+
annotations_map = client.convert_labelme_to_fastlabel(folder_path="./dataset/")
1201+
task_id = client.create_image_task(
1202+
project="YOUR_PROJECT_SLUG",
1203+
name="sample.jpg",
1204+
file_path="./sample.jpg",
1205+
annotations=annotations_map.get("sample.jpg")
1206+
)
1207+
```
1208+
1209+
Example of converting annotations to create multiple tasks.
1210+
1211+
In the case of the following tree structure.
1212+
1213+
```
1214+
dataset
1215+
├── sample1.jpg
1216+
├── sample1.json
1217+
├── sample2.jpg
1218+
└── sample2.json
1219+
```
1220+
1221+
Example source code.
1222+
1223+
```python
1224+
import fastlabel
1225+
1226+
project = "YOUR_PROJECT_SLUG"
1227+
input_dataset_path = "./dataset/"
1228+
1229+
annotations_map = client.convert_labelme_to_fastlabel(folder_path=input_dataset_path)
1230+
for image_file_path in glob.iglob(os.path.join(input_dataset_path, "**/**.jpg"), recursive=True):
1231+
time.sleep(1)
1232+
name = image_file_path.replace(os.path.join(*[input_dataset_path, ""]), "")
1233+
file_path = image_file_path
1234+
annotations = annotations_map.get(name) if annotations_map.get(name) is not None else []
1235+
task_id = client.create_image_task(
1236+
project=project,
1237+
name=name,
1238+
file_path=file_path,
1239+
annotations=annotations
1240+
)
1241+
```
1242+
9451243
> Please check const.COLOR_PALLETE for index colors.
9461244
9471245
## API Docs

0 commit comments

Comments
 (0)