有关人脸检测RetinaFace分析

args.network == "mobile0.25"
    cfg = cfg_mnet
    
    #elif args.network == "resnet50":
    #    cfg = cfg_re50
    # net and model
    net = RetinaFace(cfg=cfg, phase = 'test')
    
    args.trained_model = 'mobilenet0.25_250.pth'   #epoch_200.pth'
    args.cpu = 1
    
    net = load_model(net, args.trained_model, args.cpu)
    net.eval()
    print('Finished loading model!')
    print(net)
    
    #cudnn.benchmark = True
    
    device = torch.device("cpu" if args.cpu else "cuda")
    net = net.to(device)
    
    ###########
    new_model = net
    new_model2 = net

      
    model_int8 = torch.quantization.quantize_dynamic(
    net,  # the original model
    {torch.nn.Conv2d,torch.nn.BatchNorm2d},  # a set of layers to dynamically quantize
    dtype=torch.quint8)
     
    print_size_of_model(net)
    print_size_of_model(model_int8)
    
    #torch.quantization.quantize_dynamic(new_model2, qconfig_spec=None, dtype=torch.qint8, mapping=None, inplace=False)
    
    f0 = open("para250-quint8.txt","w")
    
    for name, param in model_int8.named_parameters():
        f0.write(name)
        f0.write('\n')
        
        # quantize
        #param2 = torch.quantize_per_tensor(param, scale=1./127, zero_point=0, dtype=torch.qint8) 
        param2 = torch.quantize_per_tensor(param, scale=1./255, zero_point=127, dtype=torch.quint8)       
          
        y = param2.int_repr()
        
        #print(y)
        
        #numpy_para = param.numpy()  # tensor to numpy
        str = y.__repr__() 
        
        f0.write(str)
        f0.write('\n\n')
    
    
    
    for name, module in new_model.named_modules():
    # prune 20% of connections in all 2D-conv layers
        if isinstance(module, torch.nn.Conv2d):
            prune.l1_unstructured(module, name='weight', amount=0.5)
        # prune 40% of connections in all linear layers
        elif isinstance(module, torch.nn.Linear):
            prune.l1_unstructured(module, name='weight', amount=0.2)

    #print(dict(new_model.named_buffers()).keys()) 
    ############
    
    ##
    pthfile = 'mobilenet0.25_epoch_200.pth'
    net2 = torch.load(pthfile,map_location=torch.device('cpu'))
       
    f1 = open("para200-variable.txt","w")
    for k in net2.keys():
        #print(k)
        f1.write(k)
        f1.write('\n')
  

    resize = 1
    
    
    f00 = open("para250-prune-Conv2d-0.5.txt","w")
    
    for name, param in new_model.named_parameters():
        f00.write(name)
        f00.write('\n')
                  
        numpy_para = param.numpy()  # tensor to numpy
        str = numpy_para.__repr__() 
        f00.write(str)
        f00.write('\n\n')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值