MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / evaluate

Function evaluate

CV/Pytorch_classification/DenseNet/utils.py:133–149  ·  view source on GitHub ↗
(model, data_loader, device)

Source from the content-addressed store, hash-verified

131
132@torch.no_grad()
133def evaluate(model, data_loader, device):
134 model.eval()
135
136 # 验证样本总个数
137 total_num = len(data_loader.dataset)
138
139 # 用于存储预测正确的样本个数
140 sun_num = torch.zeros(1).to(device)
141
142 data_loader = tqdm(data_loader, file=sys.stdout)
143
144 for step, data in enumerate(data_loader):
145 images, labels = data
146 pred = model(images.to(device))
147 pred = torch.max(pred, dim=1)[1]
148 sum_num += torch.eq(pred, labels.to(device)).sum()
149 return sum_num.item() / total_num

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected