# Save as: diagnose_model.py import h5py import tensorflow as tf import json print("🔍 Diagnosing hybrid_model.keras...") # 1. Check file structure print("\n1. HDF5 File Structure:") with h5py.File('hybrid_model.keras', 'r') as f: print("Top-level keys:", list(f.keys())) # Check for model config if 'model_config' in f: config = f['model_config'][()] if isinstance(config, bytes): config = config.decode('utf-8') # Try to parse JSON try: model_config = json.loads(config) print("\n2. Model Configuration:") print(f" Model class: {model_config.get('class_name', 'Unknown')}") print(f" Config keys: {list(model_config.get('config', {}).keys())}") # Print layers if 'layers' in model_config.get('config', {}): layers = model_config['config']['layers'] print(f"\n3. Model Layers ({len(layers)} total):") for i, layer in enumerate(layers): class_name = layer.get('class_name', 'Unknown') name = layer.get('config', {}).get('name', 'No name') print(f" {i:3d}: {class_name:30s} - {name}") except: print(" Could not parse model config") # Check weights if 'model_weights' in f: print("\n4. Model Weights:") weight_layers = list(f['model_weights'].keys()) print(f" Weight groups: {weight_layers[:10]}") # First 10 # Try to load with Keras print("\n5. Attempting Keras load...") try: model = tf.keras.models.load_model('hybrid_model.keras', compile=False) print(f" ✅ Success! Model loaded") print(f" Input shape: {model.input_shape}") print(f" Output shape: {model.output_shape}") print(f" Layers: {len(model.layers)}") # Show layer names print("\n Layer Names:") for i, layer in enumerate(model.layers[:10]): # First 10 print(f" {i}: {layer.name} ({layer.__class__.__name__})") except Exception as e: print(f" ❌ Failed: {e}")