Fix LoadStreams
final frame bug (#4387)
Co-authored-by: Nadim Bou Alwan <64587372+nadinator@users.noreply.github.com>
This commit is contained in:
@ -442,5 +442,5 @@ def copy_default_cfg():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Example Usage: entrypoint(debug='yolo predict model=yolov8n.pt')
|
||||
# Example: entrypoint(debug='yolo predict model=yolov8n.pt')
|
||||
entrypoint(debug='')
|
||||
|
@ -36,11 +36,12 @@ def convert_coco(labels_dir='../coco/annotations/', use_segments=False, use_keyp
|
||||
use_keypoints (bool, optional): Whether to include keypoint annotations in the output.
|
||||
cls91to80 (bool, optional): Whether to map 91 COCO class IDs to the corresponding 80 COCO class IDs.
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: If the labels_dir path does not exist.
|
||||
Example:
|
||||
```python
|
||||
from ultralytics.data.converter import convert_coco
|
||||
|
||||
Example Usage:
|
||||
convert_coco(labels_dir='../coco/annotations/', use_segments=True, use_keypoints=True, cls91to80=True)
|
||||
convert_coco('../datasets/coco/annotations/', use_segments=True, use_keypoints=False, cls91to80=True)
|
||||
```
|
||||
|
||||
Output:
|
||||
Generates output files in the specified output directory.
|
||||
|
@ -79,19 +79,18 @@ class LoadStreams:
|
||||
def update(self, i, cap, stream):
|
||||
"""Read stream `i` frames in daemon thread."""
|
||||
n, f = 0, self.frames[i] # frame number, frame array
|
||||
while self.running and cap.isOpened() and n < f:
|
||||
while self.running and cap.isOpened() and n < (f - 1):
|
||||
# Only read a new frame if the buffer is empty
|
||||
if not self.imgs[i]:
|
||||
n += 1
|
||||
cap.grab() # .read() = .grab() followed by .retrieve()
|
||||
if n % self.vid_stride == 0:
|
||||
success, im = cap.retrieve()
|
||||
if success:
|
||||
self.imgs[i].append(im) # add image to buffer
|
||||
else:
|
||||
if not success:
|
||||
im = np.zeros(self.shape[i], dtype=np.uint8)
|
||||
LOGGER.warning('WARNING ⚠️ Video stream unresponsive, please check your IP camera connection.')
|
||||
self.imgs[i].append(np.zeros(self.shape[i]))
|
||||
cap.open(stream) # re-open stream if signal was lost
|
||||
self.imgs[i].append(im) # add image to buffer
|
||||
else:
|
||||
time.sleep(0.01) # wait until the buffer is empty
|
||||
|
||||
|
@ -463,6 +463,7 @@ class Exporter:
|
||||
yaml_save(f / 'metadata.yaml', self.metadata) # add metadata.yaml
|
||||
return str(f), None
|
||||
|
||||
@try_export
|
||||
def export_coreml(self, prefix=colorstr('CoreML:')):
|
||||
"""YOLOv8 CoreML export."""
|
||||
mlmodel = self.args.format.lower() == 'mlmodel' # legacy *.mlmodel export format requested
|
||||
|
@ -175,15 +175,6 @@ class RepConv(nn.Module):
|
||||
kernelid, biasid = self._fuse_bn_tensor(self.bn)
|
||||
return kernel3x3 + self._pad_1x1_to_3x3_tensor(kernel1x1) + kernelid, bias3x3 + bias1x1 + biasid
|
||||
|
||||
def _avg_to_3x3_tensor(self, avgp):
|
||||
channels = self.c1
|
||||
groups = self.g
|
||||
kernel_size = avgp.kernel_size
|
||||
input_dim = channels // groups
|
||||
k = torch.zeros((channels, input_dim, kernel_size, kernel_size))
|
||||
k[np.arange(channels), np.tile(np.arange(input_dim), groups), :, :] = 1.0 / kernel_size ** 2
|
||||
return k
|
||||
|
||||
def _pad_1x1_to_3x3_tensor(self, kernel1x1):
|
||||
if kernel1x1 is None:
|
||||
return 0
|
||||
|
@ -437,11 +437,17 @@ def check_amp(model):
|
||||
Args:
|
||||
model (nn.Module): A YOLOv8 model instance.
|
||||
|
||||
Example:
|
||||
```python
|
||||
from ultralytics import YOLO
|
||||
from ultralytics.utils.checks import check_amp
|
||||
|
||||
model = YOLO('yolov8n.pt').model.cuda()
|
||||
check_amp(model)
|
||||
```
|
||||
|
||||
Returns:
|
||||
(bool): Returns True if the AMP functionality works correctly with YOLOv8 model, else False.
|
||||
|
||||
Raises:
|
||||
AssertionError: If the AMP checks fail, indicating anomalies with the AMP functionality on the system.
|
||||
"""
|
||||
device = next(model.parameters()).device # get model device
|
||||
if device.type in ('cpu', 'mps'):
|
||||
|
Reference in New Issue
Block a user