Преглед изворни кода

[feat] label-studio 数据处理

WangChao пре 2 месеци
родитељ
комит
fffbc0e2cc
2 измењених фајлова са 78 додато и 0 уклоњено
  1. 26 0
      data_collection/CopyImage.py
  2. 52 0
      data_collection/ExportLabel.py

+ 26 - 0
data_collection/CopyImage.py

@@ -0,0 +1,26 @@
+from pathlib import Path
+import requests
+
+imageUrl = "http://192.168.10.18:10088/Table_Figure_V1.3_20230208/train2017/"
+destPath = "./project-22-at-2024-09-04-06-33-61be369e"
+
+def download_file(url, local_filename):
+    # 发送带有流式响应的 GET 请求
+    with requests.get(url, stream=True) as r:
+        # 检查请求结果是否成功
+        if r.status_code == 200:
+            # 打开本地文件以便写入
+            with open(local_filename, 'wb') as f:
+                for chunk in r.iter_content(chunk_size=8192):
+                    # 写入文件块
+                    f.write(chunk)
+        else:
+            print(f"Failed to download file: {r.status_code}")
+
+labels_path = Path(destPath+'/labels')
+for file in labels_path.iterdir():
+    if file.is_file():
+        imageName = file.name.replace('.txt', '.jpg')
+        download_file(imageUrl+imageName, destPath+'/images/'+imageName)
+
+print('下载完成')

+ 52 - 0
data_collection/ExportLabel.py

@@ -0,0 +1,52 @@
+from label_studio_sdk import Client
+from label_studio_sdk.data_manager import Filters, Column, Operator, Type
+
+LABEL_STUDIO_URL = "http://192.168.10.18:8081"  # 或者是你的Label Studio的URL
+API_KEY = "b614d8c956495f52ea3f3f598c0be3f11866d9a0"  # 从Label Studio获得你的API密钥
+
+#LABEL_STUDIO_URL = "http://localhost:8080"  # 或者是你的Label Studio的URL
+#API_KEY = "87ae9ca430852c3b9753bacf214b7f90bedf5bdd"  # 从Label Studio获得你的API密钥
+
+# 初始化 Label Studio 客户端
+ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY)
+
+projects = ls.get_projects()
+for project in projects:
+    print(f"Project ID: {project.id}, Project Title: {project.title}")
+
+# Project ID: 22, Project Title: LA_Table_Figure_V1.3_20230208
+# Project ID: 16, Project Title: LA_KR_1.0.0
+# Project ID: 14, Project Title: LA_VAL_1.0.0
+# Project ID: 12, Project Title: Demo1
+# Project ID: 10, Project Title: LA_0.1.0
+# Project ID: 4, Project Title: Test Project #1  
+
+PROJECT_ID = 22                  # 项目 ID
+
+# 获取项目
+project = ls.get_project(PROJECT_ID)
+
+filters = Filters.create(Filters.AND, [
+    Filters.item(
+        Column.inner_id,
+        Operator.GREATER_OR_EQUAL,
+        Type.Number,
+        Filters.value(1)
+    ),
+    Filters.item(
+        Column.inner_id,
+        Operator.LESS_OR_EQUAL,
+        Type.Number,
+        Filters.value(3000)
+    )
+])
+
+export_result = project.export(filters=filters, export_type='YOLO')
+
+# 导出数据
+# export_result = project.export_tasks(export_type = "YOLO",
+#                                     download_all_tasks = False,
+#                                     download_resources = True,
+#                                     export_location = 'C:/test/yolo_export.zip')
+
+print('导出完成')