Skip to content
GitLab
探索
登录
注册
主导航
搜索或转到…
项目
D
DAGMM
管理
动态
成员
标记
计划
议题
0
议题看板
里程碑
Wiki
代码
合并请求
0
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
构建
流水线
作业
流水线计划
产物
部署
发布
软件包库
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
Contributor analytics
CI/CD 分析
仓库分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
快捷键
?
支持
扫码加入微信群
1. 获取企业级DevOps解决方案
2. 免费或优惠考取极狐GitLab官方培训认证
代码片段
群组
项目
AIOps-NanKai
model
DAGMM
提交
adb67814
未验证
提交
adb67814
编辑于
6年前
作者:
Toshihiro NAKAE
提交者:
GitHub
6年前
浏览文件
操作
下载
差异文件
Merge pull request #6 from tnakae/NormalizeInputData
Implement input data normalization #3
上级
3423318e
18477e53
分支
分支 包含提交
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
dagmm/dagmm.py
+26
-1
26 个添加, 1 个删除
dagmm/dagmm.py
有
26 个添加
和
1 个删除
dagmm/dagmm.py
+
26
−
1
浏览文件 @
adb67814
import
tensorflow
as
tf
import
tensorflow
as
tf
from
sklearn.preprocessing
import
StandardScaler
from
sklearn.externals
import
joblib
from
dagmm.compression_net
import
CompressionNet
from
dagmm.compression_net
import
CompressionNet
from
dagmm.estimation_net
import
EstimationNet
from
dagmm.estimation_net
import
EstimationNet
...
@@ -17,11 +19,13 @@ class DAGMM:
...
@@ -17,11 +19,13 @@ class DAGMM:
"""
"""
MODEL_FILENAME
=
"
DAGMM_model
"
MODEL_FILENAME
=
"
DAGMM_model
"
SCALER_FILENAME
=
"
DAGMM_scaler
"
def
__init__
(
self
,
comp_hiddens
,
comp_activation
,
def
__init__
(
self
,
comp_hiddens
,
comp_activation
,
est_hiddens
,
est_activation
,
est_dropout_ratio
=
0.5
,
est_hiddens
,
est_activation
,
est_dropout_ratio
=
0.5
,
minibatch_size
=
1024
,
epoch_size
=
100
,
minibatch_size
=
1024
,
epoch_size
=
100
,
learning_rate
=
0.0001
,
lambda1
=
0.1
,
lambda2
=
0.005
):
learning_rate
=
0.0001
,
lambda1
=
0.1
,
lambda2
=
0.005
,
normalize
=
True
):
"""
"""
Parameters
Parameters
----------
----------
...
@@ -54,6 +58,9 @@ class DAGMM:
...
@@ -54,6 +58,9 @@ class DAGMM:
lambda2 : float (optional)
lambda2 : float (optional)
a parameter of loss function
a parameter of loss function
(for sum of diagonal elements of covariance)
(for sum of diagonal elements of covariance)
normalize : bool (optional)
specify whether input data need to be normalized.
by default, input data is normalized.
"""
"""
self
.
comp_net
=
CompressionNet
(
comp_hiddens
,
comp_activation
)
self
.
comp_net
=
CompressionNet
(
comp_hiddens
,
comp_activation
)
self
.
est_net
=
EstimationNet
(
est_hiddens
,
est_activation
)
self
.
est_net
=
EstimationNet
(
est_hiddens
,
est_activation
)
...
@@ -68,6 +75,9 @@ class DAGMM:
...
@@ -68,6 +75,9 @@ class DAGMM:
self
.
lambda1
=
lambda1
self
.
lambda1
=
lambda1
self
.
lambda2
=
lambda2
self
.
lambda2
=
lambda2
self
.
normalize
=
normalize
self
.
scaler
=
None
self
.
graph
=
None
self
.
graph
=
None
self
.
sess
=
None
self
.
sess
=
None
...
@@ -85,6 +95,10 @@ class DAGMM:
...
@@ -85,6 +95,10 @@ class DAGMM:
"""
"""
n_samples
,
n_features
=
x
.
shape
n_samples
,
n_features
=
x
.
shape
if
self
.
normalize
:
self
.
scaler
=
scaler
=
StandardScaler
()
x
=
scaler
.
fit_transform
(
x
)
with
tf
.
Graph
().
as_default
()
as
graph
:
with
tf
.
Graph
().
as_default
()
as
graph
:
self
.
graph
=
graph
self
.
graph
=
graph
...
@@ -159,6 +173,9 @@ class DAGMM:
...
@@ -159,6 +173,9 @@ class DAGMM:
if
self
.
sess
is
None
:
if
self
.
sess
is
None
:
raise
Exception
(
"
Trained model does not exist.
"
)
raise
Exception
(
"
Trained model does not exist.
"
)
if
self
.
normalize
:
x
=
self
.
scaler
.
transform
(
x
)
energies
=
self
.
sess
.
run
(
self
.
energy
,
feed_dict
=
{
self
.
input
:
x
})
energies
=
self
.
sess
.
run
(
self
.
energy
,
feed_dict
=
{
self
.
input
:
x
})
return
energies
return
energies
...
@@ -182,6 +199,10 @@ class DAGMM:
...
@@ -182,6 +199,10 @@ class DAGMM:
model_path
=
join
(
fdir
,
self
.
MODEL_FILENAME
)
model_path
=
join
(
fdir
,
self
.
MODEL_FILENAME
)
self
.
saver
.
save
(
self
.
sess
,
model_path
)
self
.
saver
.
save
(
self
.
sess
,
model_path
)
if
self
.
normalize
:
scaler_path
=
join
(
fdir
,
self
.
SCALER_FILENAME
)
joblib
.
dump
(
self
.
scaler
,
scaler_path
)
def
restore
(
self
,
fdir
):
def
restore
(
self
,
fdir
):
"""
Restore trained model from designated directory.
"""
Restore trained model from designated directory.
...
@@ -203,3 +224,7 @@ class DAGMM:
...
@@ -203,3 +224,7 @@ class DAGMM:
self
.
saver
.
restore
(
self
.
sess
,
model_path
)
self
.
saver
.
restore
(
self
.
sess
,
model_path
)
self
.
input
,
self
.
energy
=
tf
.
get_collection
(
"
save
"
)
self
.
input
,
self
.
energy
=
tf
.
get_collection
(
"
save
"
)
if
self
.
normalize
:
scaler_path
=
join
(
fdir
,
self
.
SCALER_FILENAME
)
self
.
scaler
=
joblib
.
load
(
scaler_path
)
This diff is collapsed.
Click to expand it.
预览
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录