Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
folkien committed Feb 5, 2025
1 parent 71ca20d commit 6895577
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/yaya_tools/yaya_augument.py",
"args": ["--dataset_path", "tests/test_dataset/","--blur", "--select_class_id", "2"],
"args": ["--dataset_path", "tests/test_dataset/","--sepia", "--select_crowded" ],
"console": "integratedTerminal",
"justMyCode": false
},
Expand Down
18 changes: 10 additions & 8 deletions yaya_tools/helpers/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,20 @@ def annotations_filter_tiny(annotations: sv.Detections, max_area: float = 0.01)

def annotations_filter_crowded(annotations: sv.Detections, min_objects: int = 7) -> sv.Detections:
"""Filter out large annotations from the dataset"""
annotations_files = annotations.data.get("filepaths", np.array([]))
# Count for each filename how many annotations are there
annotations_count = np.array([np.sum(annotations_files == filename) for filename in annotations_files])
return annotations[annotations_count >= min_objects] # type: ignore
annotations_files = annotations.data.get("filepaths", np.array([], dtype=str))
unique_files = np.unique(annotations_files)
files_sum = np.array([np.sum(annotations_files == filename) for filename in unique_files])
files_approved = unique_files[files_sum >= min_objects]
return annotations[np.isin(annotations_files, files_approved)] # type: ignore


def annotations_filter_spacious(annotations: sv.Detections, max_objects: int = 3) -> sv.Detections:
def annotations_filter_spacious(annotations: sv.Detections, max_objects: int = 4) -> sv.Detections:
"""Filter out large annotations from the dataset"""
annotations_files = annotations.data.get("filepaths", np.array([]))
# Count for each filename how many annotations are there
annotations_count = np.array([np.sum(annotations_files == filename) for filename in annotations_files])
return annotations[annotations_count < max_objects] # type: ignore
unique_files = np.unique(annotations_files)
files_sum = np.array([np.sum(annotations_files == filename) for filename in unique_files])
files_approved = unique_files[files_sum < max_objects]
return annotations[np.isin(annotations_files, files_approved)] # type: ignore


def annotations_filter_equalize(
Expand Down
6 changes: 3 additions & 3 deletions yaya_tools/helpers/augmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ def augmentation_select(args: argparse.Namespace) -> Optional[Augumentation]:
return transform_flip_horizontal_make()
if args.flip_vertical:
return transform_flip_vertical_make()
if args.crop:
if args.crop != -1:
return transform_crop_make(args.crop)
if args.rotate:
if args.rotate != -1:
return transform_rotate_make(args.rotate)
if args.randrotate:
return transform_rotate_make(args.randrotate)
Expand Down Expand Up @@ -439,7 +439,7 @@ def augmentation_select(args: argparse.Namespace) -> Optional[Augumentation]:
return transform_spatter_big_make()
if args.spatter_small:
return transform_spatter_small_make()
if args.blackboxing:
if args.blackboxing != -1:
return transform_blackboxing_make()
if args.snow:
return transform_snow_make()
Expand Down
8 changes: 4 additions & 4 deletions yaya_tools/yaya_augument.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ def main() -> None:
"--crop",
type=int,
nargs="?",
const=0,
default=0,
const=-1,
default=-1,
required=False,
help="Augument by random Crop image (for ex 640).",
)
parser.add_argument(
"--rotate",
type=int,
nargs="?",
const=0,
default=0,
const=-1,
default=-1,
required=False,
help="Augument by direct degrees rotation (for ex 90).",
)
Expand Down

0 comments on commit 6895577

Please sign in to comment.