当前位置:网站首页>Pytoch uses torchnet Classerrormeter in meter
Pytoch uses torchnet Classerrormeter in meter
2022-07-05 12:26:00 【Dongcheng West que】
Use torchnet.meter Medium ClassErrorMeter seek Top-x Score
from torchnet.meter import ClassErrorMeter
# Other omitted
metric = [ClassErrorMeter([1,2], True)] # Calculation top-1 top-2 ACC
take metric Transfer to training class
Call in the training function or verification function metric
if self.metric is not None: # every last epoch Reset , Calculate each epoch The accumulation of acc
self.metric[0].reset()
if self.metric is not None:
prob = F.softmax(outputs, dim=1).data.cpu()
self.metric[0].add(prob, labels.data.cpu()) # Add to metric[0]
Print out
if i == len(self.train_data_loader) - 1 and self.metric is not None:
top1_acc_score = self.metric[0].value()[0]
top2_acc_score = self.metric[0].value()[1]
Accumulating top-1 acc You can also use the following methods
# stay for Define before the loop
presum = 0
for i, (inputs, labels) in enumerate(self.train_data_loader):
#....
prob = F.softmax(outputs, dim=1).data.cpu()
pre=torch.argmax(prob, 1)
a=(pre==labels.data.cpu()).int()
presum+=a.sum().numpy()
acc=100*presum/len(train_datasets)
边栏推荐
- 7月华清学习-1
- 【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
- II. Data type
- Learn memory management of JVM 01 - first memory
- Check the debug port information in rancher and do idea remote JVM debug
- Instance + source code = see through 128 traps
- HiEngine:可媲美本地的云原生内存数据库引擎
- Master-slave mode of redis cluster
- [pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
- Matlab label2idx function (convert the label matrix into a cell array with linear index)
猜你喜欢
Intern position selection and simplified career development planning in Internet companies
ZABBIX customized monitoring disk IO performance
Learn memory management of JVM 01 - first memory
MySQL transaction
Interviewer: is acid fully guaranteed for redis transactions?
Hiengine: comparable to the local cloud native memory database engine
Simple production of wechat applet cloud development authorization login
One article tells the latest and complete learning materials of flutter
什么是数字化存在?数字化转型要先从数字化存在开始
Read and understand the rendering mechanism and principle of flutter's three trees
随机推荐
Embedded software architecture design - message interaction
Tabbar configuration at the bottom of wechat applet
Why do you always fail in automated tests?
Multi table operation - Auto Association query
C language structure is initialized as a function parameter
SENT协议译码的深入探讨
Seven ways to achieve vertical centering
Redis highly available slice cluster
PXE启动配置及原理
Image hyperspectral experiment: srcnn/fsrcnn
How to recover the information server and how to recover the server data [easy to understand]
手机 CPU 架构类型了解
Experimental design - using stack to realize calculator
Check the debug port information in rancher and do idea remote JVM debug
Learn the memory management of JVM 03 - Method area and meta space of JVM
Multi table operation - sub query
MySQL log module of InnoDB engine
MySQL installation, Windows version
MySQL index (1)
Summary of C language learning problems (VS)