How to train the model to identify custom objects?
This is the initial pre-trained model that has a set of objects and images for detection (it fails to recognize a pen)
This is after training it to recognize a pen
Here is a step by step guide on how to identify custom objects
I have used my NVIDIA Jetson Orin Nano running Jetpack7.2.1 for this project
- Verify your JetPack version.
cat /etc/nv_tegra_release
- Make sure the following JetPack contents are installed.
- CUDA
- cuDNN
- TensorRT
- VPI
- multimedia libraries
- NVIDIA container runtime
- If you are not sure the JetPack is installed then type the following command:
sudo apt update
sudo apt install nvidia-jetpack
- Then run
sudo reboot
- Verify the installed CUDA version:
nvcc --version
- Check if you have Python installed
python3 --version
- Create a YOLO project
mkdir -p ~/yolo-jetson
cd ~/yolo-jetson
- Create a Python virtual environment
python3 -m venv yolo-env
- Activate it
source yolo-env/bin/activate
- Every time you open a new terminal you can activate it with :
cd ~/yolo-jetson
source yolo-env/bin/activate
- Upgrade PIP
python3 -m pip install --upgrade pip
- Install Ultralytics
pip install ultralytics
- Install the correct version of PyTorch for JetPack 7.2.1.
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu130
- Verify PyTorch
python3
- Then,
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
or
python3 -c "import torch; print('PyTorch:', torch.__version__); print('CUDA available:', torch.cuda.is_available()); print('GPU:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'N/A')"
- Install ONNX Runtime GPU
pip install https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.24.0-cp312-cp312-linux_aarch64.whl
- Run your first Ultralytics program
yolo predict model=yolo26n.pt source="https://github.com/ultralytics/assets/releases/download/v0.0.0/bus.jpg"
- After this works you can run YOLO on your image.Create your image folder.
mkdir -p images
You can use images that are already annotated or annotate them yourseves using roboflow.
If you decide to annotate them yourself,
- Create your project on Roboflow or any other similar platforms.
- Annotate the object you want to train precisely.
Remember to annotate around 250-400 images for better accuracy.
Export the whole image set in YOLOv8 format
- From the directory containing your dataset:
yolo detect train \
model=yolo26n.pt \
data=pen-dataset/data.yaml \
epochs=100 \
imgsz=640 \
device=0
- Run
yolo predict \
model=runs/detect/train/weights/best.pt \
source=some_new_pen_image.jpg
- Export to TensorRT
yolo export \
model=models/best.pt \
format=engine \
half=True
- Run TensorRT
yolo predict \
model=models/best.engine \
source=images/test_pen.jpg \
device=0
- Try it out!!
yolo predict model=models/best.pt source=0 device=0 show=True
or
yolo predict model=models/best.engine source=0 device=0 show=True
- If it is the first test then run the test by running the following command:
cd ~/yolo-jetson
source yolo-env/bin/activate
yolo predict model=models/best.pt source=0 device=0 show=True


Top comments (1)
Good going