Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Fix evaluate.py (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepnmenon authored Jun 2, 2023
1 parent 69750e9 commit f30f0da
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@


def main() -> None:
dist.init()

torch.backends.cudnn.benchmark = True
torch.cuda.set_device(dist.local_rank())

parser = argparse.ArgumentParser()
parser.add_argument('config', metavar='FILE', help='config file')
parser.add_argument('--run-dir', metavar='DIR', help='run directory')
Expand All @@ -34,6 +29,12 @@ def main() -> None:
configs.load(args.config, recursive=True)
configs.update(opts)

if configs.distributed:
dist.init()

torch.backends.cudnn.benchmark = True
torch.cuda.set_device(dist.local_rank())

if args.run_dir is None:
args.run_dir = auto_set_run_dir()
else:
Expand Down Expand Up @@ -67,10 +68,11 @@ def main() -> None:
else:
raise NotImplementedError

model = torch.nn.parallel.DistributedDataParallel(
model.cuda(),
device_ids=[dist.local_rank()],
find_unused_parameters=True)
if configs.distributed:
model = torch.nn.parallel.DistributedDataParallel(
model.cuda(),
device_ids=[dist.local_rank()],
find_unused_parameters=True)
model.eval()

criterion = builder.make_criterion()
Expand All @@ -95,35 +97,35 @@ def main() -> None:
trainer.before_epoch()

model.eval()

for feed_dict in tqdm(dataflow['test'], desc='eval'):
_inputs = {}
for key, value in feed_dict.items():
if 'name' not in key:
_inputs[key] = value.cuda()

inputs = _inputs['lidar']
targets = feed_dict['targets'].F.long().cuda(non_blocking=True)
outputs = model(inputs)

invs = feed_dict['inverse_map']
all_labels = feed_dict['targets_mapped']
_outputs = []
_targets = []
for idx in range(invs.C[:, -1].max() + 1):
cur_scene_pts = (inputs.C[:, -1] == idx).cpu().numpy()
cur_inv = invs.F[invs.C[:, -1] == idx].cpu().numpy()
cur_label = (all_labels.C[:, -1] == idx).cpu().numpy()
outputs_mapped = outputs[cur_scene_pts][cur_inv].argmax(1)
targets_mapped = all_labels.F[cur_label]
_outputs.append(outputs_mapped)
_targets.append(targets_mapped)
outputs = torch.cat(_outputs, 0)
targets = torch.cat(_targets, 0)
output_dict = {'outputs': outputs, 'targets': targets}
trainer.after_step(output_dict)

trainer.after_epoch()
with torch.no_grad():
for feed_dict in tqdm(dataflow['test'], desc='eval'):
_inputs = {}
for key, value in feed_dict.items():
if 'name' not in key:
_inputs[key] = value.cuda()

inputs = _inputs['lidar']
targets = feed_dict['targets'].F.long().cuda(non_blocking=True)
outputs = model(inputs)

invs = feed_dict['inverse_map']
all_labels = feed_dict['targets_mapped']
_outputs = []
_targets = []
for idx in range(invs.C[:, -1].max() + 1):
cur_scene_pts = (inputs.C[:, -1] == idx).cpu().numpy()
cur_inv = invs.F[invs.C[:, -1] == idx].cpu().numpy()
cur_label = (all_labels.C[:, -1] == idx).cpu().numpy()
outputs_mapped = outputs[cur_scene_pts][cur_inv].argmax(1)
targets_mapped = all_labels.F[cur_label]
_outputs.append(outputs_mapped)
_targets.append(targets_mapped)
outputs = torch.cat(_outputs, 0)
targets = torch.cat(_targets, 0)
output_dict = {'outputs': outputs, 'targets': targets}
trainer.after_step(output_dict)

trainer.after_epoch()


if __name__ == '__main__':
Expand Down

0 comments on commit f30f0da

Please sign in to comment.