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
b63f6e40
Unverified
Commit
b63f6e40
authored
Aug 10, 2018
by
Gao, Xiang
Committed by
GitHub
Aug 10, 2018
Browse files
add TransformedLoss to allow adding non-linearity to computed loss (#61)
parent
b16a3234
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
3 deletions
+19
-3
tests/test_ignite.py
tests/test_ignite.py
+4
-1
torchani/ignite/__init__.py
torchani/ignite/__init__.py
+4
-2
torchani/ignite/loss_metrics.py
torchani/ignite/loss_metrics.py
+11
-0
No files found.
tests/test_ignite.py
View file @
b63f6e40
...
@@ -34,8 +34,11 @@ if sys.version_info.major >= 3:
...
@@ -34,8 +34,11 @@ if sys.version_info.major >= 3:
model
=
torch
.
nn
.
Sequential
(
prepare
,
aev_computer
,
nnp
,
Flatten
())
model
=
torch
.
nn
.
Sequential
(
prepare
,
aev_computer
,
nnp
,
Flatten
())
container
=
torchani
.
ignite
.
Container
({
'energies'
:
model
})
container
=
torchani
.
ignite
.
Container
({
'energies'
:
model
})
optimizer
=
torch
.
optim
.
Adam
(
container
.
parameters
())
optimizer
=
torch
.
optim
.
Adam
(
container
.
parameters
())
loss
=
torchani
.
ignite
.
TransformedLoss
(
torchani
.
ignite
.
MSELoss
(
'energies'
),
lambda
x
:
torch
.
exp
(
x
)
-
1
)
trainer
=
create_supervised_trainer
(
trainer
=
create_supervised_trainer
(
container
,
optimizer
,
torchani
.
ignite
.
MSELoss
(
'energies'
)
)
container
,
optimizer
,
loss
)
evaluator
=
create_supervised_evaluator
(
container
,
metrics
=
{
evaluator
=
create_supervised_evaluator
(
container
,
metrics
=
{
'RMSE'
:
torchani
.
ignite
.
RMSEMetric
(
'energies'
)
'RMSE'
:
torchani
.
ignite
.
RMSEMetric
(
'energies'
)
})
})
...
...
torchani/ignite/__init__.py
View file @
b63f6e40
from
.container
import
Container
from
.container
import
Container
from
.loss_metrics
import
DictLoss
,
DictMetric
,
MSELoss
,
RMSEMetric
from
.loss_metrics
import
DictLoss
,
DictMetric
,
MSELoss
,
RMSEMetric
,
\
TransformedLoss
__all__
=
[
'Container'
,
'DictLoss'
,
'DictMetric'
,
'MSELoss'
,
'RMSEMetric'
]
__all__
=
[
'Container'
,
'DictLoss'
,
'DictMetric'
,
'MSELoss'
,
'RMSEMetric'
,
'TransformedLoss'
]
torchani/ignite/loss_metrics.py
View file @
b63f6e40
...
@@ -57,5 +57,16 @@ def MSELoss(key, per_atom=True):
...
@@ -57,5 +57,16 @@ def MSELoss(key, per_atom=True):
return
DictLoss
(
key
,
torch
.
nn
.
MSELoss
())
return
DictLoss
(
key
,
torch
.
nn
.
MSELoss
())
class
TransformedLoss
(
_Loss
):
def
__init__
(
self
,
origin
,
transform
):
super
(
TransformedLoss
,
self
).
__init__
()
self
.
origin
=
origin
self
.
transform
=
transform
def
forward
(
self
,
input
,
other
):
return
self
.
transform
(
self
.
origin
(
input
,
other
))
def
RMSEMetric
(
key
):
def
RMSEMetric
(
key
):
return
DictMetric
(
key
,
RootMeanSquaredError
())
return
DictMetric
(
key
,
RootMeanSquaredError
())
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