import os import json def create_word_mapping(): word_to_number = { "eye": 0, "lip": 1, "nose": 2, "hair": 3, "eyebrow": 4, } return word_to_number # def create_word_mapping(): # word_to_number = { # "bangs": 0, # "beard": 1, # "young": 2, # "eyeglasses": 3, # "smiling": 4, # } # return word_to_number def words_to_numbers(sentence, word_to_number): # Remove the trailing period and split the sentence into words based on ". " delimiter words = sentence.lower().strip().rstrip('.').split(". ") # Convert words to numbers using the mapping numbers = [word_to_number[word] for word in words if word in word_to_number] return numbers def strip_path_and_map_words(file_path, word_to_number): # Extract the relevant part of the file path relevant_part = os.path.basename(os.path.dirname(file_path)) # Split the relevant part into words based on "-" delimiter words = relevant_part.lower().split('-') # Convert words to numbers using the mapping numbers = [word_to_number[word] for word in words if word in word_to_number] return numbers def read_jsonl(file_path): with open(file_path, 'r') as file: return [json.loads(line) for line in file] def process_files(image_jsonl_path, text_jsonl_path): image_data = read_jsonl(image_jsonl_path) text_data = read_jsonl(text_jsonl_path) if len(image_data) != len(text_data): raise ValueError("The two JSONL files must have the same number of entries.") accuracies=[] totalCorrect=0 totalTotal=0 accuracyC = [0,0,0,0,0] accuracyT = [0,0,0,0,0] for img_entry, text_entry in zip(image_data, text_data): img_path = img_entry.get('image') text_seq = text_entry.get('text') if img_path is None or text_seq is None: raise ValueError("Entries must contain 'image' and 'text' fields respectively.") a = words_to_numbers(text_seq, word_to_number) b = strip_path_and_map_words(img_path, word_to_number) correct = 0 # total = len(b) # for i in b: # accuracyT[i]+=1 # i = 0 # while(i