| 13 | return matrix, labels |
| 14 | |
| 15 | class SimilarityMatrixProcessor: |
| 16 | |
| 17 | def __init__(self, similarity_matrices_dir, full_data_file=None): |
| 18 | |
| 19 | self.similarity_matrices_dir = Path(similarity_matrices_dir) |
| 20 | |
| 21 | assert full_data_file is not None, "must provide full_data_file" |
| 22 | |
| 23 | logging.info("load...") |
| 24 | self.sim_matrices = {} |
| 25 | self.tag_labels = {} |
| 26 | |
| 27 | for task_id in range(1, 10): |
| 28 | matrix_file = self.similarity_matrices_dir / f"task{task_id}_tag_normalized.npz" |
| 29 | |
| 30 | if matrix_file.exists(): |
| 31 | try: |
| 32 | |
| 33 | matrix, labels = load_matrix_from_upper_triangle(matrix_file) |
| 34 | self.sim_matrices[task_id-1] = matrix |
| 35 | self.tag_labels[task_id-1] = labels if labels is not None else [] |
| 36 | except Exception as e: |
| 37 | |
| 38 | raise |
| 39 | else: |
| 40 | raise FileNotFoundError(f"similarity matrix file not found: {matrix_file}") |
| 41 | |
| 42 | self.tag_indices = {} |
| 43 | for task_id in range(9): |
| 44 | tag_list = list(self.tag_labels[task_id]) |
| 45 | self.tag_indices[task_id] = {tag: idx for idx, tag in enumerate(tag_list)} |
| 46 | |
| 47 | with open(full_data_file, "r") as f: |
| 48 | self.full_data = json.load(f) |
| 49 | |
| 50 | self.full_data_dict = {} |
| 51 | self.full_data_dict_alt = {} |
| 52 | self.full_data_dict_no_ext = {} |
| 53 | |
| 54 | for record in self.full_data: |
| 55 | media_name = record['media_name'] |
| 56 | self.full_data_dict[media_name] = record |
| 57 | |
| 58 | if media_name.endswith('.jpg'): |
| 59 | self.full_data_dict_no_ext[media_name[:-4]] = record |
| 60 | else: |
| 61 | self.full_data_dict_alt[media_name + '.jpg'] = record |
| 62 | |
| 63 | self.task_keys = { |
| 64 | "task1":"Diagnosis", |
| 65 | "task2":"Body_system_level", |
| 66 | "task3":"Organ_level", |
| 67 | "task4":"Shape", |
| 68 | "task5":"Margins", |
| 69 | "task6":"Echogenicity", |
| 70 | "task7":"InternalCharacteristics", |
| 71 | "task8":"PosteriorAcoustics", |
| 72 | "task9":"Vascularity" |
nothing calls this directly
no outgoing calls
no test coverage detected