Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torchani
Commits
e2bc9f29
Unverified
Commit
e2bc9f29
authored
Jul 30, 2018
by
Gao, Xiang
Committed by
GitHub
Jul 30, 2018
Browse files
add DictMetric (#31)
parent
10699bf7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
18 deletions
+43
-18
tests/test_ignite.py
tests/test_ignite.py
+10
-2
torchani/ignite/__init__.py
torchani/ignite/__init__.py
+2
-2
torchani/ignite/dict_loss.py
torchani/ignite/dict_loss.py
+0
-14
torchani/ignite/loss_metrics.py
torchani/ignite/loss_metrics.py
+31
-0
No files found.
tests/test_ignite.py
View file @
e2bc9f29
...
...
@@ -4,7 +4,9 @@ if sys.version_info.major >= 3:
import
os
import
unittest
import
torch
from
ignite.engine
import
create_supervised_trainer
from
ignite.metrics
import
RootMeanSquaredError
from
ignite.engine
import
create_supervised_trainer
,
\
create_supervised_evaluator
import
torchani
import
torchani.data
...
...
@@ -37,11 +39,17 @@ if sys.version_info.major >= 3:
nnp
=
Flatten
(
nnp
)
batch_nnp
=
torchani
.
models
.
BatchModel
(
nnp
)
container
=
torchani
.
ignite
.
Container
({
'energies'
:
batch_nnp
})
loss
=
torchani
.
ignite
.
DictLoss
es
({
'energies'
:
torch
.
nn
.
MSELoss
()
}
)
loss
=
torchani
.
ignite
.
DictLoss
(
'energies'
,
torch
.
nn
.
MSELoss
())
optimizer
=
torch
.
optim
.
SGD
(
container
.
parameters
(),
lr
=
0.001
,
momentum
=
0.8
)
trainer
=
create_supervised_trainer
(
container
,
optimizer
,
loss
)
trainer
.
run
(
loader
,
max_epochs
=
10
)
metric
=
torchani
.
ignite
.
DictMetric
(
'energies'
,
RootMeanSquaredError
())
evaluator
=
create_supervised_evaluator
(
container
,
metrics
=
{
'RMSE'
:
metric
})
evaluator
.
run
(
loader
)
if
__name__
==
'__main__'
:
unittest
.
main
()
torchani/ignite/__init__.py
View file @
e2bc9f29
from
.container
import
Container
from
.
dict_los
s
import
DictLoss
es
from
.
loss_metric
s
import
DictLoss
,
DictMetric
__all__
=
[
'Container'
,
'DictLoss
es
'
]
__all__
=
[
'Container'
,
'DictLoss
'
,
'DictMetric
'
]
torchani/ignite/dict_loss.py
deleted
100644 → 0
View file @
10699bf7
from
torch.nn.modules.loss
import
_Loss
class
DictLosses
(
_Loss
):
def
__init__
(
self
,
losses
):
super
(
DictLosses
,
self
).
__init__
()
self
.
losses
=
losses
def
forward
(
self
,
input
,
other
):
total
=
0
for
i
in
self
.
losses
:
total
+=
self
.
losses
[
i
](
input
[
i
],
other
[
i
])
return
total
torchani/ignite/loss_metrics.py
0 → 100644
View file @
e2bc9f29
from
torch.nn.modules.loss
import
_Loss
from
ignite.metrics.metric
import
Metric
class
DictLoss
(
_Loss
):
def
__init__
(
self
,
key
,
loss
):
super
(
DictLoss
,
self
).
__init__
()
self
.
key
=
key
self
.
loss
=
loss
def
forward
(
self
,
input
,
other
):
return
self
.
loss
(
input
[
self
.
key
],
other
[
self
.
key
])
class
DictMetric
(
Metric
):
def
__init__
(
self
,
key
,
metric
):
self
.
key
=
key
self
.
metric
=
metric
super
(
DictMetric
,
self
).
__init__
()
def
reset
(
self
):
self
.
metric
.
reset
()
def
update
(
self
,
output
):
y_pred
,
y
=
output
self
.
metric
.
update
((
y_pred
[
self
.
key
],
y
[
self
.
key
]))
def
compute
(
self
):
self
.
metric
.
compute
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment