ultralytics / hub

Ultralytics HUB tutorials and support
https://hub.ultralytics.com
GNU Affero General Public License v3.0
138 stars 14 forks source link

UnpicklingError: Invalid load key when loading model from Ultralytics HUB #925

Open rjacaac211 opened 1 week ago

rjacaac211 commented 1 week ago

Search before asking

HUB Component

Models, Training

Bug

I am experiencing an UnpicklingError while attempting to load a model from Ultralytics HUB in Python. The error occurs despite successful authentication and confirmation that the model was downloaded.

Ultralytics HUB: View model at https://hub.ultralytics.com/models/NmBAojugSjGYoRfLmYoZ πŸš€
Found https://storage.googleapis.com/ultralytics-hub.appspot.com/users/PXpjF6uXemg1w8IEmvatQ5fSPMW2/models/NmBAojugSjGYoRfLmYoZ/epoch-63.pt locally at weights/epoch-63.pt
---------------------------------------------------------------------------
UnpicklingError                           Traceback (most recent call last)
<ipython-input-8-dbff24cb0977> in <cell line: 2>()
      1 # Load your model from HUB
----> 2 model = YOLO('https://hub.ultralytics.com/models/NmBAojugSjGYoRfLmYoZ')

7 frames
/usr/local/lib/python3.10/dist-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
   1626         )
   1627 
-> 1628     magic_number = pickle_module.load(f, **pickle_load_args)
   1629     if magic_number != MAGIC_NUMBER:
   1630         raise RuntimeError("Invalid magic number; corrupt file?")

UnpicklingError: invalid load key, '<'.

Environment

Using Google Colab

%pip install ultralytics  # install
from ultralytics import YOLO, checks, hub

checks()  # checks

Ultralytics 8.3.29 πŸš€ Python-3.10.12 torch-2.5.0+cu121 CUDA:0 (NVIDIA L4, 22700MiB) Setup complete βœ… (12 CPUs, 53.0 GB RAM, 32.1/235.7 GB disk)

Minimal Reproducible Example

# Login to HUB using your API key
hub.login('2ab43a5d8c3ba1dddd1121b95e4d8bba83200728b2')

# Load your model from HUB
model = YOLO('https://hub.ultralytics.com/models/NmBAojugSjGYoRfLmYoZ')

Additional

No response

UltralyticsAssistant commented 1 week ago

πŸ‘‹ Hello @rjacaac211, thank you for bringing this issue to our attention regarding Ultralytics HUB πŸš€! Please explore our comprehensive HUB Docs to maximize your understanding and usage of the platform:

It seems you're encountering an πŸ› error when attempting to load a model. To better assist you, please ensure the provided snippet accurately recreates the issue you're experiencing. This will help us diagnose and address the problem more effectively. Here's a link to guide you on creating a minimum reproducible example.

An Ultralytics engineer will soon delve into this to provide more detailed assistance. Thanks for your patience and collaboration! 😊

glenn-jocher commented 1 week ago

@rjacaac211 thank you for the bug report. I'm able to reproduce this, but please don't share your API key in the future as other users can then use your account. You should delete this key and create another.

This problem may be transient and specific to just this model, can you try training another model quickly to see if this happens again, i.e. you can train COCO8 for 3 epochs quickly.

Screenshot 2024-11-12 at 11 18 40
rjacaac211 commented 1 week ago

@rjacaac211 thank you for the bug report. I'm able to reproduce this, but please don't share your API key in the future as other users can then use your account. You should delete this key and create another.

This problem may be transient and specific to just this model, can you try training another model quickly to see if this happens again, i.e. you can train COCO8 for 3 epochs quickly.

Screenshot 2024-11-12 at 11 18 40

Thank you for the response @glenn-jocher. Does that mean that I will never be able to continue my training in that model? If so, what can I do to prevent this from happening again? Also, I have already deleted the API key.

glenn-jocher commented 1 week ago

@rjacaac211 I suspect this particular model may not be salvageable, but you should be able to train a new model. If you have any problems there please let us know!