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

Function evaluate

CV/Pytorch_classification/ShuffleNet/utils.py:146–163  ·  view source on GitHub ↗
(model, data_loader, device)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected