Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Update VIA Conversion to new JSON format" #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Rohanbagulwar
Copy link

implemented yolov4 load function

/
`def _load(self, labels: List[str] = None, is_load_empty_ann: bool = True):
"""
Load Yolo Darknet (Yolov4) format annotations
:param labels: list of class labels. If None, load all seen labels
:param is_load_empty_ann: if True - load annotations with empty objects images, otherwise - skip.
:return:
"""

# Iterate through the annotation files in the directory
for ann_file in os.listdir(self.annotation_path):
    if ann_file.endswith('.txt'):
        # Construct the full path to the annotation file
        ann_path = os.path.join(self.annotation_path, ann_file)

        # Read the annotation file
        with open(ann_path, 'r') as file:
            lines = file.readlines()

        # Create an annotation object for this file
        annotation = Annotation()  # You'll need to define this class or use an appropriate class from your code

        # Parse each line in the annotation file
        for line in lines:
            # Split the line by space and extract the values
            label, x_c, y_c, w_b, h_b = map(float, line.strip().split())

            # Convert the coordinates to your desired format
            # Here, I'm assuming you want to convert back to pixel coordinates
            w_image, h_image = annotation.width, annotation.height
            x_min = (x_c - w_b / 2) * w_image
            y_min = (y_c - h_b / 2) * h_image
            x_max = (x_c + w_b / 2) * w_image
            y_max = (y_c + h_b / 2) * h_image

            # Create the HBox object and add it to the annotation
            hbox = HBox([x_min, y_min, x_max, y_max], label=labels[int(label)])
            annotation.objects.append(hbox)

        # Add the annotation to the list of annotations
        self._annotations.append(annotation)

# After parsing all files, the annotations should be loaded
self.log.info("Loaded {} annotations.".format(len(self._annotations)))

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant