Skip to content

Commit 0d408b6

Browse files
Merge pull request #193 from fastlabel/add-dataset-training
add dataset training evaluation job
2 parents 0d44f1d + b231538 commit 0d408b6

File tree

2 files changed

+230
-0
lines changed

2 files changed

+230
-0
lines changed

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,14 @@ def get_training_jobs() -> list[dict]:
30113011

30123012
```
30133013

3014+
#### Find Training job
3015+
3016+
Find a single training job.
3017+
3018+
```python
3019+
task = client.find_training_job(id="YOUR_TRAINING_ID")
3020+
```
3021+
30143022
#### Response
30153023

30163024
Example of two training jobs.
@@ -3070,6 +3078,110 @@ Example of two training jobs.
30703078
]
30713079
```
30723080

3081+
### Execute training job
3082+
3083+
Get training jobs.
3084+
3085+
```python
3086+
training_job = client.execute_training_job(
3087+
dataset_name="dataset_name",
3088+
base_model_name="fastlabel_object_detection_light", // "fastlabel_object_detection_light" or "fastlabel_object_detection_high_accuracy"
3089+
epoch=300,
3090+
use_dataset_train_val=True
3091+
)
3092+
3093+
```
3094+
3095+
### Get evaluation jobs
3096+
3097+
Get evaluation jobs.
3098+
3099+
```python
3100+
def get_evaluation_jobs() -> list[dict]:
3101+
all_evaluation_jobs = []
3102+
offset = None
3103+
while True:
3104+
time.sleep(1)
3105+
3106+
evaluation_jobs = client.get_evaluation_jobs(offset=offset)
3107+
all_evaluation_jobs.extend(evaluation_jobs)
3108+
3109+
if len(evaluation_jobs) > 0:
3110+
offset = len(all_evaluation_jobs)
3111+
else:
3112+
break
3113+
return all_evaluation_jobs
3114+
3115+
```
3116+
3117+
#### Find Evaluation job
3118+
3119+
Find a single evaluation job.
3120+
3121+
```python
3122+
evaluation_job = client.find_evaluation_job(id="YOUR_EVALUATION_ID")
3123+
```
3124+
3125+
#### Response
3126+
3127+
Example of two evaluation jobs.
3128+
3129+
```python
3130+
3131+
{
3132+
id: "50873ea1-e008-48db-a368-241ca88d6f67",
3133+
version: 59,
3134+
status: "in_progress",
3135+
modelType: "builtin",
3136+
modelName: "FastLabel Object Detection Light - 汎用",
3137+
customModelId: None,
3138+
iouThreshold: 0.8,
3139+
confidenceThreshold: 0.4,
3140+
contentCount: 0,
3141+
gtCount: 0,
3142+
predCount: 0,
3143+
mAP: 0,
3144+
recall: 0,
3145+
precision: 0,
3146+
f1: 0,
3147+
confusionMatrix: None,
3148+
duration: 0,
3149+
evaluationSource: "dataset",
3150+
projects: [],
3151+
statuses: [],
3152+
tags: [],
3153+
datasetId: "deacbe6d-406f-4086-bd87-80ffb1c1a393",
3154+
dataset: {
3155+
id: "deacbe6d-406f-4086-bd87-80ffb1c1a393",
3156+
workspaceId: "df201d3c-af00-423a-aa7f-827376fd96de",
3157+
name: "sample-dataset",
3158+
createdAt: "2023-12-20T10:44:12.198Z",
3159+
updatedAt: "2023-12-20T10:44:12.198Z",
3160+
},
3161+
datasetRevisionId: "2d26ab64-dfc0-482d-9211-ce8feb3d480b",
3162+
useDatasetTest: True,
3163+
userName: "",
3164+
completedAt: None,
3165+
createdAt: "2023-12-21T09:08:16.111Z",
3166+
updatedAt: "2023-12-21T09:08:18.414Z",
3167+
};
3168+
3169+
```
3170+
3171+
### Execute evaluation job
3172+
3173+
Execute evaluation jobs.
3174+
3175+
```python
3176+
training_job = client.execute_evaluation_job(
3177+
dataset_name="DATASET_NAME",
3178+
model_name="fastlabel_object_detection_light",
3179+
// If you want to use the built-in model, select the following. "fastlabel_object_detection_light" or "fastlabel_object_detection_high_accuracy"
3180+
// If you want to use the custom model, please fill out model name.
3181+
use_dataset_test=True,
3182+
)
3183+
3184+
```
30733185

