The class function will help us grab classes from the classes text file. We can find the coco_classes.txt file in the data folder in the project, in the section, Importing YOLO.
The COCO dataset contains almost 80 classes. It can detect them as follows:
def get_classes(file):
"""Get classes name.
# Argument:
file: classes name for database.
# Returns
class_names: List, classes name.
"""
with open(file) as f:
name_of_class = f.readlines()
name_of_class_names = [c.strip() for c in name_of_class]
return name_of_class
In the next section, we will write code for the box function, which is useful for drawing boxes around the objects in images.