File size: 1,073 Bytes
7306a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import tensorflow as tf

model_path = "model.h5"

print(f"TensorFlow version: {tf.__version__}")
print(f"Keras (bundled with TensorFlow): {tf.__version__}")
print(f"Model file exists: {os.path.exists(model_path)}")

try:
    # Custom InputLayer to handle batch_shape -> shape conversion
    class CompatibleInputLayer(tf.keras.layers.InputLayer):
        def __init__(self, **kwargs):
            print(f"InputLayer kwargs: {kwargs}")
            if 'batch_shape' in kwargs:
                batch_shape = kwargs.pop('batch_shape')
                if batch_shape is not None:
                    kwargs['input_shape'] = batch_shape[1:]
            super().__init__(**kwargs)
    
    custom_objects = {'InputLayer': CompatibleInputLayer}
    model = tf.keras.models.load_model(
        model_path, 
        custom_objects=custom_objects,
        compile=False
    )
    print("Model loaded successfully!")
    print(f"Model summary:")
    model.summary()
except Exception as e:
    print(f"Error loading model: {e}")
    import traceback
    traceback.print_exc()