Ver Fonte

Merge pull request #7 from PaddlePaddle/develop

00
SunAhong1993 há 5 anos atrás
pai
commit
4d6efec9b6

+ 7 - 2
docs/update.md

@@ -1,9 +1,14 @@
 # 更新日志
 
+- 2020.05.20
+> - 发布正式版 v1.0
+> - 增加模型C++部署和Python部署代码
+> - 增加模型加密部署方案
+> - 增加分类模型的OpenVINO部署方案
+> - 增加模型可解释性的接口
+
 - 2020.05.17
 > - 发布v0.1.8 pip更新
 > - 修复部分代码Bug
 > - 新增EasyData平台数据标注格式支持
 > - 支持imgaug数据增强库的pixel-level算子
-
-

+ 1 - 1
paddlex/__init__.py

@@ -53,4 +53,4 @@ log_level = 2
 
 from . import interpret
 
-__version__ = '1.0.1.github'
+__version__ = '1.0.2.github'

+ 3 - 3
paddlex/cv/transforms/cls_transforms.py

@@ -259,8 +259,8 @@ class ResizeByShort(ClsTransform):
         im_short_size = min(im.shape[0], im.shape[1])
         im_long_size = max(im.shape[0], im.shape[1])
         scale = float(self.short_size) / im_short_size
-        if self.max_size > 0 and np.round(
-                scale * im_long_size) > self.max_size:
+        if self.max_size > 0 and np.round(scale *
+                                          im_long_size) > self.max_size:
             scale = float(self.max_size) / float(im_long_size)
         resized_width = int(round(im.shape[1] * scale))
         resized_height = int(round(im.shape[0] * scale))
@@ -455,7 +455,7 @@ class ArrangeClassifier(ClsTransform):
             tuple: 当mode为'train'或'eval'时,返回(im, label),分别对应图像np.ndarray数据、
                 图像类别id;当mode为'test'或'quant'时,返回(im, ),对应图像np.ndarray数据。
         """
-        im = permute(im, False)
+        im = permute(im, False).astype('float32')
         if self.mode == 'train' or self.mode == 'eval':
             outputs = (im, label)
         else:

+ 1 - 1
paddlex/interpret/__init__.py

@@ -16,4 +16,4 @@ from __future__ import absolute_import
 from . import visualize
 
 lime = visualize.lime
-normlime = visualize.normlime
+normlime = visualize.normlime

+ 8 - 11
paddlex/interpret/core/_session_preparation.py

@@ -28,17 +28,6 @@ def gen_user_home():
     return os.path.expanduser('~')
 
 
-root_path = gen_user_home()
-root_path = osp.join(root_path, '.paddlex')
-h_pre_models = osp.join(root_path, "pre_models")
-if not osp.exists(h_pre_models):
-    if not osp.exists(root_path):
-        os.makedirs(root_path)
-    url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
-    pdx.utils.download_and_decompress(url, path=root_path)
-h_pre_models_kmeans = osp.join(h_pre_models, "kmeans_model.pkl")
-
-
 def paddle_get_fc_weights(var_name="fc_0.w_0"):
     fc_weights = fluid.global_scope().find_var(var_name).get_tensor()
     return np.array(fc_weights)
@@ -50,6 +39,14 @@ def paddle_resize(extracted_features, outsize):
 
 
 def compute_features_for_kmeans(data_content):
+    root_path = gen_user_home()
+    root_path = osp.join(root_path, '.paddlex')
+    h_pre_models = osp.join(root_path, "pre_models")
+    if not osp.exists(h_pre_models):
+        if not osp.exists(root_path):
+            os.makedirs(root_path)
+        url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
+        pdx.utils.download_and_decompress(url, path=root_path)
     def conv_bn_layer(input,
                       num_filters,
                       filter_size,

+ 11 - 1
paddlex/interpret/core/interpretation_algorithms.py

@@ -13,11 +13,12 @@
 #limitations under the License.
 
 import os
+import os.path as osp
 import numpy as np
 import time
 
 from . import lime_base
-from ._session_preparation import paddle_get_fc_weights, compute_features_for_kmeans, h_pre_models_kmeans
+from ._session_preparation import paddle_get_fc_weights, compute_features_for_kmeans, gen_user_home
 from .normlime_base import combine_normlime_and_lime, get_feature_for_kmeans, load_kmeans_model
 from paddlex.interpret.as_data_reader.readers import read_image
 
@@ -215,6 +216,15 @@ class LIME(object):
 class NormLIME(object):
     def __init__(self, predict_fn, label_names, num_samples=3000, batch_size=50,
                  kmeans_model_for_normlime=None, normlime_weights=None):
+        root_path = gen_user_home()
+        root_path = osp.join(root_path, '.paddlex')
+        h_pre_models = osp.join(root_path, "pre_models")
+        if not osp.exists(h_pre_models):
+            if not osp.exists(root_path):
+                os.makedirs(root_path)
+            url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
+            pdx.utils.download_and_decompress(url, path=root_path)
+        h_pre_models_kmeans = osp.join(h_pre_models, "kmeans_model.pkl")
         if kmeans_model_for_normlime is None:
             try:
                 self.kmeans_model = load_kmeans_model(h_pre_models_kmeans)

+ 11 - 1
paddlex/interpret/core/normlime_base.py

@@ -13,13 +13,14 @@
 #limitations under the License.
 
 import os
+import os.path as osp
 import numpy as np
 import glob
 
 from paddlex.interpret.as_data_reader.readers import read_image
 import paddlex.utils.logging as logging
 from . import lime_base
-from ._session_preparation import compute_features_for_kmeans, h_pre_models_kmeans
+from ._session_preparation import compute_features_for_kmeans, gen_user_home
 
 
 def load_kmeans_model(fname):
@@ -103,6 +104,15 @@ def save_one_lime_predict_and_kmean_labels(lime_all_weights, image_pred_labels,
 
 
 def precompute_lime_weights(list_data_, predict_fn, num_samples, batch_size, save_dir):
+    root_path = gen_user_home()
+    root_path = osp.join(root_path, '.paddlex')
+    h_pre_models = osp.join(root_path, "pre_models")
+    if not osp.exists(h_pre_models):
+        if not osp.exists(root_path):
+            os.makedirs(root_path)
+        url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
+        pdx.utils.download_and_decompress(url, path=root_path)
+    h_pre_models_kmeans = osp.join(h_pre_models, "kmeans_model.pkl")
     kmeans_model = load_kmeans_model(h_pre_models_kmeans)
 
     for data_index, each_data_ in enumerate(list_data_):

+ 1 - 1
setup.py

@@ -19,7 +19,7 @@ long_description = "PaddleX. A end-to-end deeplearning model development toolkit
 
 setuptools.setup(
     name="paddlex",
-    version='1.0.1',
+    version='1.0.2',
     author="paddlex",
     author_email="paddlex@baidu.com",
     description=long_description,