estoy tratando de desplegar una palicacion de la cual ya tengo los pesos entrenados y esta funcionando en local, los pesos estan en un archivo .pt el cual tengo en la ruta de mi github el nombre del archivo que tiene los pesos optimos es ‘modelo_guardado.pt’, voy a adjuntar una parte del donde enruto el modelo
#Import All the Required Libraries
import cv2
import streamlit as st
from pathlib import Path
import sys
from ultralytics import YOLO
from PIL import Image
#Get the absolute path of the current file
FILE = Path(file).resolve()
ROOT = FILE.parent
MODEL_DIR = ROOT/‘weights’
#import torch
#import ultralytics.nn.tasks
#torch.serialization.add_safe_globals([ultralytics.nn.tasks.DetectionModel])
#DETECTION_MODEL = aplicativo-limpio/weights/‘modelo_guardado.pt’
DETECTION_MODEL = MODEL_DIR/‘modelo_guardado.pt’
al hacer el despliegue tengo el siguiente aviso:
Unable to load model. Check the sepcified path: weights/modelo_guardado.pt
Weights only load failed. This file can still be loaded, to do so you have two options, e[1mdo those steps only if you trust the source of the checkpointe[0m. (1) In PyTorch 2.6, we changed the default value of the weights_only argument in torch.load from False to True. Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. (2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message. WeightsUnpickler error: Unsupported global: GLOBAL ultralytics.nn.tasks.DetectionModel was not an allowed global by default. Please use torch.serialization.add_safe_globals([ultralytics.nn.tasks.DetectionModel]) or the torch.serialization.safe_globals([ultralytics.nn.tasks.DetectionModel]) context manager to allowlist this global if you trust this class/function.
Check the documentation of torch.load to learn more about types accepted by default with weights_only torch.load — PyTorch 2.7 documentation.
I’ve tried everything in the instructions, but I haven’t been able to get the model to work. Please, if anyone can help me, I’d appreciate it.
Thank you very much for your help.
Greetings from Colombia