Created
February 24, 2022 01:37
-
-
Save Hiromi-nee/3a36c1a09959655c6c00780eb3e8a1a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob, os | |
import sys | |
def yolo_reader(annotation_file): | |
with open(annotation_file, 'r') as f: | |
data = f.read() | |
data = data.split("\n") | |
return data | |
# <class id> <Xo/X> <Yo/Y> <W/X> <H/Y> | |
def collate_classes(annotation_files): | |
classes = {} | |
for f in annotation_files: | |
data = yolo_reader(f) | |
for i in data: | |
cls = i.split(" ")[0] | |
classes[cls] = classes.get(cls, 0) +1 | |
return classes | |
def main(dir): | |
os.chdir(dir) | |
annotation_files = [] | |
for file in glob.glob("*.txt"): | |
annotation_files.append(file) | |
classes = collate_classes(annotation_files) | |
print(classes) | |
if __name__ == '__main__': | |
if len(sys.argv) >1: | |
main(sys.argv[1].rstrip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment