Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hyunji
/
CapstoneDesign2021-1
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-06-21 19:29:29 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f6bfb095b08c6fbb2711773d633153118aabd79f
f6bfb095
1 parent
3db53916
regression
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
src/models/regression.py
src/models/regression.py
0 → 100644
View file @
f6bfb09
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