code: def main():
      weights_path = "./resNet34.pth"
      model = resnet34(num_classes=5)
      model.load_state_dict(
          torch.load(weights_path, map_location=device)
      )
      model.to(device)
      # validate_model(model)
      # module = model.conv1
      # print(list(module.named_parameters()))
      # # print(list(module.named_buffers()))
      #
      # # 裁剪50%的卷积核
      # prune.ln_structured(module, name="weight", amount=0.5, n=2, dim=0)
      # print(list(module.weight))
      # print(module.weight.shape)
      # # print(list(module.named_buffers()))
      #
      # prune.remove(module, "weight")
      # print(module.weight.shape)
  
      # 收集所有需要裁剪的卷积核
      parameters_to_prune = []
      for name, module in model.named_modules():
          if isinstance(module, torch.nn.Conv2d):
              parameters_to_prune.append((module, "weight"))
  
      # 对卷积核进行剪枝处理
      prune.global_unstructured(
          parameters_to_prune,
          pruning_method=prune.L1Unstructured,
          amount=0.5,
      )
  
      # 统计剪枝比例
      count_sparsity(model, p=False)
  
      # 验证剪枝后的模型
      validate_model(model)
  
file_path: deep-learning-for-image-processing/deploying_service/pruning_model_pytorch/main.py
imports: import os
  import torch
  from torchvision import transforms, datasets
  import torch.nn.utils.prune
  import torch.nn.functional
  from tqdm import tqdm
  import time
  from model import resnet34
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types