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

Function evaluate

CV/Pytorch_classification/RegNet/utils.py:148–165  ·  view source on GitHub ↗
(model, data_loader, device)

Source from the content-addressed store, hash-verified

146
147@torch.no_grad()
148def evaluate(model, data_loader, device):
149 model.eval()
150
151 # 验证样本总个数
152 total_num = len(data_loader.dataset)
153
154 # 用于存储预测正确的样本个数
155 sum_num = torch.zeros(1).to(device)
156
157 data_loader = tqdm(data_loader, file=sys.stdout)
158
159 for step, data in enumerate(data_loader):
160 images, labels = data
161 pred = model(images.to(device))
162 pred = torch.max(pred, dim=1)[1]
163 sum_num += torch.eq(pred, labels.to(device)).sum()
164
165 return sum_num.item() / total_num

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected