Material of Gifu AI Study Group (1st meeting) 2025/3/23

1. Overview

This page is prepared for reference at the Gifu AI Study Group (1st meeting) scheduled to be held on March 23, 2025 (Sunday).

2. Running the prediction process of the object detection model YOLO using Google Colab
2.1. Create a Google Account

Create a Google Account to use Google Colab and Google Drive.
Sign in to Chrome with the Google Account you created.

2.2. Perform YOLO prediction process with Google Colab

Open this link.

This is a page for Google Colab prepared for Gifu AI Study Group (1st meeting).

First, click the arrow in the upper left corner of the code cell below.
The Python package ultralytics and related packages will be installed, and then the ultralytics check program will be run.

%pip install ultralytics
import ultralytics
ultralytics.checks()

Click the arrow in the upper left corner of the code cell containing the script below. Object recognition is performed using YOLO11n. If the URL of the image specified in source is changed to another image, object recognition will be performed on the other image.

# Run inference on an image with YOLO11n
!yolo predict model=yolo11n.pt source='https://www.leafwindow.com/wordpress-05/wp-content/uploads/2023/12/IMG_6460-20.jpg'

The resulting image file from object recognition can be viewed by clicking on the folder icon to the left of Google Colab. The image below will be shown by double-clicking on the resulting output image.

In addition to object recognition using YOLO11n, a code cell for object recognition using YOLO11x, which has a larger network size than YOLO11n, is also available on the above page. I have also prepared a code cell for human posture estimation using YOLO11n-pose.

3. Execution of YOLO process with reference to Google Drive data
3.1. Referencing Google Drive data from Goole Colab

Click the arrow in the upper left corner of the code cell containing the script below. You will be able to browse files placed on Google Drive.

from google.colab import drive
drive.mount('/content/drive')

A pop-up will appear as shown in the first image, select “Connect to Google Drive”.
On the second screen, select which Google Drive account to connect to.
Click “Next” on the third screen.
On the fourth screen, click the “Select All” checkbox, then click “Continue” (fourth and fifth images).
The mounted drive folder appears on the left side of Google Colab as shown in the sixth image. Click on the drive folder to display the MyDrive folder.

3.2. Upload data to Google Drive

Click on this link and select the compressed file of the dataset on GitHub.

Click the green box in the first image to download the compressed file of the dataset.
Connect to Google Drive from Chrome signed in with your Google Account as shown in the second image. Open Google’s top page in a different tab from the one in which you opened Google Colab. Then click on the button in the upper right green frame and select the drive.
After connecting to Google Drive as shown in the third image, select My Drive.

Right-click on My Drive as shown in the first image and select “Upload File”.
Select the file to be uploaded from the folder on your PC as shown in the second image. In this example, I select gifu-ai-2025-03-23.zip in the download folder.
gifu-ai-2025-03-23.zip will be uploaded to My Drive as shown in the third image.

3.3. Refer to images on Google Drive in YOLO

In the example in 3.2. above, the compressed file gifu-ai-2025-03-23.zip of the dataset was uploaded, but image files can also be uploaded using the same procedure.

The following code cell performs object recognition by referencing the image file “DSC00422-min (SonyAlpha-side).JPG” placed on My Drive.

# Run inference on an image in Google Drive
!yolo predict model=yolo11n.pt source='/content/drive/MyDrive/DSC00422-min (SonyAlpha-横).JPG'
3.4. Training YOLO on a dataset placed on Google Drive

Click the arrow in the upper left corner of the code cell containing the script below. Copy the compressed file gifu-ai-2025-03-23.zip from Google Drive to the Google Colab folder and extract it.

%%bash
mkdir -p dataset
cd dataset
cp /content/drive/MyDrive/gifu-ai-2025-03-23.zip .
unzip gifu-ai-2025-03-23.zip

Click the arrow in the upper left corner of the code cell containing the script below. Refer to the dataset copied from Google Drive and train YOLO’s object detection model.

!yolo train model=yolo11n.pt data=/content/dataset/gifu-ai-2025-03-23/data.yaml epochs=50 batch=10

In this command example, the number of training iterations (epochs) is 50. The batch size is set to 10 (batch). Specify an appropriate batch size since it affects the recognition performance of the object detection model obtained after training.

The object detection model yolo11n.pt, which has already been trained on other datasets, is used as the initial value and trained on the given dataset.

The model is trained to detect several species of wild birds photographed in Toba River and Dodogamine in Gifu City. Birds in the dataset include great egrets, grey herons, Eurasian coots, oriental turtle doves, varied tits, eastern spot-billed ducks, mallards (male), Eurasian wigeons (male), and great cormorants.

3.5. Recognizing birds with trained YOLO

Click the arrow in the upper left corner of the code cell containing the script below. Object detection is performed by referring to the 17 image files placed in the directory gifu-ai-2025-03-23/images/test in the expanded dataset.

!yolo predict model=/content/runs/detect/train/weights/best.pt source=/content/dataset/gifu-ai-2025-03-23/images/test

The /content/runs/detect/train/weights/best.pt specified as model in the above command is the object detection model obtained by training in 3.4. above. The /content/dataset/gifu-ai-2025-03-23/images/test specified as source contains images that were not referenced in the training.

The image below is an example of a detection result image that appears by double-clicking on the image output file, /content/runs/detect/predict/DSC01632.jpg.

The following script also performs object detection using the object detection model obtained with the training described in 3.4. above. Object detection is performed using images outside the dataset as input.

!yolo predict model=/content/runs/detect/train/weights/best.pt source=https://www.leafwindow.com/wordpress-05/wp-content/uploads/2023/02/DSC00022-min-SonyAlpha-%E6%A8%AA.jpg

The images below are the examples of the results obtained by executing the code cell containing the above script. The three results are obtained by changing the image specified in source.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA