Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
f9d62294
Commit
f9d62294
authored
8 years ago
by
Stefan Wunsch
Committed by
Lorenzo Moneta
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make PyKeras tests more verbose
parent
0bf3201d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tmva/pymva/test/testPyKerasClassification.C
+8
-1
8 additions, 1 deletion
tmva/pymva/test/testPyKerasClassification.C
tmva/pymva/test/testPyKerasRegression.C
+7
-1
7 additions, 1 deletion
tmva/pymva/test/testPyKerasRegression.C
with
15 additions
and
2 deletions
tmva/pymva/test/testPyKerasClassification.C
+
8
−
1
View file @
f9d62294
...
...
@@ -23,12 +23,14 @@ model.save(\"kerasModelClassification.h5\")\n";
int
testPyKerasClassification
(){
// Get data file
std
::
cout
<<
"Get test data..."
<<
std
::
endl
;
TString
fname
=
"./tmva_class_example.root"
;
if
(
gSystem
->
AccessPathName
(
fname
))
// file does not exist in local directory
gSystem
->
Exec
(
"curl -O http://root.cern.ch/files/tmva_class_example.root"
);
TFile
*
input
=
TFile
::
Open
(
fname
);
// Build model from python file
std
::
cout
<<
"Generate keras model..."
<<
std
::
endl
;
UInt_t
ret
;
ret
=
gSystem
->
Exec
(
"echo '"
+
pythonSrc
+
"' > generateKerasModelClassification.py"
);
if
(
ret
!=
0
){
...
...
@@ -42,6 +44,7 @@ int testPyKerasClassification(){
}
// Setup PyMVA and factory
std
::
cout
<<
"Setup TMVA..."
<<
std
::
endl
;
TMVA
::
PyMethodBase
::
PyInitialize
();
TFile
*
outputFile
=
TFile
::
Open
(
"ResultsTestPyKerasClassification.root"
,
"RECREATE"
);
TMVA
::
Factory
*
factory
=
new
TMVA
::
Factory
(
"testPyKerasClassification"
,
outputFile
,
...
...
@@ -66,6 +69,7 @@ int testPyKerasClassification(){
// Book and train method
factory
->
BookMethod
(
dataloader
,
TMVA
::
Types
::
kPyKeras
,
"PyKeras"
,
"!H:!V:VarTransform=D,G:FilenameModel=kerasModelClassification.h5:FilenameTrainedModel=trainedKerasModelClassification.h5:NumEpochs=10:BatchSize=32:SaveBestOnly=false:Verbose=0"
);
std
::
cout
<<
"Train model..."
<<
std
::
endl
;
factory
->
TrainAllMethods
();
// Clean-up
...
...
@@ -74,6 +78,8 @@ int testPyKerasClassification(){
delete
outputFile
;
// Setup reader
UInt_t
numEvents
=
100
;
std
::
cout
<<
"Run reader and classify "
<<
numEvents
<<
" events..."
<<
std
::
endl
;
TMVA
::
Reader
*
reader
=
new
TMVA
::
Reader
(
"!Color:Silent"
);
Float_t
vars
[
4
];
reader
->
AddVariable
(
"var1"
,
vars
+
0
);
...
...
@@ -93,7 +99,6 @@ int testPyKerasClassification(){
background
->
SetBranchAddress
(
"var3"
,
vars
+
2
);
background
->
SetBranchAddress
(
"var4"
,
vars
+
3
);
UInt_t
numEvents
=
100
;
Float_t
meanMvaSignal
=
0
;
Float_t
meanMvaBackground
=
0
;
for
(
UInt_t
i
=
0
;
i
<
numEvents
;
i
++
){
...
...
@@ -106,10 +111,12 @@ int testPyKerasClassification(){
meanMvaBackground
=
meanMvaBackground
/
float
(
numEvents
);
// Check whether the response is obviously better than guessing
std
::
cout
<<
"Mean MVA response on signal: "
<<
meanMvaSignal
<<
std
::
endl
;
if
(
meanMvaSignal
<
0
.
6
){
std
::
cout
<<
"[ERROR] Mean response on signal is "
<<
meanMvaSignal
<<
" (<0.6)"
<<
std
::
endl
;
return
1
;
}
std
::
cout
<<
"Mean MVA response on background: "
<<
meanMvaBackground
<<
std
::
endl
;
if
(
meanMvaBackground
>
0
.
4
){
std
::
cout
<<
"[ERROR] Mean response on background is "
<<
meanMvaBackground
<<
" (>0.4)"
<<
std
::
endl
;
return
1
;
...
...
This diff is collapsed.
Click to expand it.
tmva/pymva/test/testPyKerasRegression.C
+
7
−
1
View file @
f9d62294
...
...
@@ -23,12 +23,14 @@ model.save(\"kerasModelRegression.h5\")\n";
int
testPyKerasRegression
(){
// Get data file
std
::
cout
<<
"Get test data..."
<<
std
::
endl
;
TString
fname
=
"./tmva_reg_example.root"
;
if
(
gSystem
->
AccessPathName
(
fname
))
// file does not exist in local directory
gSystem
->
Exec
(
"curl -O http://root.cern.ch/files/tmva_reg_example.root"
);
TFile
*
input
=
TFile
::
Open
(
fname
);
// Build model from python file
std
::
cout
<<
"Generate keras model..."
<<
std
::
endl
;
UInt_t
ret
;
ret
=
gSystem
->
Exec
(
"echo '"
+
pythonSrc
+
"' > generateKerasModelRegression.py"
);
if
(
ret
!=
0
){
...
...
@@ -42,6 +44,7 @@ int testPyKerasRegression(){
}
// Setup PyMVA and factory
std
::
cout
<<
"Setup TMVA..."
<<
std
::
endl
;
TMVA
::
PyMethodBase
::
PyInitialize
();
TFile
*
outputFile
=
TFile
::
Open
(
"ResultsTestPyKerasRegression.root"
,
"RECREATE"
);
TMVA
::
Factory
*
factory
=
new
TMVA
::
Factory
(
"testPyKerasRegression"
,
outputFile
,
...
...
@@ -63,6 +66,7 @@ int testPyKerasRegression(){
// Book and train method
factory
->
BookMethod
(
dataloader
,
TMVA
::
Types
::
kPyKeras
,
"PyKeras"
,
"!H:!V:VarTransform=D,G:FilenameModel=kerasModelRegression.h5:FilenameTrainedModel=trainedKerasModelRegression.h5:NumEpochs=10:BatchSize=32:SaveBestOnly=false:Verbose=0"
);
std
::
cout
<<
"Train model..."
<<
std
::
endl
;
factory
->
TrainAllMethods
();
// Clean-up
...
...
@@ -71,6 +75,8 @@ int testPyKerasRegression(){
delete
outputFile
;
// Setup reader
UInt_t
numEvents
=
100
;
std
::
cout
<<
"Run reader and estimate target of "
<<
numEvents
<<
" events..."
<<
std
::
endl
;
TMVA
::
Reader
*
reader
=
new
TMVA
::
Reader
(
"!Color:Silent"
);
Float_t
vars
[
3
];
reader
->
AddVariable
(
"var1"
,
vars
+
0
);
...
...
@@ -82,7 +88,6 @@ int testPyKerasRegression(){
tree
->
SetBranchAddress
(
"var2"
,
vars
+
1
);
tree
->
SetBranchAddress
(
"fvalue"
,
vars
+
2
);
UInt_t
numEvents
=
100
;
Float_t
meanMvaError
=
0
;
for
(
UInt_t
i
=
0
;
i
<
numEvents
;
i
++
){
tree
->
GetEntry
(
i
);
...
...
@@ -91,6 +96,7 @@ int testPyKerasRegression(){
meanMvaError
=
meanMvaError
/
float
(
numEvents
);
// Check whether the response is obviously better than guessing
std
::
cout
<<
"Mean squared error: "
<<
meanMvaError
<<
std
::
endl
;
if
(
meanMvaError
>
30
.
0
){
std
::
cout
<<
"[ERROR] Mean squared error is "
<<
meanMvaError
<<
" (>30.0)"
<<
std
::
endl
;
return
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment