文章目录
- 前言
- 1. print(model)
- 2. print(model.named_models)
- 2.1 print(name)
- 2.2 print(module)
- 2.3 print(f"{name}:: {module}")
- 3. hasattr(module, 'weight')
前言
了解model.named_models,为剪枝做准备。
剪枝有一些层如果你不想剪掉,那就用需要你会用 model.named_models功能。
先放一段控制剪枝的代码,感受一下
ignored_layers = [] # 这些层不剪枝
# ignore output layers
# for cfg/training/yolov7-tiny-prune.yaml
for k, m in model.named_modules():
if isinstance(m, TSCODE_Detect):
ignored_layers.append(m.m_cls)
ignored_layers.append(m.m_reg)
ignored_layers.append(m.m_conf)
if isinstance(m, Yolov7_Tiny_E_ELAN_Attention):
ignored_layers.append(m.att)
1. print(model)
# Load model
model = attempt_load(weights, map_location=device) # load FP32 model
print(model)
输出网络结构,同学们可以去模型的yaml文件比对一下
yaml文件是模型的结构,打印的model是权重和操作
2. print(model.named_models)
2.1 print(name)
model = attempt_load(weights, map_location=device) # load FP32 model
for name, module in model.named_modules():
# print(f"{name}:: {module}")
print("NAME:", name)
2.2 print(module)
for name, module in model.named_modules():
print("MODULE:", module)
2.3 print(f"{name}:: {module}")
# Load model
model = attempt_load(weights, map_location=device) # load FP32 model
for name, module in model.named_modules():
print(f"{name}:: {module}")
3. hasattr(module, ‘weight’)
for name, module in model.named_modules():
if hasattr(module, 'weight'):
print(module)