CVAT REST API用于上传文件。

huangapple go评论149阅读模式
英文:

CVAT REST API to upload files

问题

我能够使用下面的代码在CVAT的现有项目中创建一个任务,但无法上传文件,即使我尝试引用此链接:https://github.com/opencv/cvat/issues/4704

任何建议将不胜感激!

  1. import requests
  2. # 创建项目(这部分代码有效)
  3. link = 'http://xx.x.xxx.xx:8080/api/tasks'
  4. d = {
  5. "name": "ABC",
  6. "project_id": 3
  7. }
  8. Header = {
  9. "X-Organization": "ABC_labelling"
  10. }
  11. r = requests.post(link, data=d, headers=Header, auth=('username','pw'))
  12. r.json
  1. # 上传文件(这部分代码无效)
  2. task_id = 8
  3. link = 'http://xx.x.xxx.xx:8080/api/tasks/{task_id}/data/'
  4. files = [
  5. '/Users/username/Documents/images/abc001.tif',
  6. '/Users/username/Documents/images/abc002.tif'
  7. ]
  8. Header = {
  9. "X-Organization": "ABC_labelling",
  10. "Upload-Start": "true",
  11. "Upload-Finish": "true"
  12. }
  13. d = {
  14. "image-quality": 70,
  15. "server_files": files
  16. }
  17. r = requests.post(link, data=d, headers=Header, auth=('username','pw'))
英文:

I am able to create a Task in an existing project in CVAT using the below code, but I am unable to upload files, even if I try to reference this link here: https://github.com/opencv/cvat/issues/4704

Any advice would be greatly appreciated please!

  1. import requests
  2. # to create project (this works)
  3. link = 'http://xx.x.xxx.xx:8080/api/tasks'
  4. d = {
  5. "name": "ABC",
  6. "project_id": 3
  7. }
  8. Header = {
  9. "X-Organization":"ABC_labelling"
  10. }
  11. r = requests.post(link, data=d, headers=Header, auth=('username','pw'))
  12. r.json
  1. # to upload file (doesn't work)
  2. task_id = 8
  3. link = 'http://xx.x.xxx.xx:8080/api/tasks/{task_id}/data/'
  4. files = [
  5. '/Users/username/Documents/images/abc001.tif',
  6. '/Users/username/Documents/images/abc002.tif'
  7. ]
  8. Header = {
  9. "X-Organization":"ABC_labelling",
  10. "Upload-Start":"true",
  11. "Upload-Finish":"true"
  12. }
  13. d = {
  14. "image-quality": 70,
  15. "server_files": files
  16. }
  17. r = requests.post(link, data=d, headers=Header, auth=('username','pw'))

答案1

得分: 1

虽然对我来说有时候有些小问题,但Voxel51是实现这一目标的最简单方式。

  1. # 用于此运行的唯一标识符
  2. import fiftyone as fo
  3. # 仅需CVAT密码和用户名
  4. assert os.environ['FIFTYONE_CVAT_URL'], '设置FIFTYONE_CVAT_URL环境变量'
  5. assert os.environ['FIFTYONE_CVAT_PASSWORD'], '设置FIFTYONE_CVAT_PASSWORD环境变量'
  6. dataset = fo.Dataset.from_dir(
  7. dataset_dir=<coco-dir-path>,
  8. dataset_type=fo.types.COCODetectionDataset,
  9. )
  10. dataset.name = "example_task_name"
  11. anno_key = 'something_voxel51_uses'
  12. dataset.annotate(
  13. anno_key,
  14. label_field="ground_truth",
  15. attributes=["iscrowd"],
  16. launch_editor=True,
  17. classes=['car','truck','person'],
  18. )

https://docs.voxel51.com/api/fiftyone.core.collections.html#fiftyone.core.collections.SampleCollection.annotate

可能会遗漏一些细节,但CVAT Api 使用起来很痛苦,而Voxel51的设计要简单得多。

英文:

While it's sometimes a bit buggy for me. Voxel51 is by far the easiest way to achieve this.

  1. # A unique identifier for this run
  2. import fiftyone as fo
  3. #&#160;Just the CVAT password and username
  4. assert os.environ[&#39;FIFTYONE_CVAT_URL&#39;], &#39;Set FIFTYONE_CVAT_URL env var&#39;
  5. assert os.environ[&#39;FIFTYONE_CVAT_PASSWORD&#39;], &#39;Set FIFTYONE_CVAT_PASSWORD env var&#39;
  6. dataset = fo.Dataset.from_dir(
  7. dataset_dir=&lt;coco-dir-path&gt;,
  8. dataset_type=fo.types.COCODetectionDataset,
  9. )
  10. dataset.name = &quot;example_task_name&quot;
  11. anno_key = &#39;something_voxel51_uses&#39;
  12. dataset.annotate(
  13. anno_key,
  14. label_field=&quot;ground_truth&quot;,
  15. attributes=[&quot;iscrowd&quot;],
  16. launch_editor=True,
  17. classes=[&#39;car&#39;,&#39;truck&#39;,&#39;person&#39;],
  18. )

https://docs.voxel51.com/api/fiftyone.core.collections.html#fiftyone.core.collections.SampleCollection.annotate

I may be missing some detail but the CVAT Api is a pain to use, while the voxel51 design is much simpler.

huangapple
  • 本文由 发表于 2023年3月7日 23:07:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定