图像分类模型。克拉斯!
image-classifiers的Python项目详细描述
动物园分类模型
架构:
- VGG[16,19]
- ResNet[18、34、50、101、152]
- ResNeXt[50,101]
- SE-ResNet[18,34,50,101,152]
- SE-ResNeXt[50,101]
- SE-Net[154]
- DenseNet[121169201]
- Inception ResNet V2
- Inception V3
- Xception
- NASNet[大型,移动式]
- MobileNet
- MobileNet v2
规格
TOP-K的准确度是使用 2012 ILSVRC ImageNet验证集,可能与原始验证集不同。 所有型号使用的输入大小为224x224(最小大小256),除了:
- NASNETLARGE 331x331(352)
- 接收v3 299x299(324)
- 接收resnetv2 299x299(324)
- 除外299x299(324)
对500批16号产品进行推断时间评估。 所有型号都使用相同的硬件和软件进行了测试。 列出时间只是为了比较性能。
Model | Acc@1 | Acc@5 | Time* | Source |
---|---|---|---|---|
vgg16 | 70.79 | 89.74 | 24.95 | keras |
vgg19 | 70.89 | 89.69 | 24.95 | keras |
resnet18 | 68.24 | 88.49 | 16.07 | mxnet |
resnet34 | 72.17 | 90.74 | 17.37 | mxnet |
resnet50 | 74.81 | 92.38 | 22.62 | mxnet |
resnet101 | 76.58 | 93.10 | 33.03 | mxnet |
resnet152 | 76.66 | 93.08 | 42.37 | mxnet |
resnet50v2 | 69.73 | 89.31 | 19.56 | keras |
resnet101v2 | 71.93 | 90.41 | 28.80 | keras |
resnet152v2 | 72.29 | 90.61 | 41.09 | keras |
resnext50 | 77.36 | 93.48 | 37.57 | keras |
resnext101 | 78.48 | 94.00 | 60.07 | keras |
densenet121 | 74.67 | 92.04 | 27.66 | keras |
densenet169 | 75.85 | 92.93 | 33.71 | keras |
densenet201 | 77.13 | 93.43 | 42.40 | keras |
inceptionv3 | 77.55 | 93.48 | 38.94 | keras |
xception | 78.87 | 94.20 | 42.18 | keras |
inceptionresnetv2 | 80.03 | 94.89 | 54.77 | keras |
seresnet18 | 69.41 | 88.84 | 20.19 | pytorch |
seresnet34 | 72.60 | 90.91 | 22.20 | pytorch |
seresnet50 | 76.44 | 93.02 | 23.64 | pytorch |
seresnet101 | 77.92 | 94.00 | 32.55 | pytorch |
seresnet152 | 78.34 | 94.08 | 47.88 | pytorch |
seresnext50 | 78.74 | 94.30 | 38.29 | pytorch |
seresnext101 | 79.88 | 94.87 | 62.80 | pytorch |
senet154 | 81.06 | 95.24 | 137.36 | pytorch |
nasnetlarge | 82.12 | 95.72 | 116.53 | keras |
nasnetmobile | 74.04 | 91.54 | 27.73 | keras |
mobilenet | 70.36 | 89.39 | 15.50 | keras |
mobilenetv2 | 71.63 | 90.35 | 18.31 | keras |
注意
[se-]resnext和senet模型使用GroupConvolution
构建
未在keras/tensorflow中实现。对于load_model
函数的正确工作
使用自定义对象。为了能够从文件中加载其中一个模型,请,
之前导入classification_models
。
重量
Name | Classes | Models |
---|---|---|
'imagenet' | 1000 | all models |
'imagenet11k-place365ch' | 11586 | resnet50 |
'imagenet11k' | 11221 | resnet152 |
安装
要求:
- python>;=3.5
- Keras=2.1.0
- 张量流=1.9
注意
This library does not have TensorFlow in a requirements for installation.
Please, choose suitable version (‘cpu’/’gpu’) and install it manually using
official Guide (https://www.tensorflow.org/install/).
PYPI包:
$ pip install image-classifiers
最新版本:
$ pip install git+https://github.com/qubvel/classification_models.git
示例
加载模型,重量:
- 直接方式(如Keras应用程序)
fromclassification_models.resnetimportResNet18,preprocess_inputmodel=ResNet18((224,224,3),weights='imagenet')
- 使用
Classifiers
容器
fromclassification_modelsimportClassifiersclassifier,preprocess_input=Classifiers.get('resnet18')model=classifier((224,224,3),weights='imagenet')
这种方式需要一行额外的代码,但是如果您愿意
喜欢训练一些不需要直接导入的模型,
只要通过Classifiers
访问所有内容。
您可以使用Classifiers.names()
方法获取所有模型名。
推理示例:
importnumpyasnpfromskimage.ioimportimreadfromskimage.transformimportresizefromkeras.applications.imagenet_utilsimportdecode_predictionsfromclassification_models.resnetimportResNet18,preprocess_input# read and prepare imagex=imread('./imgs/tests/seagull.jpg')x=resize(x,(224,224))*255# cast back to 0-255 rangex=preprocess_input(x)x=np.expand_dims(x,0)# load modelmodel=ResNet18(input_shape=(224,224,3),weights='imagenet',classes=1000)# processing imagey=model.predict(x)# resultprint(decode_predictions(y))
型号微调示例:
importkerasfromclassification_models.resnetimportResNet18,preprocess_input# prepare your dataX=...y=...X=preprocess_input(X)n_classes=10# build modelbase_model=ResNet18(input_shape=(224,224,3),weights='imagenet',include_top=False)x=keras.layers.GlobalAveragePooling2D()(base_model.output)output=keras.layers.Dense(n_classes,activation='softmax')(x)model=keras.models.Model(inputs=[base_model.input],outputs=[output])# trainmodel.compile(optimizer='SGD',loss='categorical_crossentropy',metrics=['accuracy'])model.fit(X,y)