图像分类模型。克拉斯!

image-classifiers的Python项目详细描述


PyPI versionBuild Status

动物园分类模型

学习ImageNet分类模型。Keras

架构:

规格

TOP-K的准确度是使用 2012 ILSVRC ImageNet验证集,可能与原始验证集不同。 所有型号使用的输入大小为224x224(最小大小256),除了:

  • NASNETLARGE 331x331(352)
  • 接收v3 299x299(324)
  • 接收resnetv2 299x299(324)
  • 除外299x299(324)

对500批16号产品进行推断时间评估。 所有型号都使用相同的硬件和软件进行了测试。 列出时间只是为了比较性能。

ModelAcc@1Acc@5Time*Source
vgg1670.7989.7424.95keras
vgg1970.8989.6924.95keras
resnet1868.2488.4916.07mxnet
resnet3472.1790.7417.37mxnet
resnet5074.8192.3822.62mxnet
resnet10176.5893.1033.03mxnet
resnet15276.6693.0842.37mxnet
resnet50v269.7389.3119.56keras
resnet101v271.9390.4128.80keras
resnet152v272.2990.6141.09keras
resnext5077.3693.4837.57keras
resnext10178.4894.0060.07keras
densenet12174.6792.0427.66keras
densenet16975.8592.9333.71keras
densenet20177.1393.4342.40keras
inceptionv377.5593.4838.94keras
xception78.8794.2042.18keras
inceptionresnetv280.0394.8954.77keras
seresnet1869.4188.8420.19pytorch
seresnet3472.6090.9122.20pytorch
seresnet5076.4493.0223.64pytorch
seresnet10177.9294.0032.55pytorch
seresnet15278.3494.0847.88pytorch
seresnext5078.7494.3038.29pytorch
seresnext10179.8894.8762.80pytorch
senet15481.0695.24137.36pytorch
nasnetlarge82.1295.72116.53keras
nasnetmobile74.0491.5427.73keras
mobilenet70.3689.3915.50keras
mobilenetv271.6390.3518.31keras
注意

[se-]resnext和senet模型使用GroupConvolution构建 未在keras/tensorflow中实现。对于load_model函数的正确工作 使用自定义对象。为了能够从文件中加载其中一个模型,请, 之前导入classification_models

重量

NameClassesModels
'imagenet'1000all models
'imagenet11k-place365ch'11586resnet50
'imagenet11k'11221resnet152

安装

要求:

  • 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

示例

加载模型,重量:
  1. 直接方式(如Keras应用程序)
fromclassification_models.resnetimportResNet18,preprocess_inputmodel=ResNet18((224,224,3),weights='imagenet')
  1. 使用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)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java文件分块,获取长度字节   java嵌入式Tomcat不执行jsf页面   java我的数据库中有2个实体,但hibernate返回其中6个。   java如何基于逗号拆分字符串   java取消已经运行的CompletableFutures的预期模式是什么   java如何在informix中从另一个数据库复制表ddl和数据   为什么图片是黑色的?   java根据字符串数组中的单词筛选列表   Java8的集合。平行流有效吗?   Kotlin中的java静态内部类   java如何在GUI中生成一列字符串   javafx如何正确使用高对比度主题?   带空格的javascript Httpurlconnection参数   java如何设置GridBagLayout的约束   java如何在一个线程可能尚未初始化时关闭另一个线程   java将简单时间格式转换为特殊时间格式(hhmmt)   安卓/java阵列重复过滤器的问题   java在队列的链接实现下,入队和出队是如何工作的   java更新sql外键约束