Tim77777767 commited on
Commit
1ef0893
·
1 Parent(s): ee9d4b8

Anpassung des .bin Checkpoints, damit die Layer den HF Standards entsprechen

Browse files
Files changed (3) hide show
  1. binchanger.py +29 -0
  2. binchecker.py +27 -0
  3. pytorch_model.bin +2 -2
binchanger.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import os
3
+
4
+ # --- Configuration ---
5
+ # Pfad zur Eingabe-BIN-Datei
6
+ input_checkpoint_path = "./pytorch_model.bin"
7
+ # Pfad zur Ausgabe-BIN-Datei (wo die geänderte Version gespeichert wird)
8
+ output_checkpoint_path = "./pytorch_model_renamed.bin"
9
+
10
+ # --- Check, ob die Eingabedatei existiert ---
11
+ if not os.path.exists(input_checkpoint_path):
12
+ print(f"Fehler: Eingabedatei nicht gefunden unter {input_checkpoint_path}. Bitte den Pfad korrigieren.")
13
+ else:
14
+ # --- Checkpoint laden ---
15
+ state_dict = torch.load(input_checkpoint_path, map_location="cpu")
16
+
17
+ # --- Layer-Namen ändern und neues State Dict erstellen ---
18
+ new_state_dict = {}
19
+ for old_key, value in state_dict.items():
20
+ if old_key.startswith('decode_head.'):
21
+ new_key = old_key.replace('decode_head.', 'segformer_head.', 1)
22
+ new_state_dict[new_key] = value
23
+ else:
24
+ new_state_dict[old_key] = value
25
+
26
+ # --- Geändertes State Dict speichern ---
27
+ torch.save(new_state_dict, output_checkpoint_path)
28
+
29
+ print(f"Fertig! Die umbenannte Datei wurde gespeichert unter: {output_checkpoint_path} 🎉")
binchecker.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import os # Import the os module for path manipulation
3
+
4
+ # Define the output file name
5
+ output_file = 'layer_names_renamed_output.txt'
6
+
7
+ # Pfad zu deiner .bin Datei
8
+ checkpoint_path = "./pytorch_model_renamed.bin"
9
+
10
+ # Check if the checkpoint file exists
11
+ if not os.path.exists(checkpoint_path):
12
+ print(f"Error: Checkpoint file not found at {checkpoint_path}. Please update the path.")
13
+ else:
14
+ # Open the output file in write mode ('w')
15
+ with open(output_file, 'w') as f:
16
+ # Checkpoint laden (State Dict)
17
+ state_dict = torch.load(checkpoint_path, map_location="cpu")
18
+
19
+ # Alle Layer-Namen in die Datei schreiben
20
+ f.write("Alle Layer-Namen im Checkpoint:\n")
21
+ for name in state_dict.keys():
22
+ f.write(name + "\n")
23
+
24
+ # Optional: Anzahl der Layer in die Datei schreiben
25
+ f.write(f"\nInsgesamt {len(state_dict)} Layer im Checkpoint.\n")
26
+
27
+ print(f"Layer names successfully saved to {output_file}")
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:eea970e0387b05e22ec603d4d2f4a3f73b38fd84bcf104f451b79043009339a3
3
- size 328287283
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42ba38f139e97fda197d9d1d3249e43f8ce461202ac6a9926b174d31e67862fc
3
+ size 328234307