快速上手efficient(keras)

efficient作为一个2019年的新模型,思想就是用一个系数来改变模型深度、宽度与分辨率来提高性能
这篇文章主要讲如何快速应用efficient net,原理可以看原论文
或者
https://blog.csdn.net/BEYONDMA/article/details/91146289
这里我们可以首先直接使用别人的库
github 地址

Requirements
Keras >= 2.2.0 / TensorFlow >= 1.12.0
keras_applications >= 1.0.7
scikit-image

首先安装库

pip install -U efficientnet

注意项目中具有tensorflow1.x与tensorflow2.x的用法
1.x:

import efficientnet.keras as efn 

model = efn.EfficientNetB0(weights='imagenet')

2.x

import efficientnet.tfkeras as efn 

model = efn.EfficientNetB0(weights='imagenet')

载入权重:

import efficientnet.tfkeras
from tensorflow.keras.models import load_model

model = load_model('path/to/model.h5')

这个需要注意,载入模型需要使用使用 tensroflow.keras 中的 load_model, 不能使用 keras 中本身自带的 load_model, 因为许多层网络在不支持使用,笔者就是在这里卡了很久,最后无奈用了 tf2.x 才成功

如果有需要重新训练属于自己的模型与权重,可以使用下列代码

base_model = efn.EfficientNetB0(input_shape=(224,224,3), wights='imagenet',include_top=False)
x = keras.layers.GlobalAveragePooling2D()(base_model.output)

output = keras.layers.Dense(classnumber, activation='softmax')(x)#classnumber 代表类别个数

如果有需要了解模型完整结构的,可以看源码来获取,另外使用不同 efficientnetB 系列时,需要注意图片输入尺寸

efficientnet-b0-224
efficientnet-b1-240
efficientnet-b2-260
efficientnet-b3-300
efficientnet-b4-380
efficientnet-b5-456
efficientnet-b6-528
efficientnet-b7-600

才开始写博客,有写的不好的地方欢迎各位指正交流

参考:
1.EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks
2.github 地址
3.https://blog.csdn.net/qq_38410428/article/details/100094669
4.https://blog.csdn.net/BEYONDMA/article/details/91146289

你可能感兴趣的:(深度学习,实验)