在Roboflow中,要开始操作项目对象,首先需要导入Roboflow库并使用API密钥初始化一个Roboflow对象。以下是初始化步骤的代码示例:
import roboflow
rf = roboflow.Roboflow(api_key="YOUR_API_KEY_HERE")
完成初始化后,可以列出工作空间中的所有项目,或者获取特定项目的信息。以下是如何列出项目和获取项目信息的代码示例:
workspace = rf.workspace()
project = workspace.project("PROJECT_ID")
此外,还可以列出特定项目的各个版本,这有助于了解项目的迭代情况。以下是如何列出项目版本的代码示例:
project.versions()
通过REST API获取项目信息
除了在Python中操作外,还可以通过REST API获取项目的信息。以下是一个使用curl命令获取项目信息的示例:
curl "https://api.roboflow.com/roboflow/chess-sample-4ckfl?api_key=$ROBOFLOW_API_KEY"
这个API端点会返回一个JSON格式的响应,其中包含了工作空间和项目的各种详细信息。例如,项目ID、类型、名称、创建和更新时间、图片数量、未标注图片数量、标注信息、公开状态、数据集划分、类别统计以及版本信息等。
项目信息的JSON响应结构
当通过REST API请求项目信息时,返回的JSON响应结构可能如下所示。这个结构包含了工作空间和项目相关的详细信息,例如工作空间名称、URL、成员数量、项目ID、类型、名称、创建和更新时间、图片数量、未标注图片数量、标注信息、公开状态、数据集划分、类别统计以及版本信息等。
{
"workspace": {
"name": "Roboflow",
"url": "roboflow",
"members": 7
},
"project": {
"id": "roboflow/chess-sample-4ckfl",
"type": "object-detection",
"name": "Chess Sample",
"created": 1630335544.592,
"updated": 1630335741.988,
"images": 12,
"unannotated": 3,
"annotation": "pieces",
"public": false,
"splits": {
"valid": 2,
"train": 9,
"test": 1
},
"classes": {
"white-queen": 7,
"white-king": 8,
"black-knight": 11,
"black-pawn": 37,
"black-rook": 10,
"white-pawn": 34,
"black-bishop": 8,
"white-knight": 10,
"black-queen": 4,
"white-bishop": 11,
"black-king": 8,
"white-rook": 10
},
"versions": [
{
"id": "roboflow/chess-sample-4ckfl/3",
"name": "raw",
"created": 1630335741.989,
"images": 12,
"splits": {
"train": 9,
"test": 1,
"valid": 2
},
"preprocessing": {
"auto-orient": {
"enabled": true
}
},
"augmentation": {},
"exports": [
"coco",
"voc"
]
},
{
"id": "roboflow/chess-sample-4ckfl/2",
"name": "416x416",
"created": 1630335730.142,
"images": 12,
"splits": {
"train": 9,
"test": 1,
"valid": 2
},
"preprocessing": {
"resize": {
"enabled": true,
"format": "Stretch to",
"width": 416,
"height": 416
},
"auto-orient": {
"enabled": true
}
},
"augmentation": {},
"exports": []
},
{
"id": "roboflow/chess-sample-4ckfl/1",
"name": "augmented",
"created": 1630335698.746,
"images": 30,
"splits": {
"valid": 2,
"train": 27,
"test": 1
},
"model": {
"id": "chess-sample-4ckfl/1",
"endpoint": "https://detect.staging.roboflow.com/chess-sample-4ckfl/1",
"start": 1630335799.682,
"end": 1630337523.889,
"fromScratch": false,
"tfjs": true,
"oak": true,
"map": "62.87",
"recall": "85.29",
"precision": "23.44"
},
"preprocessing": {
"resize": {
"enabled": true,
"width": 416,
"format": "Stretch to",
"height": 416
},
"auto-orient": {
"enabled": true
},
"grayscale": {
"enabled": true
}
},
"augmentation": {
"exposure": {
"percent": "25",
"enabled": true
},
"brightness": {
"percent": "25",
"enabled": true,
"darken": true,
"brighten": true
},
"rotate": {
"degrees": "5",
"enabled": true
},
"image": {
"enabled": true,
"versions": "3"
},
"flip": {
"enabled": true,
"horizontal": true,
"vertical": false
},
"crop": {
"min": 0,
"percent": 30,
"enabled": true
},
"noise": {
"percent": "2",
"enabled": true
}
},
"exports": [
"yolov5pytorch"
]
}
]
}
}
在命令行界面(CLI)获取项目信息
如果更喜欢使用命令行界面(CLI),Roboflow也提供了相应的命令来获取项目信息。以下是使用CLI获取项目信息的命令示例:
roboflow project get *project ID*