이 repo의 목표는 다음과 같습니다.
소식:
pip install pretrainedmodels , pretrainedmodels.model_names , pretrainedmodels.pretrained_settingspython setup.py installgit pull 이 필요합니다)model.features(input) , model.logits(features) , model.forward(input) , model.last_linear )pip install pretrainedmodelsgit clone https://github.com/Cadene/pretrained-models.pytorch.gitcd pretrained-models.pytorchpython setup.py install pretrainedmodels 가져 오려면 : import pretrainedmodels print ( pretrainedmodels . model_names )
> [ 'fbresnet152' , 'bninception' , 'resnext101_32x4d' , 'resnext101_64x4d' , 'inceptionv4' , 'inceptionresnetv2' , 'alexnet' , 'densenet121' , 'densenet169' , 'densenet201' , 'densenet161' , 'resnet18' , 'resnet34' , 'resnet50' , 'resnet101' , 'resnet152' , 'inceptionv3' , 'squeezenet1_0' , 'squeezenet1_1' , 'vgg11' , 'vgg11_bn' , 'vgg13' , 'vgg13_bn' , 'vgg16' , 'vgg16_bn' , 'vgg19_bn' , 'vgg19' , 'nasnetalarge' , 'nasnetamobile' , 'cafferesnet101' , 'senet154' , 'se_resnet50' , 'se_resnet101' , 'se_resnet152' , 'se_resnext50_32x4d' , 'se_resnext101_32x4d' , 'cafferesnet101' , 'polynet' , 'pnasnet5large' ] print ( pretrainedmodels . pretrained_settings [ 'nasnetalarge' ])
> { 'imagenet' : { 'url' : 'http://data.lip6.fr/cadene/pretrainedmodels/nasnetalarge-a1897284.pth' , 'input_space' : 'RGB' , 'input_size' : [ 3 , 331 , 331 ], 'input_range' : [ 0 , 1 ], 'mean' : [ 0.5 , 0.5 , 0.5 ], 'std' : [ 0.5 , 0.5 , 0.5 ], 'num_classes' : 1000 }, 'imagenet+background' : { 'url' : 'http://data.lip6.fr/cadene/pretrainedmodels/nasnetalarge-a1897284.pth' , 'input_space' : 'RGB' , 'input_size' : [ 3 , 331 , 331 ], 'input_range' : [ 0 , 1 ], 'mean' : [ 0.5 , 0.5 , 0.5 ], 'std' : [ 0.5 , 0.5 , 0.5 ], 'num_classes' : 1001 }} model_name = 'nasnetalarge' # could be fbresnet152 or inceptionresnetv2
model = pretrainedmodels . __dict__ [ model_name ]( num_classes = 1000 , pretrained = 'imagenet' )
model . eval () 참고 : 기본적으로 모델은 $HOME/.torch 폴더로 다운로드됩니다. $TORCH_HOME 변수를 다음과 같이 사용 하여이 동작을 수정할 수 있습니다. export TORCH_HOME="/local/pretrainedmodels"
import torch
import pretrainedmodels . utils as utils
load_img = utils . LoadImage ()
# transformations depending on the model
# rescale, center crop, normalize, and others (ex: ToBGR, ToRange255)
tf_img = utils . TransformImage ( model )
path_img = 'data/cat.jpg'
input_img = load_img ( path_img )
input_tensor = tf_img ( input_img ) # 3x400x225 -> 3x299x299 size may differ
input_tensor = input_tensor . unsqueeze ( 0 ) # 3x299x299 -> 1x3x299x299
input = torch . autograd . Variable ( input_tensor ,
requires_grad = False )
output_logits = model ( input ) # 1x1000 output_features = model . features ( input ) # 1x14x14x2048 size may differ
output_logits = model . logits ( output_features ) # 1x1000 $ python examples/imagenet_logits.py -h
> nasnetalarge, resnet152, inceptionresnetv2, inceptionv4, ...
$ python examples/imagenet_logits.py -a nasnetalarge --path_img data/cat.jpg
> 'nasnetalarge': data/cat.jpg' is a 'tiger cat'
$ python examples/imagenet_eval.py /local/common-data/imagenet_2012/images -a nasnetalarge -b 20 -e
> * Acc@1 82.693, Acc@5 96.13
결과는 훈련 과정보다 같은 크기의 (중앙 자르기) 이미지를 사용하여 얻었습니다.
| 모델 | 버전 | ACC@1 | ACC@5 |
|---|---|---|---|
| PNASNET-5-LARGE | 텐서 플로 | 82.858 | 96.182 |
| PNASNET-5-LARGE | 우리의 포팅 | 82.736 | 95.992 |
| Nasnet-a-large | 텐서 플로 | 82.693 | 96.163 |
| Nasnet-a-large | 우리의 포팅 | 82.566 | 96.086 |
| SENET154 | 카페 | 81.32 | 95.53 |
| SENET154 | 우리의 포팅 | 81.304 | 95.498 |
| 폴리넷 | 카페 | 81.29 | 95.75 |
| 폴리넷 | 우리의 포팅 | 81.002 | 95.624 |
| inceptionResnetv2 | 텐서 플로 | 80.4 | 95.3 |
| inceptionv4 | 텐서 플로 | 80.2 | 95.3 |
| SE-RESNEXT101_32X4D | 우리의 포팅 | 80.236 | 95.028 |
| SE-RESNEXT101_32X4D | 카페 | 80.19 | 95.04 |
| inceptionResnetv2 | 우리의 포팅 | 80.170 | 95.234 |
| inceptionv4 | 우리의 포팅 | 80.062 | 94.926 |
| DualPathNet107_5K | 우리의 포팅 | 79.746 | 94.684 |
| resnext101_64x4d | 토치 7 | 79.6 | 94.7 |
| DualPathNet131 | 우리의 포팅 | 79.432 | 94.574 |
| DualPathNet92_5K | 우리의 포팅 | 79.400 | 94.620 |
| dualpathnet98 | 우리의 포팅 | 79.224 | 94.488 |
| SE-RESNEXT50_32X4D | 우리의 포팅 | 79.076 | 94.434 |
| SE-RESNEXT50_32X4D | 카페 | 79.03 | 94.46 |
| xception | 케라 | 79.000 | 94.500 |
| resnext101_64x4d | 우리의 포팅 | 78.956 | 94.252 |
| xception | 우리의 포팅 | 78.888 | 94.292 |
| resnext101_32x4d | 토치 7 | 78.8 | 94.4 |
| SE-RESNET152 | 카페 | 78.66 | 94.46 |
| SE-RESNET152 | 우리의 포팅 | 78.658 | 94.374 |
| RESNET152 | Pytorch | 78.428 | 94.110 |
| SE-RESNET101 | 우리의 포팅 | 78.396 | 94.258 |
| SE-RESNET101 | 카페 | 78.25 | 94.28 |
| resnext101_32x4d | 우리의 포팅 | 78.188 | 93.886 |
| FBRESNET152 | 토치 7 | 77.84 | 93.84 |
| SE-RESNET50 | 카페 | 77.63 | 93.64 |
| SE-RESNET50 | 우리의 포팅 | 77.636 | 93.752 |
| Densenet161 | Pytorch | 77.560 | 93.798 |
| RESNET101 | Pytorch | 77.438 | 93.672 |
| FBRESNET152 | 우리의 포팅 | 77.386 | 93.594 |
| inceptionv3 | Pytorch | 77.294 | 93.454 |
| Densenet201 | Pytorch | 77.152 | 93.548 |
| DualPathNet68B_5K | 우리의 포팅 | 77.034 | 93.590 |
| Cafferesnet101 | 카페 | 76.400 | 92.900 |
| Cafferesnet101 | 우리의 포팅 | 76.200 | 92.766 |
| Densenet169 | Pytorch | 76.026 | 92.992 |
| RESNET50 | Pytorch | 76.002 | 92.980 |
| DualPathNet68 | 우리의 포팅 | 75.868 | 92.774 |
| Densenet121 | Pytorch | 74.646 | 92.136 |
| VGG19_BN | Pytorch | 74.266 | 92.066 |
| Nasnet-a-Mobile | 텐서 플로 | 74.0 | 91.6 |
| Nasnet-a-Mobile | 우리의 포팅 | 74.080 | 91.740 |
| RESNET34 | Pytorch | 73.554 | 91.456 |
| Bninception | 우리의 포팅 | 73.524 | 91.562 |
| VGG16_BN | Pytorch | 73.518 | 91.608 |
| vgg19 | Pytorch | 72.080 | 90.822 |
| vgg16 | Pytorch | 71.636 | 90.354 |
| VGG13_BN | Pytorch | 71.508 | 90.494 |
| vgg11_bn | Pytorch | 70.452 | 89.818 |
| RESNET18 | Pytorch | 70.142 | 89.274 |
| vgg13 | Pytorch | 69.662 | 89.264 |
| vgg11 | Pytorch | 68.970 | 88.746 |
| squeezenet1_1 | Pytorch | 58.250 | 80.800 |
| squeezenet1_0 | Pytorch | 58.108 | 80.428 |
| Alexnet | Pytorch | 56.432 | 79.194 |
참고 :
여기에보고 된 정확도가 항상 다른 작업 및 데이터 세트에서 네트워크의 전송 용량을 대표하는 것은 아닙니다. 당신은 그들 모두를 시도해야합니다! :피
Compute ImageNet Validation Metrics를 참조하십시오
출처 : Tensorflow Slim Repo
nasnetalarge(num_classes=1000, pretrained='imagenet')nasnetalarge(num_classes=1001, pretrained='imagenet+background')nasnetamobile(num_classes=1000, pretrained='imagenet') 출처 : Facebook의 Torch7 Repo
Torchvision의 Resnet*과 약간 다릅니다. RESNET152는 현재 유일하게 사용 가능한 유일한 것입니다.
fbresnet152(num_classes=1000, pretrained='imagenet') 출처 : Kaiminghe의 Caffe Repo
cafferesnet101(num_classes=1000, pretrained='imagenet') 출처 : inceptionv3 의 텐서 플로 슬림 리포지토리 및 Pytorch/Vision Repo
inceptionresnetv2(num_classes=1000, pretrained='imagenet')inceptionresnetv2(num_classes=1001, pretrained='imagenet+background')inceptionv4(num_classes=1000, pretrained='imagenet')inceptionv4(num_classes=1001, pretrained='imagenet+background')inceptionv3(num_classes=1000, pretrained='imagenet') 출처 : Xiong Yuanjun에 의해 Caffe와 함께 훈련
bninception(num_classes=1000, pretrained='imagenet') 출처 : Facebook의 Resnext Repo
resnext101_32x4d(num_classes=1000, pretrained='imagenet')resnext101_62x4d(num_classes=1000, pretrained='imagenet') 출처 : Chen Yunpeng의 Mxnet Repo
Ross Wightman은 Pytorch Repo에서 포팅이 가능해졌습니다.
여기에서 볼 수 있듯이 DualPathNetworks를 사용하면 다른 스케일을 시도 할 수 있습니다. 이 repo의 기본값은 0.875이며 원래 입력 크기는 224로 256입니다.
dpn68(num_classes=1000, pretrained='imagenet')dpn98(num_classes=1000, pretrained='imagenet')dpn131(num_classes=1000, pretrained='imagenet')dpn68b(num_classes=1000, pretrained='imagenet+5k')dpn92(num_classes=1000, pretrained='imagenet+5k')dpn107(num_classes=1000, pretrained='imagenet+5k') 'imagenet+5k' 는 imagenet1k에서 미세 조정되기 전에 네트워크가 imagenet5k에서 사전에 사전임을 의미합니다.
출처 : Keras Repo
T Standley는 포팅이 가능해졌습니다.
xception(num_classes=1000, pretrained='imagenet') 출처 : Jie Hu의 Caffe Repo
senet154(num_classes=1000, pretrained='imagenet')se_resnet50(num_classes=1000, pretrained='imagenet')se_resnet101(num_classes=1000, pretrained='imagenet')se_resnet152(num_classes=1000, pretrained='imagenet')se_resnext50_32x4d(num_classes=1000, pretrained='imagenet')se_resnext101_32x4d(num_classes=1000, pretrained='imagenet') 출처 : Tensorflow Slim Repo
pnasnet5large(num_classes=1000, pretrained='imagenet')pnasnet5large(num_classes=1001, pretrained='imagenet+background') 출처 : CUHK 멀티미디어 실험실의 카페 레포
polynet(num_classes=1000, pretrained='imagenet') 출처 : Pytorch/Vision Repo
( inceptionv3 Inception에 포함*)
resnet18(num_classes=1000, pretrained='imagenet')resnet34(num_classes=1000, pretrained='imagenet')resnet50(num_classes=1000, pretrained='imagenet')resnet101(num_classes=1000, pretrained='imagenet')resnet152(num_classes=1000, pretrained='imagenet')densenet121(num_classes=1000, pretrained='imagenet')densenet161(num_classes=1000, pretrained='imagenet')densenet169(num_classes=1000, pretrained='imagenet')densenet201(num_classes=1000, pretrained='imagenet')squeezenet1_0(num_classes=1000, pretrained='imagenet')squeezenet1_1(num_classes=1000, pretrained='imagenet')alexnet(num_classes=1000, pretrained='imagenet')vgg11(num_classes=1000, pretrained='imagenet')vgg13(num_classes=1000, pretrained='imagenet')vgg16(num_classes=1000, pretrained='imagenet')vgg19(num_classes=1000, pretrained='imagenet')vgg11_bn(num_classes=1000, pretrained='imagenet')vgg13_bn(num_classes=1000, pretrained='imagenet')vgg16_bn(num_classes=1000, pretrained='imagenet')vgg19_bn(num_classes=1000, pretrained='imagenet')사전 예방 모델이로드되면 그렇게 사용할 수 있습니다.
중요 참고 : 모든 이미지는 0과 1 사이의 픽셀 값을 스케일링하는 PIL 사용하여로드해야합니다.
model.input_size 3 숫자로 구성된 유형 list 의 속성 :
예:
[3, 299, 299] Inception* 네트워크,[3, 224, 224] RESNET* 네트워크. model.input_space 이미지의 색상 공간을 나타내는 유형 str 의 귀속. RGB 또는 BGR 일 수 있습니다.
model.input_range 2 숫자로 구성된 유형 list 의 속성 :
예:
[0, 1] RESNET* 및 Inception* 네트워크의 경우[0, 255] . model.mean 입력 이미지를 정규화하는 데 사용되는 3 개의 숫자로 구성된 유형 list 의 귀속 ( "색상 채널 용량").
예:
[0.5, 0.5, 0.5] Inception* 네트워크의 경우[0.485, 0.456, 0.406] . model.std 입력 이미지를 정규화하는 데 사용되는 3 개의 숫자로 구성된 유형 list 의 귀속 ( "색상 채널 별"구분).
예:
[0.5, 0.5, 0.5] Inception* 네트워크의 경우[0.229, 0.224, 0.225] . model.features/! 진행중인 작업 (사용할 수 없음)
이미지에서 기능을 추출하는 데 사용되는 메소드.
예제 모델이 fbresnet152 사용하여로드 된 경우 :
print ( input_224 . size ()) # (1,3,224,224)
output = model . features ( input_224 )
print ( output . size ()) # (1,2048,1,1)
# print(input_448.size()) # (1,3,448,448)
output = model . features ( input_448 )
# print(output.size()) # (1,2048,7,7) model.logits/! 진행중인 작업 (사용할 수 없음)
이미지에서 기능을 분류하는 데 사용되는 메소드.
예제 모델이 fbresnet152 사용하여로드 된 경우 :
output = model . features ( input_224 )
print ( output . size ()) # (1,2048, 1, 1)
output = model . logits ( output )
print ( output . size ()) # (1,1000) model.forward model.features 및 model.logits 호출하는 데 사용되는 방법. 원하는대로 덮어 쓸 수 있습니다.
참고 : 모범 사례는 모델에 입력을 전달하기 위해 선택한 기능으로 model.__call__ 사용하는 것입니다. Bellow 예제를 참조하십시오.
# Without model.__call__
output = model . forward ( input_224 )
print ( output . size ()) # (1,1000)
# With model.__call__
output = model ( input_224 )
print ( output . size ()) # (1,1000) model.last_linear nn.Linear 유형의 귀속. 이 모듈은 포워드 패스 중에 마지막으로 호출되는 모듈입니다.
nn.Linear 로 대체 할 수 있습니다.pretrained.utils.Identity 로 대체 할 수 있습니다. 예제 모델이 fbresnet152 사용하여로드 된 경우 :
print ( input_224 . size ()) # (1,3,224,224)
output = model . features ( input_224 )
print ( output . size ()) # (1,2048,1,1)
output = model . logits ( output )
print ( output . size ()) # (1,1000)
# fine tuning
dim_feats = model . last_linear . in_features # =2048
nb_classes = 4
model . last_linear = nn . Linear ( dim_feats , nb_classes )
output = model ( input_224 )
print ( output . size ()) # (1,4)
# features extraction
model . last_linear = pretrained . utils . Identity ()
output = model ( input_224 )
print ( output . size ()) # (1,2048) th pretrainedmodels/fbresnet/resnet152_dump.lua
python pretrainedmodels/fbresnet/resnet152_load.py
https://github.com/clcarwin/convert_torch_to_pytorch
https://github.com/cadene/tensorflow-model-zoo.torch
딥 러닝 커뮤니티, 특히 Pytorch Ecosystem의 기고자들에게 감사합니다.