I’m encountering a problem with creating space after uploading app.py and requirements.txt. For loading the model, I’m using this code: from ultralyticsplus import YOLO, render_result. (I use Gradio to create a website.)
The main task for uploading app.py to the space is that I want the HTML code to be embedded on the Google site.
model_path = ('(my model path on huggingface')
model = YOLO(model_path)
If I use another method to load the model instead of using YOLO, is it possible to fix this error?
The error said
The error said
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/ultralyticsplus/ultralytics_utils.py", line 59, in __init__
self._load_from_hf_hub(model, hf_token=hf_token)
File "/usr/local/lib/python3.10/site-packages/ultralyticsplus/ultralytics_utils.py", line 91, in _load_from_hf_hub
) = self._assign_ops_from_task()
File "/usr/local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'YOLO' object has no attribute '_assign_ops_from_task'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/user/app/app.py", line 95, in <module>
gr.Interface(fn=detect_objects,
File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 518, in __init__
self.render_examples()
File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 851, in render_examples
self.examples_handler = Examples(
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 71, in create_examples
examples_obj.create()
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 298, in create
client_utils.synchronize_async(self.cache)
File "/usr/local/lib/python3.10/site-packages/gradio_client/utils.py", line 889, in synchronize_async
return fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args, **kwargs) # type: ignore
File "/usr/local/lib/python3.10/site-packages/fsspec/asyn.py", line 103, in sync
raise return_result
File "/usr/local/lib/python3.10/site-packages/fsspec/asyn.py", line 56, in _runner
result[0] = await coro
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 360, in cache
prediction = await Context.root_block.process_api(
File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1695, in process_api
result = await self.call_function(
File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1235, in call_function
prediction = await anyio.to_thread.run_sync(
File "/usr/local/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread
return await future
File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 851, in run
result = context.run(func, *args)
File "/usr/local/lib/python3.10/site-packages/gradio/utils.py", line 692, in wrapper
response = f(*args, **kwargs)
File "/home/user/app/app.py", line 24, in detect_objects
model = YOLO(model_path)
File "/usr/local/lib/python3.10/site-packages/ultralyticsplus/ultralytics_utils.py", line 65, in __init__
raise NotImplementedError(
NotImplementedError: Unable to load model='MvitHYF/v8mvitcocoaseed2024'. As an example try model='yolov8n.pt' or model='yolov8n.yaml'
I also ran app.py on VSCode, and everything ran perfectly (run on localhost). However, I encountered this error when trying to create the space. I tried adding yolov8n.pt to both the model and the space site, but nothing changed. At first, I thought it might fix the error.
Thank you for you help