hi happy to ask you this question.
i have a project that want extract a ROI region in image by instance segmentation.
i choose for this duty YOLO5 as i have spyder (3.11). first for exercising me make a training model with 5 images and this pre trained model = torch.hub.load(‘ultralytics/yolov5’, ‘yolov5s’) and was successful to make it.
` import torch
from PIL import Image
import os
# Step 1: Load the YOLOv5 model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Step 2: Prepare the training data
dataset_path = 'C:/Users/Stk/Desktop'
image_files = ['eye_1.png', 'eye_2.png', 'eye_3.png', 'eye_4.png', 'eye_5.png']
images = [Image.open(os.path.join(dataset_path, f)) for f in image_files]
# Step 3: Fit the model on the training data
results = model(images)
# Step 4: Inspect the results
display(results.pandas().xyxy[0])
# Step 5: Save the model for use with the camera
model.eval()
save_path = os.path.join(dataset_path, 'yolov5s.pt')
torch.save(model.state_dict(), save_path)`
but after that i went to make a good training model with 50 images and tag them like eye_number.png similarly and use yolov5s again as pre trained model. but my challenges arise due to below error.
” Exception: ‘model’. Cache may be out of date, try force_reload=True
or see https:// docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help.”
down is my second try to make a training model
import torch
from PIL import Image
import os
# Step 1: Load the YOLOv5 model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Step 2: Prepare the training data
dataset_path = 'C:/Users/Stk/Desktop'
image_files = ['eye_1.png', 'eye_2.png', 'eye_3.png', 'eye_4.png', 'eye_5.png',
'eye_6.png', 'eye_7.png', 'eye_8.png', 'eye_9.png', 'eye_10.png']
images = [Image.open(os.path.join(dataset_path, f)) for f in image_files]
# Step 3: Fit the model on the training data
results = model(images)
# Step 4: Inspect the results
display(results.pandas().xyxy[0])
# Step 5: Save the model for use with the camera
model.eval()
save_path = 'D:/yolov5s_webcam.pt'
torch.save(model.state_dict(), save_path)`
i try to changing the direct of saving model but not help me.
how can i fix this error?
thanks in advance.