MCPcopy Create free account
hub / github.com/GeWu-Lab/AnyTouch2 / evaluate

Function evaluate

train/probe_touchd_engine.py:116–166  ·  view source on GitHub ↗
(data_loader, model, device, args, epoch)

Source from the content-addressed store, hash-verified

114
115@torch.no_grad()
116def evaluate(data_loader, model, device, args, epoch):
117
118 metric_logger = misc.MetricLogger(delimiter=" ")
119 header = 'Test:'
120
121 # switch to evaluation mode
122 model.eval()
123 all_predictions = []
124 all_targets = []
125 all_force_scales = []
126
127 for batch in metric_logger.log_every(data_loader, 40, header):
128
129 images = batch[0].to(device, non_blocking=True)
130 sensors = batch[1].to(device, non_blocking=True).int()
131 target = batch[2].to(device, non_blocking=True)
132 force_scale = batch[3].to(device, non_blocking=True)
133
134 # compute output
135 with torch.amp.autocast('cuda'):
136 output = model(images, sensor_type = sensors)
137
138 all_predictions.append(output.detach())
139 all_targets.append(target.detach())
140 all_force_scales.append(force_scale.detach())
141
142
143 all_predictions = torch.cat(all_predictions, dim=0)
144 all_targets = torch.cat(all_targets, dim=0)
145 all_force_scales = torch.cat(all_force_scales, dim=0)
146
147 all_predictions = all_predictions * all_force_scales
148 all_targets = all_targets * all_force_scales
149
150 forces_rmse_xyz = torch.sqrt(((all_predictions - all_targets) ** 2).mean(dim=0)) * 1000 # in mN
151 total_rmse = forces_rmse_xyz.sum()
152
153 # print(total_rmse.shape, forces_rmse_xyz.shape)
154 metric_logger.update(rmse_x=forces_rmse_xyz[0].item())
155 metric_logger.update(rmse_y=forces_rmse_xyz[1].item())
156 metric_logger.update(rmse_z=forces_rmse_xyz[2].item())
157 metric_logger.update(rmse=total_rmse.item())
158
159 # gather the stats from all processes
160 metric_logger.synchronize_between_processes()
161 # print('* Acc@1 {top1.global_avg:.3f} loss {losses.global_avg:.3f}'
162 # .format(top1=metric_logger.acc1, losses=metric_logger.loss))
163 print("Averaged stats:", metric_logger)
164 plot_correlation(all_targets.cpu().numpy(), all_predictions.cpu().numpy(), args.log_dir, epoch)
165
166 return {k: meter.global_avg for k, meter in metric_logger.meters.items()}

Callers 1

mainFunction · 0.90

Calls 5

log_everyMethod · 0.95
updateMethod · 0.95
printFunction · 0.85
plot_correlationFunction · 0.70

Tested by

no test coverage detected