Upload 2 files
Browse files- backend.py +8 -12
- predict_pose.py +11 -2
backend.py
CHANGED
|
@@ -219,11 +219,14 @@ def process_input(input_video_path):
|
|
| 219 |
|
| 220 |
print("4. Generuji překlad...")
|
| 221 |
|
| 222 |
-
# VYLEPŠENÁ KONTROLA VSTUPŮ
|
| 223 |
print(f"DEBUG: Typ src_input: {type(src_input)}")
|
| 224 |
if isinstance(src_input, dict):
|
| 225 |
for k, v in src_input.items():
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
| 227 |
elif hasattr(src_input, 'shape'):
|
| 228 |
print(f"DEBUG: Tvar src_input: {src_input.shape}")
|
| 229 |
|
|
@@ -231,18 +234,13 @@ def process_input(input_video_path):
|
|
| 231 |
with torch.no_grad():
|
| 232 |
stack_out = model(src_input, tgt_input)
|
| 233 |
|
| 234 |
-
# Získáme instanci tokenizéru už tady, abychom mu vzali ID tokenů
|
| 235 |
tokenizer = model.mt5_tokenizer
|
| 236 |
|
| 237 |
-
#
|
| 238 |
output = model.generate(
|
| 239 |
stack_out,
|
| 240 |
max_new_tokens=100,
|
| 241 |
num_beams=4,
|
| 242 |
-
min_length=5, # Zakáže modelu vrátit jen prázdný výsledek
|
| 243 |
-
bos_token_id=tokenizer.pad_token_id,
|
| 244 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 245 |
-
pad_token_id=tokenizer.pad_token_id,
|
| 246 |
)
|
| 247 |
|
| 248 |
print(f"DEBUG: Výstupní tensor má tvar: {output.shape}")
|
|
@@ -251,7 +249,6 @@ def process_input(input_video_path):
|
|
| 251 |
tgt_pres = tokenizer.batch_decode(output, skip_special_tokens=True)
|
| 252 |
print(f"DEBUG: Surový text z tokenizéru: '{tgt_pres}'")
|
| 253 |
|
| 254 |
-
# Schválně zkusíme dekódovat BEZ přeskočení speciálních tokenů, abychom viděli, co model řekl
|
| 255 |
surove_tokeny = tokenizer.batch_decode(output, skip_special_tokens=False)
|
| 256 |
print(f"DEBUG: Text VČETNĚ speciálních tokenů: '{surove_tokeny}'")
|
| 257 |
|
|
@@ -263,7 +260,6 @@ def process_input(input_video_path):
|
|
| 263 |
return result
|
| 264 |
|
| 265 |
except Exception as e:
|
| 266 |
-
# PŘIDÁNO: Zachycení a vypsání chyby (sloučeno do jednoho bloku)
|
| 267 |
print("=====================================")
|
| 268 |
print("CHYBA PŘI GENEROVÁNÍ PŘEKLADU!")
|
| 269 |
print(f"Typ chyby: {type(e).__name__}")
|
|
@@ -272,9 +268,9 @@ def process_input(input_video_path):
|
|
| 272 |
traceback.print_exc()
|
| 273 |
print("=====================================")
|
| 274 |
return f"Došlo k vnitřní chybě modelu při generování: {str(e)}"
|
| 275 |
-
|
| 276 |
except Exception as e:
|
| 277 |
print(f"Chyba při zpracování: {e}")
|
| 278 |
import traceback
|
| 279 |
traceback.print_exc()
|
| 280 |
-
return f"Chyba při zpracování videa: {str(e)}"
|
|
|
|
| 219 |
|
| 220 |
print("4. Generuji překlad...")
|
| 221 |
|
| 222 |
+
# VYLEPŠENÁ KONTROLA VSTUPŮ S KONTROLOU HODNOT (Zda to nejsou samé nuly)
|
| 223 |
print(f"DEBUG: Typ src_input: {type(src_input)}")
|
| 224 |
if isinstance(src_input, dict):
|
| 225 |
for k, v in src_input.items():
|
| 226 |
+
if hasattr(v, 'shape') and hasattr(v, 'min'):
|
| 227 |
+
print(f"DEBUG: -- src_input['{k}'] typ: {type(v)}, tvar: {v.shape}, min: {v.min().item():.4f}, max: {v.max().item():.4f}, mean: {v.mean().item():.4f}")
|
| 228 |
+
else:
|
| 229 |
+
print(f"DEBUG: -- src_input['{k}'] typ: {type(v)}, tvar: {v.shape if hasattr(v, 'shape') else 'Není tensor'}")
|
| 230 |
elif hasattr(src_input, 'shape'):
|
| 231 |
print(f"DEBUG: Tvar src_input: {src_input.shape}")
|
| 232 |
|
|
|
|
| 234 |
with torch.no_grad():
|
| 235 |
stack_out = model(src_input, tgt_input)
|
| 236 |
|
|
|
|
| 237 |
tokenizer = model.mt5_tokenizer
|
| 238 |
|
| 239 |
+
# NÁVRAT K ORIGINÁLNÍMU VOLÁNÍ (Odebrány nepodporované argumenty)
|
| 240 |
output = model.generate(
|
| 241 |
stack_out,
|
| 242 |
max_new_tokens=100,
|
| 243 |
num_beams=4,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
)
|
| 245 |
|
| 246 |
print(f"DEBUG: Výstupní tensor má tvar: {output.shape}")
|
|
|
|
| 249 |
tgt_pres = tokenizer.batch_decode(output, skip_special_tokens=True)
|
| 250 |
print(f"DEBUG: Surový text z tokenizéru: '{tgt_pres}'")
|
| 251 |
|
|
|
|
| 252 |
surove_tokeny = tokenizer.batch_decode(output, skip_special_tokens=False)
|
| 253 |
print(f"DEBUG: Text VČETNĚ speciálních tokenů: '{surove_tokeny}'")
|
| 254 |
|
|
|
|
| 260 |
return result
|
| 261 |
|
| 262 |
except Exception as e:
|
|
|
|
| 263 |
print("=====================================")
|
| 264 |
print("CHYBA PŘI GENEROVÁNÍ PŘEKLADU!")
|
| 265 |
print(f"Typ chyby: {type(e).__name__}")
|
|
|
|
| 268 |
traceback.print_exc()
|
| 269 |
print("=====================================")
|
| 270 |
return f"Došlo k vnitřní chybě modelu při generování: {str(e)}"
|
| 271 |
+
|
| 272 |
except Exception as e:
|
| 273 |
print(f"Chyba při zpracování: {e}")
|
| 274 |
import traceback
|
| 275 |
traceback.print_exc()
|
| 276 |
+
return f"Chyba při zpracování videa: {str(e)}"
|
predict_pose.py
CHANGED
|
@@ -542,9 +542,18 @@ def predict_pose(video: List[np.ndarray], models: tuple, sign_space=4, yolo_sign
|
|
| 542 |
}
|
| 543 |
|
| 544 |
try:
|
| 545 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
with open("latest_keypoints.json", "w", encoding="utf-8") as f:
|
| 547 |
-
json.dump(json_data, f, indent=4)
|
| 548 |
print("DEBUG: JSON úspěšně uložen jako latest_keypoints.json (včetně bounding boxů)")
|
| 549 |
except Exception as e:
|
| 550 |
print(f"VAROVÁNÍ: Nepodařilo se uložit JSON soubor. Chyba: {e}")
|
|
|
|
| 542 |
}
|
| 543 |
|
| 544 |
try:
|
| 545 |
+
# Pomocná funkce pro automatický převod numpy typů (int64, ndarray) na čistý Python
|
| 546 |
+
def convert_numpy(obj):
|
| 547 |
+
if isinstance(obj, (np.integer, np.int64, np.int32)):
|
| 548 |
+
return int(obj)
|
| 549 |
+
if isinstance(obj, (np.floating, np.float64, np.float32)):
|
| 550 |
+
return float(obj)
|
| 551 |
+
if isinstance(obj, np.ndarray):
|
| 552 |
+
return obj.tolist()
|
| 553 |
+
raise TypeError(f"Type {type(obj)} not serializable")
|
| 554 |
+
|
| 555 |
with open("latest_keypoints.json", "w", encoding="utf-8") as f:
|
| 556 |
+
json.dump(json_data, f, indent=4, default=convert_numpy)
|
| 557 |
print("DEBUG: JSON úspěšně uložen jako latest_keypoints.json (včetně bounding boxů)")
|
| 558 |
except Exception as e:
|
| 559 |
print(f"VAROVÁNÍ: Nepodařilo se uložit JSON soubor. Chyba: {e}")
|