Pytorch骨干网络性能测试
生活随笔
收集整理的這篇文章主要介紹了
Pytorch骨干网络性能测试
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Pytorch骨干網(wǎng)絡(luò)性能測(cè)試
測(cè)試平臺(tái):
- Intel? Core? i7-8700 CPU @ 3.20GHz × 12
- GeForce RTX 2070/PCIe/SSE2
| mobilenet_v2 | [1,3,112,112] | 512 | 4.743 | 910 |
| reset18 | [1,3,112,112] | 512 | 2.372 | 960 |
| resnet34 | [1,3,112,112] | 512 | 3.974 | 1010 |
| vgg16 | [1,3,112,112] | 512 | 3.844 | 1460 |
| squeezenet1_0 | [1,3,112,112] | 512 | 2.103 | 897 |
| squeezenet1_1 | [1,3,112,112] | 512 | 2.095 | 891 |
| mnasnet1_0 | [1,3,112,112] | 512 | 4.248 | 909 |
| shufflenet_v2_x1_0 | [1,3,112,112] | 512 | 5.449 | 891 |
| inception_v3 | [1,3,112,112] | 512 | 12.341 | 1203 |
| googlenet | [1,3,112,112] | 512 | 5.752 | 935 |
| MixNet_S | [1,3,112,112] | 512 | 8.260 | 930 |
| MixNet_M | [1,3,112,112] | 512 | 9.914 | 960 |
| MixNet_L | [1,3,112,112] | 512 | 10.020 | 990 |
| ? | ? | ? | ? | ? |
測(cè)試代碼:
# -*-coding: utf-8 -*- """@Project: pytorch-learning-tutorials@File : main.py@Author : panjq@E-mail : pan_jinquan@163.com@Date : 2019-06-27 13:46:20 """ import torch from torchvision import models from utils import debug import performance.core.mixnet as mixnetdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu") # device = 'cpu' print("-----device:{}".format(device)) print("-----Pytorch version:{}".format(torch.__version__))# @debug.run_time_decorator() def model_forward(model, input_tensor):T0 = debug.TIME()out = model(input_tensor)torch.cuda.synchronize()T1 = debug.TIME()time = debug.RUN_TIME(T1 - T0)return out, timedef iter_model(model, input_tensor, iter):out, time = model_forward(model, input_tensor)all_time = 0for i in range(iter):out, time = model_forward(model, input_tensor)all_time += timereturn all_timedef squeezenet1_0(input_tensor, out_features, iter=10):model = models.squeezenet.squeezenet1_0(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("squeezenet1_0,mean run time :{:.3f}".format(all_time / iter))def squeezenet1_1(input_tensor, out_features, iter=10):model = models.squeezenet.squeezenet1_1(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("squeezenet1_1,mean run time :{:.3f}".format(all_time / iter))def mnasnet1_0(input_tensor, out_features, iter=10):model = models.mnasnet.mnasnet1_0(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("mnasnet1_0,mean run time :{:.3f}".format(all_time / iter))def shufflenet_v2_x1_0(input_tensor, out_features, iter=10):model = models.shufflenetv2.shufflenet_v2_x1_0(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("shufflenet_v2_x1_0,mean run time :{:.3f}".format(all_time / iter))def mobilenet_v2(input_tensor, out_features, iter=10):model = models.mobilenet_v2(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("mobilenet_v2,mean run time :{:.3f}".format(all_time / iter))def resnet18(input_tensor, out_features, iter=10):model = models.resnet18(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("reset18,mean run time :{:.3f}".format(all_time / iter))def resnet34(input_tensor, out_features, iter=10):model = models.resnet34(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("resnet34,mean run time :{:.3f}".format(all_time / iter))def vgg16(input_tensor, out_features, iter=10):model = models.vgg16(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("vgg16,mean run time :{:.3f}".format(all_time / iter))def MixNet_L(input_tensor, input_size, out_features, iter=10):model = mixnet.MixNet_L(input_size, out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("MixNet_L,mean run time :{:.3f}".format(all_time / iter))def MixNet_M(input_tensor, input_size, out_features, iter=10):model = mixnet.MixNet_M(input_size, out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("MixNet_M,mean run time :{:.3f}".format(all_time / iter))def MixNet_S(input_tensor, input_size, out_features, iter=10):model = mixnet.MixNet_S(input_size, out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("MixNet_S,mean run time :{:.3f}".format(all_time / iter))def inception_v3(input_tensor, out_features, iter=10):model = models.inception.inception_v3(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("inception_v3,mean run time :{:.3f}".format(all_time / iter))def googlenet(input_tensor, out_features, iter=10):model = models.googlenet(pretrained=False, num_classes=out_features).to(device)model.eval()all_time = iter_model(model, input_tensor, iter)print("googlenet,mean run time :{:.3f}".format(all_time / iter))if __name__ == "__main__":input_size = [112, 112]out_features = 512input_tensor = torch.randn(1, 3, input_size[0], input_size[1]).to(device)print('input_tensor:', input_tensor.shape)iter = 10000# mobilenet_v2(input_tensor, out_features, iter)# resnet18(input_tensor, out_features, iter)# resnet34(input_tensor, out_features, iter)# vgg16(input_tensor, out_features, iter)# squeezenet1_0(input_tensor, out_features, iter)# squeezenet1_1(input_tensor, out_features, iter)# inception_v3(input_tensor, out_features, iter)googlenet(input_tensor, out_features, iter)# mnasnet1_0(input_tensor, out_features, iter)# shufflenet_v2_x1_0(input_tensor, out_features, iter)# MixNet_S(input_tensor, input_size, out_features, iter)# MixNet_M(input_tensor, input_size, out_features, iter)# MixNet_L(input_tensor, input_size, out_features, iter)?
總結(jié)
以上是生活随笔為你收集整理的Pytorch骨干网络性能测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决mxnet错误:OSError: l
- 下一篇: 解决 from torch._C imp