提交 6675cf43 编写于 作者: W WuHaobo

polish download pretrain

上级 a39ae69c
# 模型量化 # 模型量化
模型量化是 [PaddleSlim](https://github.com/PaddlePaddle/PaddleSlim) 的特色功能之一,支持动态和静态两种量化训练方式,对权重全局量化和 Channel-Wise 量化,同时以兼容 Paddle Mobile 的格式保存模型。 模型量化是 [PaddleSlim](https://github.com/PaddlePaddle/PaddleSlim) 的特色功能之一,支持动态和静态两种量化训练方式,对权重全局量化和 Channel-Wise 量化,同时以兼容 Paddle-Lite 的格式保存模型。
[PaddleClas](https://github.com/PaddlePaddle/PaddleClas) 使用该量化工具,量化了78.9%的mobilenet_v3_large_x1_0的蒸馏模型, 量化后SD855上预测速度从19.308ms加速到14.395ms,存储大小从21M减小到10M, top1识别准确率75.9%。 [PaddleClas](https://github.com/PaddlePaddle/PaddleClas) 使用该量化工具,量化了78.9%的mobilenet_v3_large_x1_0的蒸馏模型, 量化后SD855上预测速度从19.308ms加速到14.395ms,存储大小从21M减小到10M, top1识别准确率75.9%。
具体的训练方法可以参见 [PaddleSlim 量化训练](https://paddlepaddle.github.io/PaddleSlim/quick_start/quant_aware_tutorial.html) 具体的训练方法可以参见 [PaddleSlim 量化训练](https://paddlepaddle.github.io/PaddleSlim/quick_start/quant_aware_tutorial.html)
...@@ -17,4 +17,4 @@ from . import loss ...@@ -17,4 +17,4 @@ from . import loss
from .architectures import * from .architectures import *
from .loss import * from .loss import *
from .utils import similar_architectures from .utils import *
- ResNet18
- ResNet34
- ResNet50
- ResNet101
- ResNet152
- ResNet50_vc
- ResNet18_vd
- ResNet34_vd
- ResNet50_vd
- ResNet50_vd_v2
- ResNet101_vd
- ResNet152_vd
- ResNet200_vd
- ResNet50_vd_ssld
- MobileNetV3_large_x0_35
- MobileNetV3_large_x0_5
- MobileNetV3_large_x0_75
- MobileNetV3_large_x1_0
- MobileNetV3_large_x1_25
- MobileNetV3_small_x0_35
- MobileNetV3_small_x0_5
- MobileNetV3_small_x0_75
- MobileNetV3_small_x1_0
- MobileNetV3_small_x1_25
- MobileNetV3_large_x1_0_ssld
- MobileNetV3_large_x1_0_ssld_int8
- MobileNetV3_small_x1_0_ssld
- MobileNetV2_x0_25
- MobileNetV2_x0_5
- MobileNetV2_x0_75
- MobileNetV2
- MobileNetV2_x1_5
- MobileNetV2_x2_0
- MobileNetV2_ssld
- MobileNetV1_x0_25
- MobileNetV1_x0_5
- MobileNetV1_x0_75
- MobileNetV1
- MobileNetV1_ssld
- ShuffleNetV2_x0_25
- ShuffleNetV2_x0_33
- ShuffleNetV2_x0_5
- ShuffleNetV2
- ShuffleNetV2_x1_5
- ShuffleNetV2_x2_0
- ShuffleNetV2_swish
- ResNeXt50_32x4d
- ResNeXt50_64x4d
- ResNeXt101_32x4d
- ResNeXt101_64x4d
- ResNeXt152_32x4d
- ResNeXt152_64x4d
- ResNeXt50_vd_32x4d
- ResNeXt50_vd_64x4d
- ResNeXt101_vd_32x4d
- ResNeXt101_vd_64x4d
- ResNeXt152_vd_32x4d
- ResNeXt152_vd_64x4d
- SE_ResNet18_vd
- SE_ResNet34_vd
- SE_ResNet50_vd
- SE_ResNeXt50_32x4d
- SE_ResNeXt101_32x4d
- SE_ResNeXt50_vd_32x4d
- SENet154_vd
- Res2Net50_26w_4s
- Res2Net50_vd_26w_4s
- Res2Net50_14w_8s
- Res2Net101_vd_26w_4s
- Res2Net200_vd_26w_4s
- GoogLeNet
- InceptionV4
- Xception41
- Xception41_deeplab
- Xception65
- Xception65_deeplab
- Xception71
- HRNet_W18_C
- HRNet_W30_C
- HRNet_W32_C
- HRNet_W40_C
- HRNet_W44_C
- HRNet_W48_C
- HRNet_W64_C
- DPN68
- DPN92
- DPN98
- DPN107
- DPN131
- DenseNet121
- DenseNet161
- DenseNet169
- DenseNet201
- DenseNet264
- EfficientNetB0_small
- EfficientNetB0
- EfficientNetB1
- EfficientNetB2
- EfficientNetB3
- EfficientNetB4
- EfficientNetB5
- EfficientNetB6
- EfficientNetB7
- ResNeXt101_32x8d_wsl
- ResNeXt101_32x16d_wsl
- ResNeXt101_32x32d_wsl
- ResNeXt101_32x48d_wsl
- Fix_ResNeXt101_32x48d_wsl
- AlexNet
- SqueezeNet1_0
- SqueezeNet1_1
- VGG11
- VGG13
- VGG16
- VGG19
- DarkNet53
- ResNet50_ACNet_deploy
...@@ -12,10 +12,12 @@ ...@@ -12,10 +12,12 @@
#See the License for the specific language governing permissions and #See the License for the specific language governing permissions and
#limitations under the License. #limitations under the License.
import types
import architectures import architectures
import types
from difflib import SequenceMatcher from difflib import SequenceMatcher
from ppcls.utils.config import get_config
def get_architectures(): def get_architectures():
""" """
...@@ -28,12 +30,18 @@ def get_architectures(): ...@@ -28,12 +30,18 @@ def get_architectures():
return names return names
def similar_architectures(name='', thresh=0.1, topk=10): def get_pretrained():
"""
get all of model pretrained
"""
return get_config('./pretrained.list')
def similar_architectures(name='', names=[], thresh=0.1, topk=10):
""" """
inferred similar architectures inferred similar architectures
""" """
scores = [] scores = []
names = get_architectures()
for idx, n in enumerate(names): for idx, n in enumerate(names):
if n[:2] == '__': continue if n[:2] == '__': continue
score = SequenceMatcher(None, n.lower(), name.lower()).quick_ratio() score = SequenceMatcher(None, n.lower(), name.lower()).quick_ratio()
......
...@@ -20,6 +20,7 @@ import sys ...@@ -20,6 +20,7 @@ import sys
import paddle.fluid as fluid import paddle.fluid as fluid
from ppcls.modeling import get_architectures
from ppcls.modeling import similar_architectures from ppcls.modeling import similar_architectures
from ppcls.utils import logger from ppcls.utils import logger
...@@ -60,7 +61,7 @@ def check_architecture(architecture): ...@@ -60,7 +61,7 @@ def check_architecture(architecture):
""" """
assert isinstance(architecture, str), \ assert isinstance(architecture, str), \
("the type of architecture({}) should be str". format(architecture)) ("the type of architecture({}) should be str". format(architecture))
similar_names = similar_architectures(architecture) similar_names = similar_architectures(architecture, get_architectures())
model_list = ', '.join(similar_names) model_list = ', '.join(similar_names)
err = "{} is not exist! Maybe you want: [{}]" \ err = "{} is not exist! Maybe you want: [{}]" \
"".format(architecture, model_list) "".format(architecture, model_list)
......
...@@ -23,6 +23,8 @@ import tarfile ...@@ -23,6 +23,8 @@ import tarfile
import tqdm import tqdm
import zipfile import zipfile
from ppcls.modeling import get_pretrained
from ppcls.modeling import similar_architectures
from ppcls.utils.check import check_architecture from ppcls.utils.check import check_architecture
from ppcls.utils import logger from ppcls.utils import logger
...@@ -40,6 +42,14 @@ class UrlError(Exception): ...@@ -40,6 +42,14 @@ class UrlError(Exception):
super(UrlError, self).__init__(message) super(UrlError, self).__init__(message)
class ModelNameError(Exception):
""" ModelNameError
"""
def __init__(self, message=''):
super(ModelNameError, self).__init__(message)
class RetryError(Exception): class RetryError(Exception):
""" RetryError """ RetryError
""" """
...@@ -159,19 +169,22 @@ def _decompress(fname): ...@@ -159,19 +169,22 @@ def _decompress(fname):
os.remove(fname) os.remove(fname)
def _check_pretrained_name(architecture):
assert isinstance(architecture, str), \
("the type of architecture({}) should be str". format(architecture))
similar_names = similar_architectures(architecture, get_pretrained())
model_list = ', '.join(similar_names)
err = "{} is not exist! Maybe you want: [{}]" \
"".format(architecture, model_list)
if architecture not in similar_names:
raise ModelNameError(err)
def get(architecture, path, decompress=True): def get(architecture, path, decompress=True):
""" """
Get the pretrained model. Get the pretrained model.
Args:
architecture: the name of which architecture to get.
If the name is not exist, will raises UrlError with error code 404.
path: which dir to save the pretrained model.
decompress: decompress the download or not.
Raises:
RetryError or UrlError if download failed
""" """
_check_pretrained_name(architecture)
url = _get_url(architecture) url = _get_url(architecture)
fname = _download(url, path) fname = _download(url, path)
if decompress: _decompress(fname) if decompress: _decompress(fname)
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
import sys import sys
import argparse import argparse
sys.path.append("../")
from ppcls import model_zoo from ppcls import model_zoo
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册