Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
baa0036f
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
baa0036f
编写于
5月 19, 2020
作者:
S
sunyanfang01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move sklearn
上级
441634a1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
12 deletion
+20
-12
paddlex/interpret/core/interpretation_algorithms.py
paddlex/interpret/core/interpretation_algorithms.py
+7
-1
paddlex/interpret/core/lime_base.py
paddlex/interpret/core/lime_base.py
+9
-8
paddlex/interpret/core/normlime_base.py
paddlex/interpret/core/normlime_base.py
+4
-3
未找到文件。
paddlex/interpret/core/interpretation_algorithms.py
浏览文件 @
baa0036f
...
...
@@ -242,7 +242,13 @@ class NormLIME(object):
self
.
label_names
=
label_names
def
predict_cluster_labels
(
self
,
feature_map
,
segments
):
return
self
.
kmeans_model
.
predict
(
get_feature_for_kmeans
(
feature_map
,
segments
))
X
=
get_feature_for_kmeans
(
feature_map
,
segments
)
try
:
cluster_labels
=
self
.
kmeans_model
.
predict
(
X
)
except
AttributeError
:
from
sklearn.metrics
import
pairwise_distances_argmin_min
cluster_labels
,
_
=
pairwise_distances_argmin_min
(
X
,
self
.
kmeans_model
.
cluster_centers_
)
return
cluster_labels
def
predict_using_normlime_weights
(
self
,
pred_labels
,
predicted_cluster_labels
):
# global weights
...
...
paddlex/interpret/core/lime_base.py
浏览文件 @
baa0036f
...
...
@@ -30,17 +30,10 @@ The code in this file (lime_base.py) is modified from https://github.com/marcotc
import
numpy
as
np
import
scipy
as
sp
import
sklearn
import
sklearn.preprocessing
from
skimage.color
import
gray2rgb
from
sklearn.linear_model
import
Ridge
,
lars_path
from
sklearn.utils
import
check_random_state
import
tqdm
import
copy
from
functools
import
partial
from
skimage.segmentation
import
quickshift
from
skimage.measure
import
regionprops
class
LimeBase
(
object
):
...
...
@@ -59,6 +52,7 @@ class LimeBase(object):
generate random numbers. If None, the random state will be
initialized using the internal numpy seed.
"""
from
sklearn.utils
import
check_random_state
self
.
kernel_fn
=
kernel_fn
self
.
verbose
=
verbose
self
.
random_state
=
check_random_state
(
random_state
)
...
...
@@ -75,6 +69,7 @@ class LimeBase(object):
(alphas, coefs), both are arrays corresponding to the
regularization parameter and coefficients, respectively
"""
from
sklearn.linear_model
import
lars_path
x_vector
=
weighted_data
alphas
,
_
,
coefs
=
lars_path
(
x_vector
,
weighted_labels
,
...
...
@@ -106,6 +101,7 @@ class LimeBase(object):
def
feature_selection
(
self
,
data
,
labels
,
weights
,
num_features
,
method
):
"""Selects features for the model. see interpret_instance_with_data to
understand the parameters."""
from
sklearn.linear_model
import
Ridge
if
method
==
'none'
:
return
np
.
array
(
range
(
data
.
shape
[
1
]))
elif
method
==
'forward_selection'
:
...
...
@@ -213,7 +209,7 @@ class LimeBase(object):
score is the R^2 value of the returned interpretation
local_pred is the prediction of the interpretation model on the original instance
"""
from
sklearn.linear_model
import
Ridge
weights
=
self
.
kernel_fn
(
distances
)
labels_column
=
neighborhood_labels
[:,
label
]
used_features
=
self
.
feature_selection
(
neighborhood_data
,
...
...
@@ -376,6 +372,7 @@ class LimeImageInterpreter(object):
generate random numbers. If None, the random state will be
initialized using the internal numpy seed.
"""
from
sklearn.utils
import
check_random_state
kernel_width
=
float
(
kernel_width
)
if
kernel
is
None
:
...
...
@@ -422,6 +419,10 @@ class LimeImageInterpreter(object):
An ImageIinterpretation object (see lime_image.py) with the corresponding
interpretations.
"""
import
sklearn
from
skimage.measure
import
regionprops
from
skimage.segmentation
import
quickshift
from
skimage.color
import
gray2rgb
if
len
(
image
.
shape
)
==
2
:
image
=
gray2rgb
(
image
)
...
...
paddlex/interpret/core/normlime_base.py
浏览文件 @
baa0036f
...
...
@@ -17,6 +17,7 @@ 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
...
...
@@ -113,11 +114,11 @@ def precompute_lime_weights(list_data_, predict_fn, num_samples, batch_size, sav
save_path
=
os
.
path
.
join
(
save_dir
,
save_path
)
if
os
.
path
.
exists
(
save_path
):
print
(
f
'
{
save_path
}
exists, not computing this one.'
)
logging
.
info
(
save_path
+
' exists, not computing this one.'
,
use_color
=
True
)
continue
print
(
'processing'
,
each_data_
if
isinstance
(
each_data_
,
str
)
else
data_index
,
f
'
,
{
data_index
}
/
{
len
(
list_data_
)
}
'
)
logging
.
info
(
'processing'
+
each_data_
if
isinstance
(
each_data_
,
str
)
else
data_index
+
\
f
'
+
{
data_index
}
/
{
len
(
list_data_
)
}
'
,
use_color
=
True
)
image_show
=
read_image
(
each_data_
)
result
=
predict_fn
(
image_show
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录