| 49 | |
| 50 | |
| 51 | def test(model, loader, num_class=40): |
| 52 | mean_correct = [] |
| 53 | class_acc = np.zeros((num_class, 3)) |
| 54 | classifier = model.eval() |
| 55 | |
| 56 | for j, (points, target) in tqdm(enumerate(loader), total=len(loader)): |
| 57 | |
| 58 | if not args.use_cpu: |
| 59 | points, target = points.cuda(), target.cuda() |
| 60 | |
| 61 | points = points.transpose(2, 1) |
| 62 | pred, _ = classifier(points) |
| 63 | pred_choice = pred.data.max(1)[1] |
| 64 | |
| 65 | for cat in np.unique(target.cpu()): |
| 66 | classacc = pred_choice[target == cat].eq(target[target == cat].long().data).cpu().sum() |
| 67 | class_acc[cat, 0] += classacc.item() / float(points[target == cat].size()[0]) |
| 68 | class_acc[cat, 1] += 1 |
| 69 | |
| 70 | correct = pred_choice.eq(target.long().data).cpu().sum() |
| 71 | mean_correct.append(correct.item() / float(points.size()[0])) |
| 72 | |
| 73 | class_acc[:, 2] = class_acc[:, 0] / class_acc[:, 1] |
| 74 | class_acc = np.mean(class_acc[:, 2]) |
| 75 | instance_acc = np.mean(mean_correct) |
| 76 | |
| 77 | return instance_acc, class_acc |
| 78 | |
| 79 | |
| 80 | def main(args): |