Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hyunji
/
A-Performance-Evaluation-of-CNN-for-Brain-Age-Prediction-Using-Structural-MRI-Data
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Hyunji
2021-12-20 04:27:23 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
658dd6d796b83228259c76fd2bf6c5e0af44076f
658dd6d7
1 parent
bd5cf299
regression
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
2DCNN/src/models/regression.py
2DCNN/src/models/regression.py
0 → 100644
View file @
658dd6d
import
torch
from
lib.base_model
import
Base
as
BaseModel
class
Regression
(
BaseModel
):
def
__init__
(
self
,
net
):
super
()
.
__init__
()
self
.
net
=
net
def
forward
(
self
,
batch
):
return
self
.
net
(
batch
[
0
]
.
to
(
self
.
device
))
def
loss
(
self
,
pred
,
batch
,
reduce
=
True
):
ret_obj
=
{}
y
=
batch
[
1
]
.
to
(
self
.
device
)
.
float
()
N
=
y
.
shape
[
0
]
y
=
y
.
reshape
(
N
,
-
1
)
y_pred
=
pred
.
y_pred
.
reshape
(
N
,
-
1
)
loss
=
torch
.
nn
.
functional
.
mse_loss
(
y_pred
,
y
,
reduction
=
"none"
)
.
sum
(
dim
=
1
)
mae
=
torch
.
abs
(
y_pred
-
y
)
.
sum
(
dim
=
1
)
if
reduce
:
#print(sum(y[0])/len(y[[0]]))
#print(sum(y_pred[0])/len(y_pred[0]))
#print(sum((y_pred/y)[0])/len((y_pred/y)[0]))
mae
=
mae
.
mean
()
loss
=
loss
.
mean
()
return
loss
,
{
"mse"
:
loss
,
"mae"
:
mae
}
Please
register
or
login
to post a comment