save the jsons per gpu with rank
Browse files- tools/annotate.py +6 -4
tools/annotate.py
CHANGED
|
@@ -105,6 +105,7 @@ def worker(model, processor, dataset, args, output_dir):
|
|
| 105 |
batch_size = 1
|
| 106 |
data_loader = DataLoader(sub_dataset, batch_size=batch_size, shuffle=False, num_workers=0, collate_fn=DataCollatorForSupervisedDataset(processor, args.data_path))
|
| 107 |
labels = []
|
|
|
|
| 108 |
for batch_tensors, result_meta in tqdm(data_loader):
|
| 109 |
|
| 110 |
input_ids = batch_tensors['input_ids'].cuda()
|
|
@@ -139,11 +140,12 @@ def worker(model, processor, dataset, args, output_dir):
|
|
| 139 |
'action_labels': meta['hoi_obj']['action_labels'],
|
| 140 |
'description': output,
|
| 141 |
})
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
output_path =
|
| 146 |
-
|
| 147 |
|
| 148 |
def eval_model(args):
|
| 149 |
torch.distributed.init_process_group(backend='nccl')
|
|
|
|
| 105 |
batch_size = 1
|
| 106 |
data_loader = DataLoader(sub_dataset, batch_size=batch_size, shuffle=False, num_workers=0, collate_fn=DataCollatorForSupervisedDataset(processor, args.data_path))
|
| 107 |
labels = []
|
| 108 |
+
|
| 109 |
for batch_tensors, result_meta in tqdm(data_loader):
|
| 110 |
|
| 111 |
input_ids = batch_tensors['input_ids'].cuda()
|
|
|
|
| 140 |
'action_labels': meta['hoi_obj']['action_labels'],
|
| 141 |
'description': output,
|
| 142 |
})
|
| 143 |
+
|
| 144 |
|
| 145 |
+
local_rank = int(os.environ.get("LOCAL_RANK", "0"))
|
| 146 |
+
output_path = os.path.join(args.output_dir, f'labels_{local_rank}.json')
|
| 147 |
+
with open(output_path, "w", encoding="utf-8") as f:
|
| 148 |
+
json.dump(labels, f, ensure_ascii=False, indent=2)
|
| 149 |
|
| 150 |
def eval_model(args):
|
| 151 |
torch.distributed.init_process_group(backend='nccl')
|