MCPcopy Index your code
hub / github.com/OpenPPL/ppq / eval

Method eval

ppq/samples/QAT/trainer.py:102–132  ·  view source on GitHub ↗

Do Evaluation process on given dataloader. Split your dataset into training and evaluation dataset at first, then use eval function to monitor model performance on evaluation dataset. Here are some options to prevent overfitting, which helps improve the model pe

(self, dataloader: Iterable)

Source from the content-addressed store, hash-verified

100 return pred, loss.item()
101
102 def eval(self, dataloader: Iterable) -> float:
103 """Do Evaluation process on given dataloader.
104
105 Split your dataset into training and evaluation dataset at first, then
106 use eval function to monitor model performance on evaluation dataset.
107
108 Here are some options to prevent overfitting, which helps improve the model performance.
109 1. Train with more data.
110 2. Data augmentation.
111 3. Addition of noise to the input data.
112 """
113 total_pred, total_correct = 0, 0
114 with torch.no_grad():
115 for bidx, batch in enumerate(tqdm(dataloader, desc='Eval: ')):
116 if type(batch) not in {tuple, list}:
117 raise TypeError('Feeding Data is invalid, expect a Tuple or List like [data, label], '
118 f'however {type(batch)} was given. To feed customized data, you have to rewrite '
119 '"eval" function of PPQ Trainer.')
120 if len(batch) != 2:
121 raise ValueError('Unrecognized data format, '
122 'your dataloader should contains batched data like [data, label]')
123 data, label = batch
124 data, label = data.cuda(), label.cuda()
125
126 pred, _ = self.step(data, label, False)
127 pred_label = torch.argmax(pred, dim=-1)
128 total_correct += torch.sum(pred_label == label).item()
129 total_pred += pred_label.numel()
130
131 print(f'Classification Accuracy: {total_correct / total_pred * 100:.3f}%\n')
132 return total_correct / total_pred
133
134 def save(self, file_path: str):
135 """ Save model to given path.

Callers 10

myquantizer.pyFile · 0.80
imagenet.pyFile · 0.80
export_onnxFunction · 0.80
export_onnxFunction · 0.80
load_torch_modelFunction · 0.80
dump_torch_to_onnxFunction · 0.80
test_block.pyFile · 0.80

Calls 1

stepMethod · 0.95

Tested by

no test coverage detected