Easiest Object Detection in Pytorch with Faster-RCNN
3 min readMar 20, 2021
Today we will learning about how we can do object detection in pytorch in the most simplest manner as possible. We will be working with the x-ray dataset given in Kaggle website. Every code is being mentioned with comments on it.
#1# First we will do some import stuffs for the functions we will be using in this code.
#2# we will check whether cuda is available for our system or not, through this code
#3# Then we will adjust our dataset according requirements
#4# We will apply cross validation to split our dataset into training and validation set.
#5# Then we will be constructing the Pytorch custom dataset class for our object detection dataset
#6# Applying Image Transformations
#7# Creating object for the dataset class we created.
#8# Visualizing the image to be used for the training purpose
#9# Declaring the data loaders for our dataset to be used during the training and validation purpose
#10# Loading the pretrained Faster-RCNN model in pytorch
#11# Declaring the number of epochs, optimizer, scheduler… etc
#12# Defining the training function for our dataset
#13# defining the validation function
#14# Taking all the function in one function and initializing them step by step
#15# Finally we start training our model.
if __name__ == "__main__":
_run()
This is how we can use object detection model Faster RCNN on a dataset having bounding boxes for prediction using Pytorch framework. Let me know if you have any questions comments or concerns with regards to this . Until then ENJOY LEARNING.