環境搭建
注意:efficientnet這個庫在7月24的時候更新了,keras和tensorflow.keras框架也可以用,
想要學習EfficientNet,如果你要訓練的模型是7月24日之前的,請安裝0.0.4版本。安裝代碼: pip install -U efficientnet==0.0.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
環境:tensorflow > 1.12.0、Keras > 2.2.0 、keras_applications > 1.0.7
安裝方法:參考鏈接
1、從github上安裝(一般不推薦,網太慢)
pip install -U git+https://github.com/qubvel/efficientnet
2、安裝穩定版(-i 後邊是清華提供的鏡像文件,速度飛快)
pip install -U efficientnet -i https://pypi.tuna.tsinghua.edu.cn/simple
3、安裝最新版
pip install -U --pre efficientnet -i https://pypi.tuna.tsinghua.edu.cn/simple
EfficientNet介紹
爲什麼EfficientNet是最好的分類網絡、什麼是EfficientNet?
- https://blog.csdn.net/weixin_37737254/article/details/102920452
- https://blog.csdn.net/h__ang/article/details/92801712
- https://blog.csdn.net/qidailiming1994/article/details/102969501
EfficientNet實例代碼
自己訓練這個網絡有點不切實際,肯定是用遷移學習進行分類任務的。下面先羅列我參考過的一些文章,如果是在tensorflow、keras環境下,則簡稱tf-k環境下。
tf-k環境下:
- https://blog.csdn.net/weixin_43051346/article/details/103757375
- https://blog.csdn.net/weixin_43848469/article/details/104182708
pytorch環境下:
- https://blog.csdn.net/qq_33764934/article/details/103783779
- https://github.com/lukemelas/EfficientNet-PyTorch
本人的代碼案例介紹:
本代碼用來參加了AI研習社舉辦的一個分類競賽,競賽地址https://god.yanxishe.com/26。第一次用EfficientNet效果還不錯,正確率達到95%。
我的代碼運行在kaggle提供的GPU環境下。kaggle每週都會免費提供30個小時的GPU訓練時常,對窮學生來說很實用。
閒話不多說,正式介紹代碼:
因爲efficientnet這個庫在7月24號更新過,更新後tf-k環境下也可以用。如果你要用更新前的版本則需安裝efficientnet==0.0.4版本。並且使用方法也有所不同:
老版本:
#導入
from efficientnet import EfficientNetB0 as Net
#使用
conv_base = Net(weights='imagenet', include_top=False, input_shape=input_shape)
新版本:
#導入
import efficientnet.tfkeras as efn
#使用
base_model = efn.EfficientNetB0(
input_shape=(224,224,3),
wights='imagenet',
include_top=False)
競賽的全部代碼(不需要積分就能下載):https://download.csdn.net/download/jiachang98/12167199