Skip to content

Commit

Permalink
Save label files for tiles without annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Pierce committed Jan 6, 2025
1 parent 899b46d commit d4b8c5d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions yolo_tiler/yolo_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,11 @@ def _save_tile_labels(self, labels: Optional[List], image_path: Path, suffix: st
suffix: Suffix for the tile filename
folder: Subfolder name (train, valid, test)
"""
if labels:
# Save the labels in the appropriate directory
label_path = self.target / folder / "labels" / image_path.name.replace(self.config.ext, suffix)
label_path = label_path.with_suffix('.txt')
is_segmentation = self.config.annotation_type == "instance_segmentation"
self._save_labels(labels, label_path, is_segmentation)
# Save the labels in the appropriate directory
label_path = self.target / folder / "labels" / image_path.name.replace(self.config.ext, suffix)
label_path = label_path.with_suffix('.txt')
is_segmentation = self.config.annotation_type == "instance_segmentation"
self._save_labels(labels, label_path, is_segmentation)

def _save_tile(self,
tile_data: np.ndarray,
Expand Down Expand Up @@ -575,7 +574,7 @@ def split_data(self) -> None:

if self.callback:
progress = TileProgress(
current_tile=tile_idx+1,
current_tile=tile_idx + 1,
total_tiles=num_valid,
current_set='valid',
current_image=image_path.name
Expand All @@ -587,7 +586,7 @@ def split_data(self) -> None:
self._move_split_data(image_path, label_path, 'test')
if self.callback:
progress = TileProgress(
current_tile=tile_idx+1,
current_tile=tile_idx + 1,
total_tiles=num_test,
current_set='test',
current_image=image_path.name
Expand Down Expand Up @@ -685,14 +684,14 @@ def visualize_random_samples(self) -> None:

if self.callback:
progress = TileProgress(
current_tile=tile_idx+1,
current_tile=tile_idx + 1,
total_tiles=num_samples,
current_set='rendered',
current_image=image_path.name
)
self.callback(progress)

self._render_single_sample(image_path, label_path, tile_idx+1)
self._render_single_sample(image_path, label_path, tile_idx + 1)

def _render_single_sample(self, image_path: Path, label_path: Path, idx: int) -> None:
"""
Expand Down

0 comments on commit d4b8c5d

Please sign in to comment.