Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122173477
loggerBasic.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
Wed, Jul 16, 08:30
Size
980 B
Mime Type
text/x-python
Expires
Fri, Jul 18, 08:30 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27444477
Attached To
R8206 networkTraining
loggerBasic.py
View Options
import
os
import
torch
class
LoggerBasic
:
def
__init__
(
self
,
log_dir
,
name
,
saveNetEvery
=
500
):
self
.
log_dir
=
log_dir
self
.
log_file
=
os
.
path
.
join
(
self
.
log_dir
,
"log"
+
name
+
".txt"
)
text_file
=
open
(
self
.
log_file
,
"w"
)
text_file
.
close
()
self
.
loss
=
0
self
.
count
=
0
self
.
saveNetEvery
=
saveNetEvery
self
.
epoch
=
0
def
add
(
self
,
l
,
output
,
target
):
self
.
loss
+=
l
self
.
count
+=
1
def
logEpoch
(
self
,
net
):
text_file
=
open
(
self
.
log_file
,
"a"
)
text_file
.
write
(
str
(
self
.
loss
/
self
.
count
))
text_file
.
write
(
'
\n
'
)
text_file
.
close
()
lastLoss
=
self
.
loss
self
.
loss
=
0
self
.
count
=
0
self
.
epoch
+=
1
if
self
.
epoch
%
self
.
saveNetEvery
==
0
:
torch
.
save
({
'epoch'
:
self
.
epoch
,
'state_dict'
:
net
.
state_dict
()},
os
.
path
.
join
(
self
.
log_dir
,
'net_last.pth'
))
return
lastLoss
Event Timeline
Log In to Comment