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

Function evaluate

CV/Pytorch_classification/EfficientNet/utils.py:128–144  ·  view source on GitHub ↗
(model, data_loader, device)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected