|
|
@ -301,28 +301,22 @@ def fuse_deconv_and_bn(deconv, bn): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def model_info(model, detailed=False, verbose=True, imgsz=640): |
|
|
|
def model_info(model, detailed=False, verbose=True, imgsz=640): |
|
|
|
""" |
|
|
|
"""Print and return detailed model information layer by layer.""" |
|
|
|
Model information. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imgsz may be int or list, i.e. imgsz=640 or imgsz=[640, 320]. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
if not verbose: |
|
|
|
if not verbose: |
|
|
|
return |
|
|
|
return |
|
|
|
n_p = get_num_params(model) # number of parameters |
|
|
|
n_p = get_num_params(model) # number of parameters |
|
|
|
n_g = get_num_gradients(model) # number of gradients |
|
|
|
n_g = get_num_gradients(model) # number of gradients |
|
|
|
n_l = len(list(model.modules())) # number of layers |
|
|
|
n_l = len(list(model.modules())) # number of layers |
|
|
|
if detailed: |
|
|
|
if detailed: |
|
|
|
LOGGER.info( |
|
|
|
LOGGER.info(f"{'layer':>5}{'name':>40}{'gradient':>10}{'parameters':>12}{'shape':>20}{'mu':>10}{'sigma':>10}") |
|
|
|
f"{'layer':>5} {'name':>40} {'gradient':>9} {'parameters':>12} {'shape':>20} {'mu':>10} {'sigma':>10}" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
for i, (name, p) in enumerate(model.named_parameters()): |
|
|
|
for i, (name, p) in enumerate(model.named_parameters()): |
|
|
|
name = name.replace("module_list.", "") |
|
|
|
name = name.replace("module_list.", "") |
|
|
|
LOGGER.info( |
|
|
|
LOGGER.info( |
|
|
|
"%5g %40s %9s %12g %20s %10.3g %10.3g %10s" |
|
|
|
f"{i:>5g}{name:>40s}{p.requires_grad!r:>10}{p.numel():>12g}{str(list(p.shape)):>20s}" |
|
|
|
% (i, name, p.requires_grad, p.numel(), list(p.shape), p.mean(), p.std(), p.dtype) |
|
|
|
f"{p.mean():>10.3g}{p.std():>10.3g}{str(p.dtype):>15s}" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
flops = get_flops(model, imgsz) |
|
|
|
flops = get_flops(model, imgsz) # imgsz may be int or list, i.e. imgsz=640 or imgsz=[640, 320] |
|
|
|
fused = " (fused)" if getattr(model, "is_fused", lambda: False)() else "" |
|
|
|
fused = " (fused)" if getattr(model, "is_fused", lambda: False)() else "" |
|
|
|
fs = f", {flops:.1f} GFLOPs" if flops else "" |
|
|
|
fs = f", {flops:.1f} GFLOPs" if flops else "" |
|
|
|
yaml_file = getattr(model, "yaml_file", "") or getattr(model, "yaml", {}).get("yaml_file", "") |
|
|
|
yaml_file = getattr(model, "yaml_file", "") or getattr(model, "yaml", {}).get("yaml_file", "") |
|
|
|