In this recipe, we will use raccoon_dataset, which contains 217 images of varying widths and height. This dataset is credited to Dat Tran and can be downloaded from his GitHub repository: https://github.com/datitran/raccoon_dataset.
We downloaded all of the images from the images folder of the aforementioned GitHub repository and copied them to the chapter8 - Deep learning for computer vision/data/raccoon_dataset/images path. We also downloaded the raccoon_labels.csv file from the data folder of the preceding GitHub repository and copied it to chapter8 - Deep learning for computer vision/data/raccoon_dataset. The raccoon_labels.csv file contains the coordinates of the bounding box encapsulating the raccoon in each image.
In this recipe, we will build a single object localization model; that is, we will only locate one area of interest in the entire image. Let's ensure that we have loaded all of the required libraries:
library(keras)
library(imager)
library(graphics)
Let's load the data and see how it looks:
labels <- read.csv('data/raccoon_dataset/raccoon_labels.csv')
# Displaying first 5 rows of data
head(labels)
The following screenshot shows a few records from the data:
Using the following code, we can plot one example image and draw a bounding box from the given coordinates:
# Load image
im <- load.image('data/raccoon_dataset/images/raccoon-1.jpg')
# Image information
im_info = labels[labels$filename == 'raccoon-1.jpg' ,]
print(im_info)
plot(im)
rect(xleft = im_info$xmin ,ybottom = im_info$ymin,xright = im_info$xmax,ytop = im_info$ymax,border = "red",lwd = 1)
The following screenshot is a sample from the input data:
The bounding box in the preceding screenshot shows the area of interest.