henry000 commited on
Commit
3fa2be7
·
1 Parent(s): 73207bd

⚡️ [Update] Dataloader, run faster!

Browse files
Files changed (1) hide show
  1. yolo/utils/dataloader.py +9 -7
yolo/utils/dataloader.py CHANGED
@@ -178,13 +178,15 @@ class YoloDataLoader(DataLoader):
178
  - A tensor of batched images.
179
  - A list of tensors, each corresponding to bboxes for each image in the batch.
180
  """
181
- batch_size, target_size = len(batch), [item[1].size(0) for item in batch]
182
- batch_targets = torch.zeros(batch_size, max(target_size), 5)
183
- images = []
184
- for idx, (image, target) in enumerate(batch):
185
- images.append(image)
186
- batch_targets[idx, : target_size[idx]] = target
187
- batch_images = torch.stack(images)
 
 
188
  return batch_images, batch_targets
189
 
190
 
 
178
  - A tensor of batched images.
179
  - A list of tensors, each corresponding to bboxes for each image in the batch.
180
  """
181
+ batch_size = len(batch)
182
+ target_sizes = [item[1].size(0) for item in batch]
183
+ # TODO: Improve readability of these proccess
184
+ batch_targets = torch.zeros(batch_size, max(target_sizes), 5)
185
+ for idx, target_size in enumerate(target_sizes):
186
+ batch_targets[idx, :target_size] = batch[idx][1]
187
+
188
+ batch_images = torch.stack([item[0] for item in batch])
189
+
190
  return batch_images, batch_targets
191
 
192