Skip to content

Instantly share code, notes, and snippets.

@AlessandroMondin
Created December 26, 2022 13:55
Show Gist options
  • Save AlessandroMondin/f8beab8c30e5fd29b6b0f947e86a756d to your computer and use it in GitHub Desktop.
Save AlessandroMondin/f8beab8c30e5fd29b6b0f947e86a756d to your computer and use it in GitHub Desktop.
try:
self.annotations = pd.read_csv(os.path.join(root_directory, "labels", annot_file),
header=None, index_col=0).sort_values(by=[0])
self.annotations = self.annotations.head((len(self.annotations)-1)) # just removes last line
except FileNotFoundError:
annotations = []
for img_txt in os.listdir(os.path.join(self.root_directory, "labels", self.annot_folder)):
img = img_txt.split(".txt")[0]
try:
w, h = imagesize.get(os.path.join(self.root_directory, "images", self.annot_folder, f"{img}.jpg"))
except FileNotFoundError:
continue
annotations.append([str(img) + ".jpg", h, w])
self.annotations = pd.DataFrame(annotations)
self.annotations.to_csv(os.path.join(self.root_directory, "labels", annot_file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment