In this Notebook, I have processed the images with RoboFlow because in COCO formatted dataset was having different dimensions of image and Also data set was not splitted into different Format.
To train a custom YOLOv7 model we need to recognize the objects in the dataset. To do so I have taken the following steps:
Export the dataset to YOLOv7
Train YOLOv7 to recognize the objects in our dataset
Evaluate our YOLOv7 model's performance
Run test inference to view performance of YOLOv7 model at work
1try:2 user_secrets = UserSecretsClient()3 wandb_api_key = user_secrets.get_secret("wandb_api")4 wandb.login(key=wandb_api_key)5 anonymous =None6except:7 wandb.login(anonymous='must')8print('To use your W&B account,\nGo to Add-ons -> Secrets and provide your W&B access token. Use the Label name as WANDB. \nGet your W&B access token from here: https://wandb.ai/authorize')9101112wandb.init(project="YOLOv7",name=f"7. YOLOv7-Car-Person-Custom-Run-7")
Step 2: Assemble Our Dataset
In order to train our custom model, we need to assemble a dataset of representative images with bounding box annotations around the objects that we want to detect. And we need our dataset to be in YOLOv7 format.
epochs: define the number of training epochs. (Note: often, 3000+ are common here nut since I am using free version of colab I will be only defining it to 20!)
data: Our dataset locaiton is saved in the ./yolov7/Custom-Yolov7-on-Kaggle-on-Custom-Dataset-2 folder.
weights: specifying a path to weights to start transfer learning from. Here I have choosen a generic COCO pretrained checkpoint.
Testing inference with a pretrained checkpoint on contents of ./Custom-Yolov7-on-Kaggle-on-Custom-Dataset-2/test/images folder downloaded from Roboflow.
1for images in glob.glob('runs/detect/exp/*.jpg')[0:10]:2 display(Image(filename=images))
model = torch.load('runs/train/exp/weights/best.pt')
Conclusion and Next Steps
Now this trained custom YOLOv7 model can be used to recognize Person and Cars form any given Images.
To improve the model's performance, I might perform more interating on the datasets coverage,propper annotations and and Image quality. From orignal authors of Yolov7 this guide has been given for model performance improvement.