File size: 2,197 Bytes
810396d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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}")