Download Scripts/remap_classes.py from moiaraya/I-AsSET: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/datasets/moiaraya/I-AsSET/resolve/main/Scripts/remap_classes.py
- Command line
-
hf download hf://datasets/moiaraya/I-AsSET/Scripts/remap_classes.py
-
curl -L -o remap_classes.py https://huggingface.co/datasets/moiaraya/I-AsSET/resolve/main/Scripts/remap_classes.py
2.4 kB
| from pathlib import Path | |
| # Original class order (from Reverse_Ablation training dataset.yaml) | |
| ORIGINAL_NAMES = { | |
| 0: "C_Steel_Ball_L", 1: "C_Steel_Ball_S", 2: "GF_Split_Pin_L", 3: "GF_Split_Pin_S", | |
| 4: "GF_Collar_L", 5: "GF_Collar_S", 6: "FestoI", 7: "FestoT", 8: "FestoV", | |
| 9: "FestoX", 10: "FestoY", 11: "Festo_Torch", 12: "GF_Hexagon_F_Roll-in_Nut_M5", | |
| 13: "F_Roll-in_Nut_M5", 14: "C_O_Ring_L", 15: "C_O_Ring_M", 16: "C_O_Ring_S", | |
| 17: "C_Plastic_Washer_L", 18: "C_Plastic_Washer_S", 19: "GF_Plain_Screw_M8", | |
| 20: "MM_Wood_Screw", 21: "GF_Screw_M5", 22: "GF_Knurled_Screw_M8", | |
| 23: "MM_Silencer_L", 24: "MM_Silencer_S", 25: "GF_Cone_Screw_M8", 26: "MM_Spring", | |
| 27: "GF_Slotted_Pin_L", 28: "GF_Slotted_Pin_S", 29: "C_Washer_M6", | |
| 30: "C_Washer_M5", 31: "MM_Wing", | |
| } | |
| # inverse_permutation[true_class_index] = index the model internally predicts for that | |
| # semantic class, derived from the confusion-matrix argmax mapping (all confidences | |
| # reviewed above; bijection confirmed, no collisions). | |
| inverse_permutation = { | |
| 0: 5, 1: 6, 2: 25, 3: 26, 4: 16, 5: 17, 6: 10, 7: 11, | |
| 8: 12, 9: 13, 10: 14, 11: 15, 12: 19, 13: 9, 14: 0, 15: 1, | |
| 16: 2, 17: 3, 18: 4, 19: 21, 20: 31, 21: 22, 22: 20, 23: 27, | |
| 24: 28, 25: 18, 26: 29, 27: 23, 28: 24, 29: 8, 30: 7, 31: 30, | |
| } | |
| # --- Sanity check: confirm bijection before touching any files --- | |
| assert len(inverse_permutation) == 32, "Mapping must cover all 32 classes." | |
| assert sorted(inverse_permutation.values()) == list(range(32)), ( | |
| "Mapping is not a valid bijection. Aborting before modifying label files." | |
| ) | |
| SRC_LABELS = Path("/media/rtx5090/IRIS_Test_Remapped/labels_original/full/rgb/") | |
| DST_LABELS = Path("/media/rtx5090/IRIS_Test_Remapped/labels/full/rgb/") | |
| DST_LABELS.mkdir(parents=True, exist_ok=True) | |
| n_files = 0 | |
| n_boxes = 0 | |
| for label_file in SRC_LABELS.glob("*.txt"): | |
| lines_out = [] | |
| for line in label_file.read_text().splitlines(): | |
| if not line.strip(): | |
| continue | |
| parts = line.split() | |
| old_idx = int(parts[0]) | |
| new_idx = inverse_permutation[old_idx] | |
| lines_out.append(" ".join([str(new_idx)] + parts[1:])) | |
| n_boxes += 1 | |
| (DST_LABELS / label_file.name).write_text("\n".join(lines_out) + "\n") | |
| n_files += 1 | |
| print(f"Remapped {n_boxes} boxes across {n_files} label files.") | |
| print(f"Output written to: {DST_LABELS}") | |