OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how fix keyerror 'model' when make a training model as CNN for image segmentation?

  • Thread starter Thread starter isa nemati
  • Start date Start date
I

isa nemati

Guest
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

Code:
# 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

Code:
     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.
<p>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.</p>
<p>` import torch
from PIL import Image
import os</p>
<pre><code># 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)`
</code></pre>
<p>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 <code>force_reload=True</code> or see https:// docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help."
down is my second try to make a training model</p>
<pre><code> 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)`
</code></pre>
<p>i try to changing the direct of saving model but not help me.
how can i fix this error?
thanks in advance.</p>
 

Latest posts

Top