Skip to content

Commit 87ddc84

Browse files
authored
Merge pull request #92 from SunAhong1993/syf
remove download
2 parents 3dd9f89 + be047b5 commit 87ddc84

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

paddlex/interpret/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
from . import visualize
1717

1818
lime = visualize.lime
19-
normlime = visualize.normlime
19+
normlime = visualize.normlime

paddlex/interpret/core/_session_preparation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@ def gen_user_home():
2828
return os.path.expanduser('~')
2929

3030

31-
root_path = gen_user_home()
32-
root_path = osp.join(root_path, '.paddlex')
33-
h_pre_models = osp.join(root_path, "pre_models")
34-
if not osp.exists(h_pre_models):
35-
if not osp.exists(root_path):
36-
os.makedirs(root_path)
37-
url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
38-
pdx.utils.download_and_decompress(url, path=root_path)
39-
h_pre_models_kmeans = osp.join(h_pre_models, "kmeans_model.pkl")
40-
41-
4231
def paddle_get_fc_weights(var_name="fc_0.w_0"):
4332
fc_weights = fluid.global_scope().find_var(var_name).get_tensor()
4433
return np.array(fc_weights)
@@ -50,6 +39,14 @@ def paddle_resize(extracted_features, outsize):
5039

5140

5241
def compute_features_for_kmeans(data_content):
42+
root_path = gen_user_home()
43+
root_path = osp.join(root_path, '.paddlex')
44+
h_pre_models = osp.join(root_path, "pre_models")
45+
if not osp.exists(h_pre_models):
46+
if not osp.exists(root_path):
47+
os.makedirs(root_path)
48+
url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
49+
pdx.utils.download_and_decompress(url, path=root_path)
5350
def conv_bn_layer(input,
5451
num_filters,
5552
filter_size,

paddlex/interpret/core/interpretation_algorithms.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#limitations under the License.
1414

1515
import os
16+
import os.path as osp
1617
import numpy as np
1718
import time
1819

1920
from . import lime_base
20-
from ._session_preparation import paddle_get_fc_weights, compute_features_for_kmeans, h_pre_models_kmeans
21+
from ._session_preparation import paddle_get_fc_weights, compute_features_for_kmeans, gen_user_home
2122
from .normlime_base import combine_normlime_and_lime, get_feature_for_kmeans, load_kmeans_model
2223
from paddlex.interpret.as_data_reader.readers import read_image
2324

@@ -215,6 +216,15 @@ def interpret(self, data_, visualization=True, save_to_disk=True, save_outdir=No
215216
class NormLIME(object):
216217
def __init__(self, predict_fn, label_names, num_samples=3000, batch_size=50,
217218
kmeans_model_for_normlime=None, normlime_weights=None):
219+
root_path = gen_user_home()
220+
root_path = osp.join(root_path, '.paddlex')
221+
h_pre_models = osp.join(root_path, "pre_models")
222+
if not osp.exists(h_pre_models):
223+
if not osp.exists(root_path):
224+
os.makedirs(root_path)
225+
url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
226+
pdx.utils.download_and_decompress(url, path=root_path)
227+
h_pre_models_kmeans = osp.join(h_pre_models, "kmeans_model.pkl")
218228
if kmeans_model_for_normlime is None:
219229
try:
220230
self.kmeans_model = load_kmeans_model(h_pre_models_kmeans)

paddlex/interpret/core/normlime_base.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
#limitations under the License.
1414

1515
import os
16+
import os.path as osp
1617
import numpy as np
1718
import glob
1819

1920
from paddlex.interpret.as_data_reader.readers import read_image
2021
import paddlex.utils.logging as logging
2122
from . import lime_base
22-
from ._session_preparation import compute_features_for_kmeans, h_pre_models_kmeans
23+
from ._session_preparation import compute_features_for_kmeans, gen_user_home
2324

2425

2526
def load_kmeans_model(fname):
@@ -103,6 +104,15 @@ def save_one_lime_predict_and_kmean_labels(lime_all_weights, image_pred_labels,
103104

104105

105106
def precompute_lime_weights(list_data_, predict_fn, num_samples, batch_size, save_dir):
107+
root_path = gen_user_home()
108+
root_path = osp.join(root_path, '.paddlex')
109+
h_pre_models = osp.join(root_path, "pre_models")
110+
if not osp.exists(h_pre_models):
111+
if not osp.exists(root_path):
112+
os.makedirs(root_path)
113+
url = "https://bj.bcebos.com/paddlex/interpret/pre_models.tar.gz"
114+
pdx.utils.download_and_decompress(url, path=root_path)
115+
h_pre_models_kmeans = osp.join(h_pre_models, "kmeans_model.pkl")
106116
kmeans_model = load_kmeans_model(h_pre_models_kmeans)
107117

108118
for data_index, each_data_ in enumerate(list_data_):

0 commit comments

Comments
 (0)