1

This is part of task.py from yolov8 codebase.

m = self.model[-1] # Detect()
if isinstance(m, (Detect, Segment, Pose)):
 s = 256 # 2x min stride
 m.inplace = self.inplace
 forward = lambda x: self.forward(x)[0] if isinstance(m, (Segment, Pose)) else self.forward(x)
 m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))]) # forward
 self.stride = m.stride
 m.bias_init() # only run once
else:
 self.stride = torch.Tensor([32]) # default stride for i.e. RTDETR

So why yolov8 uses torch.zeros(1, ch, s, s), in this case (1,3,256,256), as input to forward pass to calculate model stride ? Doesn't yolov8 has default stride 32 ? can someone explain me will different task, like detect, segment, and Pose, will have different stride ?

the same question I have asked in yolov8 repo https://github.com/orgs/ultralytics/discussions/4492

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
rakeshKM
  • 53
  • 6

0 Answers0