lr, oentu09, eightdecay5e-4
scheduler torchoptilrschedulersteplroptiizer, stepsize5, gaa09
if not ospathexists“logn“:
oskdir“logn“
riter tenrboarduaryriter“logn“
for epoch ranepochnu:
trasuloss 0
trasurrect 0
trasufp 0
trasufn 0
trasutp 0
trasutn 0
for i, data enueratetradataloader:
tra
puts, bels data
puts putsunseeze1totorchfloat32
bels belstypetorchlongtenr
puts, bels putstodevice, belstodevice
outputs puts
loss lossfunutputs, bels
optiizerzerograd
lossbackard
optiizerstep
, pred torchaxoutputsdata, di1
a predeqbelsdatacpu
one torchoneslikebels
zero torchzeroslikebels
tn bels zero pred zerosu
tp bels one pred onesu
fp bels zero pred onesu
fn bels one pred zerosu
trasufn + fnite
trasufp + fpite
trasutn + tnite
trasutp + tpite
trasuloss + lossite
trasurrect + aite
traloss trasuloss 10 lentradataloader
trarrect trasurrect 10 lentradataloader batchsize
traprecision trasutp 10 trasufp + trasutp
trarecall trasutp 10 trasufn + trasutp
riteraddscar“tra loss“, traloss, globalstepepoch
riteraddscar“tra rrect“,
trarrect, globalstepepoch
riteraddscar“tra precision“,
traprecision, globalstepepoch
riteraddscar“tra recall“, trarecall, globalstepepoch
if not ospathexists“odelsaugn“:
oskdir“odelsaugn“
torchsavestatedict, “odelsaugn{}pth“foratepoch + 1
schedulerstep
suloss 0
surrect 0
testsufp 0
testsufn 0
testsutp 0
testsutn 0
for i, data enueratetestdataloader:
eval
puts, bels data
puts putsunseeze1totorchfloat32
bels belstypetorchlongtenr
puts, bels putstodevice, belstodevice
outputs puts
loss lossfunutputs, bels
, pred torchaxoutputsdata, di1
a predeqbelsdatacpu
one torchoneslikebels
zero torchzeroslikebels
tn bels zero pred zerosu
tp bels one pred onesu
fp bels zero pred &nbs
『加入书签,方便阅读』
-->> 本章未完,点击下一页继续阅读(第2页/共3页)