Spaces:
Sleeping
Sleeping
Download test_model_load.py from KnowingFly/depression-detection-api: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/KnowingFly/depression-detection-api/resolve/main/test_model_load.py
- Command line
-
hf download hf://spaces/KnowingFly/depression-detection-api/test_model_load.py
-
curl -L -o test_model_load.py https://huggingface.co/spaces/KnowingFly/depression-detection-api/resolve/main/test_model_load.py
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() | |