depression-detection-api / test_model_load.py
KnowingFly26's picture
Initial commit - Depression Detection API
7306a70
Raw History Blame Contribute Delete
1.07 kB
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()