Полный код для обучения на новых данных выглядит следующим образом:
Код: Выделить всё
from ultralytics import YOLO
model = YOLO('yolov8/weights/yolov8n.pt')
results = model(source='./weirdobject.jpg', conf=0.25, save_txt=None)[0]
print(results)
annotated_frame = results.plot()
import cv2
import supervision as sv
sv.plot_image(annotated_frame)
#use roboflow to download the data annotated with the new image (the dataset contains 1 annotated image)
from roboflow import Roboflow
rf = Roboflow(api_key="idofproject")
print(rf.workspace().projects())
project = rf.workspace("id1").project("id2")
version = project.version(4)
#download the data from roboflow to train the model with
dataset = version.download(model_format="yolov8", location="./datasets")
#train the model with the data containing the added annotated image
results = model.train(data="roboflow_ml_image_detection/datasets/data.yaml", epochs=5)
results = model.val()
#yield the new predictions that should include the new image detection with the right label
results = model(source='./weirdobject.jpg', conf=0.25, save_txt=None)[0]
# this results is wrong as if the model wasn't trained with the new data containing the new image
print(results)
[![структура набора данных в проекте][1 ]][1]
Файл data.yaml имеет следующий вид:
Код: Выделить всё
names:
- small_ball
nc: 1
roboflow:
license: CC BY 4.0
project: nao-s07zd
url: https://universe.roboflow.com/id1/id2/dataset/4
version: 4
workspace: id2
#test: ../test/images
train: ./train/images
val: ./valid/images
[1]: https://i.sstatic.net/fz19fDF6.png
Подробнее здесь: https://stackoverflow.com/questions/787 ... onal-image