I am training a YOLO Nas s object detection model for a retail store,using 8000 images.
I have alrerady trained this model for 1500 images for 50 epochs. I have generated the checkpoint file, now how should I train this already trained model on another set of 2000 images.
Also how can I check the accuracy of my trained model using the generated checkpoint file(.pth)
I am holding on further training for now. To check the accuracy I tried generating bounding boxes on real time shelf images.
But I am expecting how can we check accuracy rate in number using the best_checkpoint.pth file
from super_gradients.training.dataloaders.dataloaders import coco_detection_yolo_format_train, coco_detection_yolo_format_val
BATCH_SIZE = 1
CLASSES = ['product']
CLASSES += [str(i) for i in range(80 - len(CLASSES))]
dataset_params = {
'data_dir': r"C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixed",
'train_images_dir':r'C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixedimagestrain',
'train_labels_dir':r'C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixedlabelstrain',
'val_images_dir':r'C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixedimagesval',
'val_labels_dir':r'C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixedlabelsval',
'test_images_dir':r'C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixedimagestest',
'test_labels_dir':r'C:UsersGirirajDocumentsPrernas ML ModelsSKU110KDatasetSKU110K_fixedlabelstest',
'classes': CLASSES
}
train_data = coco_detection_yolo_format_train(
dataset_params={
'data_dir': dataset_params['data_dir'],
'images_dir': dataset_params['train_images_dir'],
'labels_dir': dataset_params['train_labels_dir'],
'classes': dataset_params['classes']
},
dataloader_params={
'batch_size': BATCH_SIZE,
'num_workers': 2
}
)
val_data = coco_detection_yolo_format_val(
dataset_params={
'data_dir': dataset_params['data_dir'],
'images_dir': dataset_params['val_images_dir'],
'labels_dir': dataset_params['val_labels_dir'],
'classes': dataset_params['classes']
},
dataloader_params={
'batch_size': BATCH_SIZE,
'num_workers': 2
}
)
test_data = coco_detection_yolo_format_val(
dataset_params={
'data_dir': dataset_params['data_dir'],
'images_dir': dataset_params['test_images_dir'],
'labels_dir': dataset_params['test_labels_dir'],
'classes': dataset_params['classes']
},
dataloader_params={
'batch_size': BATCH_SIZE,
'num_workers': 2
}
)
import torch from super_gradients.training import models from super_gradients.training import Trainer
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu' model = models.get('yolo_nas_s', pretrained_weights="coco").to(DEVICE) trainer = Trainer(experiment_name="SKU110K", ckpt_root_dir="./weights")
from super_gradients.training.losses import PPYoloELoss from super_gradients.training.metrics import DetectionMetrics_050 from super_gradients.training.models.detection_models.pp_yolo_e import PPYoloEPostPredictionCallback
MAX_EPOCHS = 20
train_params = {
'silent_mode': False,
"average_best_models":True,
"warmup_mode": "linear_epoch_step",
"warmup_initial_lr": 1e-6,
"lr_warmup_epochs": 3,
"initial_lr": 5e-4,
"lr_mode": "cosine",
"cosine_final_lr_ratio": 0.1,
"optimizer": "Adam",
"optimizer_params": {"weight_decay": 0.0001},
"zero_weight_decay_on_bias_and_bn": True,
"ema": True,
"resume":True,
"ema_params": {"decay": 0.9, "decay_type": "threshold"},
"max_epochs": MAX_EPOCHS,
"mixed_precision": True,
"loss": PPYoloELoss(
use_static_assigner=False,
num_classes=len(dataset_params['classes']),
reg_max=16
),
"valid_metrics_list": [
DetectionMetrics_050(
score_thres=0.1,
top_k_predictions=50,
num_cls=len(dataset_params['classes']),
normalize_targets=True,
post_prediction_callback=PPYoloEPostPredictionCallback(
score_threshold=0.01,
nms_top_k=100,
max_predictions=20,
nms_threshold=0.7
)
)
],
"metric_to_watch": '[email protected]'
}
for epoch in range(START_EPOCH, train_params['max_epochs']):
trainer.train(model=model, training_params=train_params, train_loader=train_data, valid_loader=val_data)
# Save checkpoint after each epoch
torch.save({
'epoch': epoch,
'model_state_dict': model.state_dict(),
'optimizer_state_dict': optimizer.state_dict(),
# Add any other relevant information
}, r'C:UsersGirirajsourcereposnew trainingcheckpointJun21.pth')
prerna singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.