Spaces:
Runtime error
Runtime error
Update train_lstm_model.py
Browse files- train_lstm_model.py +10 -1
train_lstm_model.py
CHANGED
|
@@ -6,6 +6,10 @@ from tensorflow.keras.layers import LSTM, Dense
|
|
| 6 |
from tensorflow.keras.optimizers import Adam
|
| 7 |
import os
|
| 8 |
import shutil
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Check disk space
|
| 11 |
available_space = shutil.disk_usage('.').free / (1024 * 1024) # Free space in MB
|
|
@@ -59,8 +63,13 @@ os.makedirs('models', exist_ok=True)
|
|
| 59 |
if not os.access('models', os.W_OK):
|
| 60 |
raise PermissionError("No write permissions for the 'models' directory.")
|
| 61 |
|
| 62 |
-
#
|
| 63 |
model_path = 'models/lstm_energy_model.h5'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
try:
|
| 65 |
model.save(model_path)
|
| 66 |
except Exception as e:
|
|
|
|
| 6 |
from tensorflow.keras.optimizers import Adam
|
| 7 |
import os
|
| 8 |
import shutil
|
| 9 |
+
import tensorflow as tf
|
| 10 |
+
|
| 11 |
+
# Disable GPU to avoid cuDNN/cuBLAS conflicts (for now)
|
| 12 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "" # Force TensorFlow to use CPU
|
| 13 |
|
| 14 |
# Check disk space
|
| 15 |
available_space = shutil.disk_usage('.').free / (1024 * 1024) # Free space in MB
|
|
|
|
| 63 |
if not os.access('models', os.W_OK):
|
| 64 |
raise PermissionError("No write permissions for the 'models' directory.")
|
| 65 |
|
| 66 |
+
# Remove any existing (invalid) model file
|
| 67 |
model_path = 'models/lstm_energy_model.h5'
|
| 68 |
+
if os.path.exists(model_path):
|
| 69 |
+
os.remove(model_path)
|
| 70 |
+
print(f"Removed existing (invalid) file at {model_path}")
|
| 71 |
+
|
| 72 |
+
# Save the trained model
|
| 73 |
try:
|
| 74 |
model.save(model_path)
|
| 75 |
except Exception as e:
|