henry000 commited on
Commit
1ff7fa6
·
1 Parent(s): b5fa3f1

🔒️ [Update] Dataset, can output data without label

Browse files
yolo/tools/data_loader.py CHANGED
@@ -32,8 +32,7 @@ from yolo.utils.dataset_utils import (
32
  class YoloDataset(Dataset):
33
  def __init__(self, config: TrainConfig, phase: str = "train2017", image_size: int = 640):
34
  augment_cfg = config.data.data_augment
35
- # TODO: add yaml -> train: train2017
36
- phase_name = config.dataset.auto_download.get(phase, phase)
37
  self.image_size = image_size
38
 
39
  transforms = [eval(aug)(prob) for aug, prob in augment_cfg.items()]
@@ -102,13 +101,14 @@ class YoloDataset(Dataset):
102
  continue
103
  with open(label_path, "r") as file:
104
  image_seg_annotations = [list(map(float, line.strip().split())) for line in file]
 
 
105
 
106
  labels = self.load_valid_labels(image_id, image_seg_annotations)
107
- if labels is not None:
108
- img_path = path.join(images_path, image_name)
109
- data.append((img_path, labels))
110
- valid_inputs += 1
111
 
 
 
 
112
  logger.info("Recorded {}/{} valid inputs", valid_inputs, len(images_list))
113
  return data
114
 
@@ -135,7 +135,7 @@ class YoloDataset(Dataset):
135
  return torch.stack(bboxes)
136
  else:
137
  logger.warning("No valid BBox in {}", label_path)
138
- return None
139
 
140
  def get_data(self, idx):
141
  img_path, bboxes = self.data[idx]
@@ -161,7 +161,7 @@ class YoloDataLoader(DataLoader):
161
  def __init__(self, config: Config):
162
  """Initializes the YoloDataLoader with hydra-config files."""
163
  data_cfg = config.task.data
164
- dataset = YoloDataset(config.task)
165
 
166
  super().__init__(
167
  dataset,
 
32
  class YoloDataset(Dataset):
33
  def __init__(self, config: TrainConfig, phase: str = "train2017", image_size: int = 640):
34
  augment_cfg = config.data.data_augment
35
+ phase_name = config.dataset.get(phase, phase)
 
36
  self.image_size = image_size
37
 
38
  transforms = [eval(aug)(prob) for aug, prob in augment_cfg.items()]
 
101
  continue
102
  with open(label_path, "r") as file:
103
  image_seg_annotations = [list(map(float, line.strip().split())) for line in file]
104
+ else:
105
+ image_seg_annotations = []
106
 
107
  labels = self.load_valid_labels(image_id, image_seg_annotations)
 
 
 
 
108
 
109
+ img_path = path.join(images_path, image_name)
110
+ data.append((img_path, labels))
111
+ valid_inputs += 1
112
  logger.info("Recorded {}/{} valid inputs", valid_inputs, len(images_list))
113
  return data
114
 
 
135
  return torch.stack(bboxes)
136
  else:
137
  logger.warning("No valid BBox in {}", label_path)
138
+ return torch.zeros((0, 5))
139
 
140
  def get_data(self, idx):
141
  img_path, bboxes = self.data[idx]
 
161
  def __init__(self, config: Config):
162
  """Initializes the YoloDataLoader with hydra-config files."""
163
  data_cfg = config.task.data
164
+ dataset = YoloDataset(config.task, config.task.task)
165
 
166
  super().__init__(
167
  dataset,
yolo/utils/dataset_utils.py CHANGED
@@ -5,6 +5,7 @@ from os import path
5
  from typing import Any, Dict, List, Optional, Tuple
6
 
7
  import numpy as np
 
8
 
9
  from yolo.tools.data_conversion import discretize_categories
10
 
@@ -32,7 +33,8 @@ def locate_label_paths(dataset_path: str, phase_name: str):
32
  if txt_files:
33
  return txt_labels_path, "txt"
34
 
35
- raise FileNotFoundError("No labels found in the specified dataset path and phase name.")
 
36
 
37
 
38
  def create_image_metadata(labels_path: str) -> Tuple[Dict[str, List], Dict[str, Dict]]:
 
5
  from typing import Any, Dict, List, Optional, Tuple
6
 
7
  import numpy as np
8
+ from loguru import logger
9
 
10
  from yolo.tools.data_conversion import discretize_categories
11
 
 
33
  if txt_files:
34
  return txt_labels_path, "txt"
35
 
36
+ logger.warning("No labels found in the specified dataset path and phase name.")
37
+ return [], None
38
 
39
 
40
  def create_image_metadata(labels_path: str) -> Tuple[Dict[str, List], Dict[str, Dict]]: