From a5db597de5bac718030f6b768bf99759615dbaa0 Mon Sep 17 00:00:00 2001 From: Ting-Jun Wang Date: Mon, 6 Nov 2023 15:52:54 +0800 Subject: [PATCH] feat: REVERIE to R2R format --- adversarial_summary.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 adversarial_summary.py diff --git a/adversarial_summary.py b/adversarial_summary.py new file mode 100644 index 0000000..b52cd8b --- /dev/null +++ b/adversarial_summary.py @@ -0,0 +1,37 @@ +import json +import os + +for file in ['train', 'val_unseen', 'val_seen', 'train_seen', 'test', 'val_train_seen']: + print(file) + if os.path.isfile('data/adversarial/reverie_{}_fnf.json'.format(file)): + with open('data/adversarial/reverie_{}_fnf.json'.format(file)) as fp: + data = json.load(fp) + + + result = {} + for i in data: + instruction_id = i['path_id'] + if instruction_id not in result: + result[instruction_id] = { + 'distance': float(i['distance']), + 'scan': i['scan'], + 'path_id': int(i['path_id']), + 'path': i['path'], + 'heading': float(i['heading']), + 'instructions': [ i['instruction'] ], + 'swap': [ True if i['found'] else False ], + 'id': i['id'], + 'objId': i['objId'] + } + else: + result[instruction_id]['instructions'].append(i['instruction']) + result[instruction_id]['swap'].append( True if i['found'] else False) + + output = [] + for k, item in result.items(): + output.append(item) + else: + output = [] + + with open('data/adversarial/R2R_{}.json'.format(file), 'w') as fp: + json.dump(output, fp)