Image classification

Image classification1. Model introduction2. Start2.1. Enter docker2.2. Image classification: imageEffect preview2.3, Image classification: VideoEffect preview2.4, Image classification: real-time detectionEffect previewReferences

Use Python to demonstrate the effect of Ultralytics: Image classification on images, videos, and real-time detection.

1. Model introduction

Image classification is the simplest of the three tasks and involves classifying the entire image into one of a set of predefined categories.

The output of the image classifier is a single class label and a confidence score. Image classification is very useful when you only need to know which class the image belongs to, without knowing the location or exact shape of the object in that class.

2. Start

2.1. Enter docker

Run YOLOv11 docker script

2.2. Image classification: image

Use yolo11n-cls.pt to predict the images under the ultralytics project (not the images that come with ultralytics).

Enter the code folder:

Run the code:

Effect preview

Yolo recognition output image location: /ultralytics/ultralytics/output/

1. View using jupyter lab

Open another terminal to enter the docker container and use jupyter lab to view the image

image-20250324155841464

image-20250324155023395

Access directly through http://localhost:8080/ in the system browser:

image-20250324182003078

2. Copy the file to the host machine for viewing

Enter the following command in the host terminal

image-20241230201848908

Sample code:

2.3, Image classification: Video

Use yolo11n-cls.pt to predict videos under the ultralytics project (not the videos that come with ultralytics).

Enter the code folder:

Run the code:

Effect preview

Video location of yolo recognition output: /ultralytics/ultralytics/output/

The output video will be displayed in real time during the code running process. If you want to view the video later, you can refer to the above [2. Copy the file to the host machine for viewing] tutorial operation.

image-20241230203858580

Sample code:

2.4, Image classification: real-time detection

Use yolo11n-cls.pt to predict the USB camera screen.

Enter the code folder:

Run the code: Click the preview screen, press the q key to terminate the program!

Effect preview

Yolo recognizes the output video location: /ultralytics/ultralytics/output/

The camera screen will be displayed in real time during the code running. If you want to view the video later, you can refer to the above [2. Copy the file to the host machine for viewing] tutorial operation.

image-20241230204347046

Sample code:

References

https://docs.ultralytics.com/tasks/classify/