|
|
@@ -123,27 +123,31 @@ class Yolov8Backbone(nn.Module):
|
|
|
if __name__ == '__main__':
|
|
|
import time
|
|
|
from thop import profile
|
|
|
+
|
|
|
+ # YOLOv8 config
|
|
|
class BaseConfig(object):
|
|
|
def __init__(self) -> None:
|
|
|
- self.use_pretrained = True
|
|
|
- self.width = 0.25
|
|
|
+ self.use_pretrained = False
|
|
|
+ self.width = 0.50
|
|
|
self.depth = 0.34
|
|
|
- self.ratio = 2.0
|
|
|
- self.model_scale = "n"
|
|
|
-
|
|
|
+ self.ratio = 2.00
|
|
|
+ self.model_scale = "s"
|
|
|
cfg = BaseConfig()
|
|
|
+
|
|
|
+ # Build backbone
|
|
|
model = Yolov8Backbone(cfg)
|
|
|
- x = torch.randn(1, 3, 640, 640)
|
|
|
- t0 = time.time()
|
|
|
+
|
|
|
+ # Randomly generate a input data
|
|
|
+ x = torch.randn(2, 3, 640, 640)
|
|
|
+
|
|
|
+ # Inference
|
|
|
outputs = model(x)
|
|
|
- t1 = time.time()
|
|
|
- print('Time: ', t1 - t0)
|
|
|
+ print(' - the shape of input : ', x.shape)
|
|
|
for out in outputs:
|
|
|
- print(out.shape)
|
|
|
+ print(' - the shape of output : ', out.shape)
|
|
|
|
|
|
x = torch.randn(1, 3, 640, 640)
|
|
|
- print('==============================')
|
|
|
flops, params = profile(model, inputs=(x, ), verbose=False)
|
|
|
- print('==============================')
|
|
|
- print('GFLOPs : {:.2f}'.format(flops / 1e9 * 2))
|
|
|
- print('Params : {:.2f} M'.format(params / 1e6))
|
|
|
+ print('============== FLOPs & Params ================')
|
|
|
+ print(' - FLOPs : {:.2f} G'.format(flops / 1e9 * 2))
|
|
|
+ print(' - Params : {:.2f} M'.format(params / 1e6))
|