amfafa commited on
Commit
e42d8ee
·
verified ·
1 Parent(s): d9d8ebc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -136,21 +136,17 @@ if isinstance(ckpt, dict):
136
  break
137
  except Exception as e:
138
  print(f"Key '{key}' found but failed: {e}")
139
-
140
- if not loaded:
141
- sample_keys = list(ckpt.keys())[:5]
142
- if any('.' in k for k in sample_keys):
143
- try:
144
- classifier.load_state_dict(ckpt)
145
- print("Loaded classifier directly from checkpoint dict")
146
- loaded = True
147
- except:
148
- try:
149
- classifier.load_state_dict(ckpt, strict=False)
150
- print("Loaded classifier with strict=False")
151
- loaded = True
152
- except Exception as e2:
153
- print(f"Direct load failed: {e2}")
154
 
155
  if not loaded and 'embedding_head_state' in ckpt and 'aam_softmax_state' in ckpt:
156
  try:
 
136
  break
137
  except Exception as e:
138
  print(f"Key '{key}' found but failed: {e}")
139
+ if not loaded and 'embedding_head_state' in ckpt and 'aam_softmax_state' in ckpt:
140
+ try:
141
+ emb_state = {}
142
+ for k, v in ckpt['embedding_head_state'].items():
143
+ emb_state[k.replace("0.", "")] = v
144
+ classifier.fc1.load_state_dict(emb_state)
145
+ classifier.aam.load_state_dict(ckpt['aam_softmax_state'])
146
+ print("Loaded classifier from embedding_head_state + aam_softmax_state")
147
+ loaded = True
148
+ except Exception as e:
149
+ print(f"Split load failed: {e}")
 
 
 
 
150
 
151
  if not loaded and 'embedding_head_state' in ckpt and 'aam_softmax_state' in ckpt:
152
  try: