New YOLOv8 Results() class for prediction outputs (#314)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Laughing-q <1185102784@qq.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com>
Co-authored-by: Viet Nhat Thai <60825385+vietnhatthai@users.noreply.github.com>
Co-authored-by: Paula Derrenger <107626595+pderrenger@users.noreply.github.com>
This commit is contained in:
Ayush Chaurasia
2023-01-17 19:02:34 +05:30
committed by GitHub
parent 0cb87f7dd3
commit c6985da9de
32 changed files with 813 additions and 259 deletions

View File

@ -65,6 +65,7 @@ class AutoBackend(nn.Module):
model = weights.to(device)
model = model.fuse() if fuse else model
names = model.module.names if hasattr(model, 'module') else model.names # get class names
stride = max(int(model.stride.max()), 32) # model stride
model.half() if fp16 else model.float()
self.model = model # explicitly assign for to(), cpu(), cuda(), half()
pt = True
@ -236,7 +237,7 @@ class AutoBackend(nn.Module):
Runs inference on the YOLOv8 MultiBackend model.
Args:
im (torch.tensor): The image tensor to perform inference on.
im (torch.Tensor): The image tensor to perform inference on.
augment (bool): whether to perform data augmentation during inference, defaults to False
visualize (bool): whether to visualize the output predictions, defaults to False
@ -328,10 +329,10 @@ class AutoBackend(nn.Module):
Convert a numpy array to a tensor.
Args:
x (numpy.ndarray): The array to be converted.
x (np.ndarray): The array to be converted.
Returns:
(torch.tensor): The converted tensor
(torch.Tensor): The converted tensor
"""
return torch.from_numpy(x).to(self.device) if isinstance(x, np.ndarray) else x

View File

@ -27,12 +27,12 @@ class BaseModel(nn.Module):
Wrapper for `_forward_once` method.
Args:
x (torch.tensor): The input image tensor
x (torch.Tensor): The input image tensor
profile (bool): Whether to profile the model, defaults to False
visualize (bool): Whether to return the intermediate feature maps, defaults to False
Returns:
(torch.tensor): The output of the network.
(torch.Tensor): The output of the network.
"""
return self._forward_once(x, profile, visualize)
@ -41,12 +41,12 @@ class BaseModel(nn.Module):
Perform a forward pass through the network.
Args:
x (torch.tensor): The input tensor to the model
x (torch.Tensor): The input tensor to the model
profile (bool): Print the computation time of each layer if True, defaults to False.
visualize (bool): Save the feature maps of the model if True, defaults to False
Returns:
(torch.tensor): The last output of the model.
(torch.Tensor): The last output of the model.
"""
y, dt = [], [] # outputs
for m in self.model: