Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65343084
losses.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 3, 02:38
Size
538 B
Mime Type
text/x-python
Expires
Wed, Jun 5, 02:38 (2 d)
Engine
blob
Format
Raw Data
Handle
18052126
Attached To
R8206 networkTraining
losses.py
View Options
import
torch
from
torch
import
nn
class
CrossEntropyLoss
(
nn
.
Module
):
def
__init__
(
self
,
class_weights
,
ignore_index
=
255
):
super
()
.
__init__
()
self
.
loss
=
nn
.
CrossEntropyLoss
(
weight
=
torch
.
FloatTensor
(
class_weights
),
ignore_index
=
255
,
reduction
=
'none'
)
def
forward
(
self
,
pred
,
target
,
weights
=
None
):
loss
=
self
.
loss
(
pred
,
target
)
if
weights
is
not
None
:
loss
*=
weights
return
loss
.
mean
()
Event Timeline
Log In to Comment