30743186
### Execute endpoint
30753187

fastlabel/__init__.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,6 +4231,124 @@ def get_training_jobs(
42314231

42324232
return self.api.get_request(endpoint, params=params)
42334233

4234+
def execute_training_job(
4235+
self,
4236+
dataset_name: str,
4237+
base_model_name: str,
4238+
epoch: int,
4239+
dataset_revision_id: str = None,
4240+
use_dataset_train_val: bool = False,
4241+
instance_type: str = "ml.p3.2xlarge",
4242+
batch_size: int = None,
4243+
learning_rate: float = None,
4244+
) -> list:
4245+
"""
4246+
Returns a list of training jobs.
4247+
Returns up to 1000 at a time, to get more, set offset as the starting position
4248+
to fetch.
4249+
offset is the starting position number to fetch (Optional).
4250+
limit is the max number to fetch (Optional).
4251+
"""
4252+
endpoint = "trainings"
4253+
payload = {
4254+
"datasetName": dataset_name,
4255+
"baseModelName": base_model_name,
4256+
"epoch": epoch,
4257+
"useDatasetTrainVal": use_dataset_train_val,
4258+
"datasetRevisionId": dataset_revision_id,
4259+
"instanceType": instance_type,
4260+
"batchSize": batch_size,
4261+
"learningRate": learning_rate,
4262+
}
4263+
4264+
return self.api.post_request(
4265+
endpoint,
4266+
payload={key: value for key, value in payload.items() if value is not None},
4267+
)
4268+
4269+
def find_training_job(self, id: str) -> list:
4270+
"""
4271+
Returns training job.
4272+
id is id of training job (Required).
4273+
"""
4274+
4275+
endpoint = f"trainings/{id}"
4276+
4277+
return self.api.get_request(
4278+
endpoint,
4279+
)
4280+
4281+
def get_evaluation_jobs(
4282+
self,
4283+
offset: int = None,
4284+
limit: int = 1000,
4285+
) -> list:
4286+
"""
4287+
Returns a list of training jobs.
4288+
Returns up to 1000 at a time, to get more, set offset as the starting position
4289+
to fetch.
4290+
offset is the starting position number to fetch (Optional).
4291+
limit is the max number to fetch (Optional).
4292+
"""
4293+
if limit > 1000:
4294+
raise FastLabelInvalidException(
4295+
"Limit must be less than or equal to 1000.", 422
4296+
)
4297+
endpoint = "evaluations"
4298+
params = {}
4299+
if offset:
4300+
params["offset"] = offset
4301+
if limit:
4302+
params["limit"] = limit
4303+
4304+
return self.api.get_request(endpoint, params=params)
4305+
4306+
def find_evaluation_job(self, id: str) -> list:
4307+
"""
4308+
Returns evaluation job.
4309+
id is id of evaluation job (Required).
4310+
"""
4311+
4312+
endpoint = f"evaluations/{id}"
4313+
4314+
return self.api.get_request(
4315+
endpoint,
4316+
)
4317+
4318+
def execute_evaluation_job(
4319+
self,
4320+
dataset_name: str,
4321+
model_name: str,
4322+
iou_threshold: float = 0.5,
4323+
confidence_threshold: float = 0.4,
4324+
dataset_revision_id: str = None,
4325+
use_dataset_test: bool = False,
4326+
instance_type: str = "ml.p3.2xlarge",
4327+
batch_size: int = None,
4328+
learning_rate: float = None,
4329+
) -> list:
4330+
"""
4331+
Returns a list of training jobs.
4332+
Returns up to 1000 at a time, to get more, set offset as the starting position
4333+
to fetch.
4334+
offset is the starting position number to fetch (Optional).
4335+
limit is the max number to fetch (Optional).
4336+
"""
4337+
endpoint = "evaluations"
4338+
payload = {
4339+
"modelName": model_name,
4340+
"datasetName": dataset_name,
4341+
"iouThreshold": iou_threshold,
4342+
"confidenceThreshold": confidence_threshold,
4343+
"datasetRevisionId": dataset_revision_id,
4344+
"useDatasetTest": use_dataset_test,
4345+
}
4346+
4347+
return self.api.post_request(
4348+
endpoint,
4349+
payload={key: value for key, value in payload.items() if value is not None},
4350+
)
4351+
42344352
def execute_endpoint(
42354353
self,
42364354
endpoint_name: str,

0 commit comments

Comments
 (0)