Replies: 7 comments 11 replies
-
|
Hello! Thanks for reaching out with your issue. 🤔 From what you've described, it seems the significant increase in inference time for image streams might be related to network latency or processing overhead for fetching the images from URLs. When you're doing inference directly on an image file, the operation is pretty straightforward and swift since the image data is readily available. However, for image streams coming from URLs, the additional time could be from the download time required to fetch each image over the network before it can be processed. One possible solution to mitigate this could be pre-fetching the images asynchronously before running them through the model, or caching the images locally if you're running multiple inferences on the same set of URLs. For example, you could use something like this to asynchronously download images: import asyncio
import aiohttp
async def download_image(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
content = await response.read()
# Save content to an image file or directly feed it to your model
# Assuming you have a list of URLs
urls = ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]
loop = asyncio.get_event_loop()
tasks = [download_image(url) for url in urls]
loop.run_until_complete(asyncio.wait(tasks))Ensure your model is ready to handle the data after it's downloaded, and this might help reduce the inference time. I hope this helps, and if you have further questions or if this doesn't resolve your issue, feel free to ask! 😊 |
Beta Was this translation helpful? Give feedback.
-
|
Hi, My mistake for not making it clear in the question but I'm getting these URL picture links from a live VMS software program using |
Beta Was this translation helpful? Give feedback.
-
|
I'm getting unsupported image type using the code you suggested here is the error: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
-
|
For completeness, I solved it by doing the following using the PIL module: Incorporate the above in your event loop handling incoming URLs for images. |
Beta Was this translation helpful? Give feedback.
-
|
Hi I’m still getting slow speeds processing the data from a stream even though Then I use Multiprocessing to fetch the inferences: And are get the following timings for each inference: 0: 384x640 1 person, 264.5ms 0: 384x640 1 person, 3 chairs, 1 bed, 1 tv, 1 laptop, 1 keyboard, 1 teddy bear, 294.8ms 0: 384x640 1 person, 1 cup, 3 chairs, 1 potted plant, 1 bed, 1 tv, 1 keyboard, 1 teddy bear, 325.7ms 0: 384x640 1 person, 234.3ms 0: 384x640 1 person, 2 chairs, 1 bed, 1 tv, 1 laptop, 1 keyboard, 1 teddy bear, 266.5ms 0: 384x640 1 person, 1 cup, 2 chairs, 1 potted plant, 1 bed, 1 tv, 1 laptop, 1 keyboard, 1 teddy bear, 243.7ms ---done inference--- --- After 0.8858550707499186 minutes... As you can see the total time from these results is 15.6+264.5+...+1385.6 = 10.25 seconds [1] fetching from a socket an XML data message, sending to another computer via sockets an alert message |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your reply and help, I slightly modified the code as it was still crashing with keyerrors but it still gives key errors... The errors are still as follows... |
Beta Was this translation helpful? Give feedback.
-
|
Before I give an MRE with multiprocessing I thought I'd export an optimal .engine file for the A2 card in the server. Beforehand I did not use from ultralytics import YOLO
model = YOLO("yolov8x-seg.pt")
model.export(format="engine", dynamic=True, batch=8, workspace=4, int8=True, data="coco.yaml")Upon Inference of an image gave the following error: (the other two models worked) AttributeError Traceback (most recent call last)
Cell In[1], line 36
20 rp = modelp.predict(img,
21 # settings
22 verbose=True,
(...)
25 amp=True,
26 imgsz=640)[0].cpu()
28 ro = modelo.predict(img,
29 # settings
30 verbose=True,
(...)
33 amp=True,
34 imgsz=640)[0].cpu()
---> 36 rs = models.predict(img,
37 # settings
38 verbose=True,
39 conf=0.1,
40 max_det=20,
41 amp=True,
42 imgsz=640)[0].cpu()
44 chairs = ib.get_chairs_bbox(ro, rs, 0.3)
45 print(len(chairs))
File c:\Users\Western\AppData\Local\Programs\Python\Python312\Lib\site-packages\ultralytics\engine\model.py:435, in Model.predict(self, source, stream, predictor, **kwargs)
433 if not self.predictor:
434 self.predictor = predictor or self._smart_load("predictor")(overrides=args, _callbacks=self.callbacks)
--> 435 self.predictor.setup_model(model=self.model, verbose=is_cli)
436 else: # only update args if predictor is already setup
437 self.predictor.args = get_cfg(self.predictor.args, args)
File c:\Users\Western\AppData\Local\Programs\Python\Python312\Lib\site-packages\ultralytics\engine\predictor.py:303, in BasePredictor.setup_model(self, model, verbose)
301 def setup_model(self, model, verbose=True):
302 """Initialize YOLO model with given parameters and set it to evaluation mode."""
--> 303 self.model = AutoBackend(
304 weights=model or self.args.model,
305 device=select_device(self.args.device, verbose=verbose),
306 dnn=self.args.dnn,
307 data=self.args.data,
308 fp16=self.args.half,
309 batch=self.args.batch,
310 fuse=True,
311 verbose=verbose,
312 )
314 self.device = self.model.device # update device
315 self.args.half = self.model.fp16 # update half
File c:\Users\Western\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\utils\_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
112 @functools.wraps(func)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)
File c:\Users\Western\AppData\Local\Programs\Python\Python312\Lib\site-packages\ultralytics\nn\autobackend.py:265, in AutoBackend.__init__(self, weights, device, dnn, data, fp16, batch, fuse, verbose)
263 if -1 in tuple(model.get_tensor_shape(name)):
264 dynamic = True
--> 265 context.set_input_shape(name, tuple(model.get_tensor_profile_shape(name, 0)[1]))
266 if dtype == np.float16:
267 fp16 = True
AttributeError: 'NoneType' object has no attribute 'set_input_shape'Can you help with what could be the problem? |
Beta Was this translation helpful? Give feedback.
-
|
Anyway I solved my speed problems by asking back and forth with the ChatGPT GPT-4o model (One of their most advanced but requires This is implemented with this simple call and return result code: Thanks for the initial help, but I'm slightly disappointed this wasn't thought of... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm having a problem running inference on a Tesla T4 card. Normally the code runs fast (150ms) see below
when running on one image but when running on an image stream supplied by URLs the inference time blows
out to 6+ seconds (see further down) is the format for the image causing a problem? (see code at bottom of page for URL pics below)
0: 480x640 1 person, 6569.2ms
Speed: 144.4ms preprocess, 6569.2ms inference, 1284.4ms postprocess per image at shape (1, 3, 480, 640)
Run Inference 8.315574169158936
Beta Was this translation helpful? Give feedback.
All reactions