Skip to content

Instantly share code, notes, and snippets.

@Chris-hughes10
Last active July 16, 2021 09:16
Show Gist options
  • Save Chris-hughes10/3cec37fcaf0ef41940ace6b51f4e05bb to your computer and use it in GitHub Desktop.
Save Chris-hughes10/3cec37fcaf0ef41940ace6b51f4e05bb to your computer and use it in GitHub Desktop.
Effdet-blog-dataset-adaptor
from pathlib import Path
import PIL
import numpy as np
class CarsDatasetAdaptor:
def __init__(self, images_dir_path, annotations_dataframe):
self.images_dir_path = Path(images_dir_path)
self.annotations_df = annotations_dataframe
self.images = self.annotations_df.image.unique().tolist()
def __len__(self) -> int:
return len(self.images)
def get_image_and_labels_by_idx(self, index):
image_name = self.images[index]
image = PIL.Image.open(self.images_dir_path / image_name)
pascal_bboxes = self.annotations_df[self.annotations_df.image == image_name][
["xmin", "ymin", "xmax", "ymax"]
].values
class_labels = np.ones(len(pascal_bboxes))
return image, pascal_bboxes, class_labels, index
def show_image(self, index):
image, bboxes, class_labels, image_id = self.get_image_and_labels_by_idx(index)
print(f"image_id: {image_id}")
show_image(image, bboxes.tolist())
print(class_labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment