Skip to content

Commit de7ffc2

Browse files
authored
Merge pull request #188 from fastlabel/get-training-jobs
feat get training jobs
2 parents e6dd4f3 + d884ebc commit de7ffc2

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,90 @@ for image_file_path in glob.iglob(os.path.join(input_dataset_path, "**/**.jpg"),
29642964

29652965
> Please check const.COLOR_PALLETE for index colors.
29662966
2967+
## Model
2968+
2969+
### Get training jobs
2970+
2971+
Get training jobs.
2972+
2973+
```python
2974+
def get_training_jobs() -> list[dict]:
2975+
all_training_jobs = []
2976+
offset = None
2977+
while True:
2978+
time.sleep(1)
2979+
2980+
training_jobs = client.get_training_jobs(offset=offset)
2981+
all_training_jobs.extend(training_jobs)
2982+
2983+
if len(training_jobs) > 0:
2984+
offset = len(all_training_jobs)
2985+
else:
2986+
break
2987+
return all_training_jobs
2988+
2989+
```
2990+
2991+
#### Response
2992+
2993+
Example of two training jobs.
2994+
2995+
```python
2996+
[
2997+
{
2998+
"trainingJobId": "f40c5838-4c3a-482f-96b7-f77e16c96fed",
2999+
"status": "in_progress",
3000+
"baseModelName": "FastLabel Object Detection High Accuracy - 汎用",
3001+
"instanceType": "ml.p3.2xlarge",
3002+
"epoch": 300,
3003+
"projects": [
3004+
"image-bbox"
3005+
],
3006+
"statuses": [],
3007+
"tags": [],
3008+
"contentCount": 23,
3009+
"userName": "Admin",
3010+
"createdAt": "2023-10-31T07:10:28.306Z",
3011+
"completedAt": null,
3012+
"customModel": {
3013+
"modelId": "",
3014+
"modelName": "",
3015+
"modelURL": "",
3016+
"classes": []
3017+
}
3018+
},
3019+
{
3020+
"trainingJobId": "1d2bc86a-c7f1-40a5-8e85-48246cc3c8d2",
3021+
"status": "completed",
3022+
"baseModelName": "custom-object-detection-image",
3023+
"instanceType": "ml.p3.2xlarge",
3024+
"epoch": 300,
3025+
"projects": [
3026+
"image-bbox"
3027+
],
3028+
"statuses": [
3029+
"approved"
3030+
],
3031+
"tags": [
3032+
"trainval"
3033+
],
3034+
"contentCount": 20,
3035+
"userName": "Admin",
3036+
"createdAt": "2023-10-31T06:56:28.112Z",
3037+
"completedAt": "2023-10-31T07:08:26.000Z",
3038+
"customModel": {
3039+
"modelId": "a6728876-2eb7-49b5-9fd8-7dee1b8a81b3",
3040+
"modelName": "fastlabel_object_detection-2023-10-31-07-08-29",
3041+
"modelURL": "URL for download model file",
3042+
"classes": [
3043+
"person"
3044+
]
3045+
}
3046+
}
3047+
]
3048+
```
3049+
3050+
29673051
## Execute endpoint
29683052

29693053
Create the endpoint from the screen at first.

fastlabel/__init__.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,8 @@ def create_video_task(
12581258
)
12591259
if not utils.is_video_supported_codec(file_path):
12601260
raise FastLabelInvalidException(
1261-
"Supported video encoding for registration through the SDK is only H.264.", 422
1261+
"Supported video encoding for registration through the SDK is only H.264.",
1262+
422,
12621263
)
12631264

12641265
file = utils.base64_encode(file_path)
@@ -1326,7 +1327,8 @@ def create_video_classification_task(
13261327
)
13271328
if not utils.is_video_supported_codec(file_path):
13281329
raise FastLabelInvalidException(
1329-
"Supported video encoding for registration through the SDK is only H.264.", 422
1330+
"Supported video encoding for registration through the SDK is only H.264.",
1331+
422,
13301332
)
13311333

13321334
file = utils.base64_encode(file_path)
@@ -4144,6 +4146,31 @@ def __get_signed_path(
41444146
params = {"project": project, "fileName": file_name, "fileType": file_type}
41454147
return self.api.get_request(endpoint, params)
41464148

4149+
def get_training_jobs(
4150+
self,
4151+
offset: int = None,
4152+
limit: int = 100,
4153+
) -> list:
4154+
"""
4155+
Returns a list of training jobs.
4156+
Returns up to 1000 at a time, to get more, set offset as the starting position
4157+
to fetch.
4158+
offset is the starting position number to fetch (Optional).
4159+
limit is the max number to fetch (Optional).
4160+
"""
4161+
if limit > 1000:
4162+
raise FastLabelInvalidException(
4163+
"Limit must be less than or equal to 1000.", 422
4164+
)
4165+
endpoint = "trainings"
4166+
params = {}
4167+
if offset:
4168+
params["offset"] = offset
4169+
if limit:
4170+
params["limit"] = limit
4171+
4172+
return self.api.get_request(endpoint, params=params)
4173+
41474174
def execute_endpoint(
41484175
self,
41494176
endpoint_name: str,

0 commit comments

Comments
 (0)