Spaces:
Sleeping
Sleeping
Update core/train_eval.py
Browse files- core/train_eval.py +20 -4
core/train_eval.py
CHANGED
|
@@ -154,6 +154,14 @@ def train_and_evaluate(
|
|
| 154 |
train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
|
| 155 |
test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
input_size = X.shape[2]
|
| 158 |
model = model_cls(input_size=input_size, hidden_size=hidden, num_layers=layers, output_size=horizon, dropout=dropout).to(device)
|
| 159 |
logging.debug(f"Model initialized: {model_cls.__name__}, input_size={input_size}, hidden={hidden}, layers={layers}")
|
|
@@ -187,8 +195,12 @@ def train_and_evaluate(
|
|
| 187 |
logging.debug(f"Training Batch_X type: {type(batch_X)}, shape: {batch_X.shape}")
|
| 188 |
logging.debug(f"Training Batch_Y type: {type(batch_y)}, shape: {batch_y.shape}")
|
| 189 |
optimizer.zero_grad()
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
loss = criterion(outputs, batch_y)
|
| 193 |
loss.backward()
|
| 194 |
optimizer.step()
|
|
@@ -202,8 +214,12 @@ def train_and_evaluate(
|
|
| 202 |
for batch_X, batch_y in test_loader:
|
| 203 |
logging.debug(f"Validation Batch_X type: {type(batch_X)}, shape: {batch_X.shape}")
|
| 204 |
logging.debug(f"Validation Batch_Y type: {type(batch_y)}, shape: {batch_y.shape}")
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
loss = criterion(outputs, batch_y)
|
| 208 |
val_loss += loss.item() * batch_X.size(0)
|
| 209 |
val_loss /= len(test_loader.dataset)
|
|
|
|
| 154 |
train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
|
| 155 |
test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)
|
| 156 |
|
| 157 |
+
# Debug DataLoader output
|
| 158 |
+
for batch_X, batch_y in train_loader:
|
| 159 |
+
logging.debug(f"DataLoader train batch: X_type={type(batch_X)}, X_shape={batch_X.shape}, y_type={type(batch_y)}, y_shape={batch_y.shape}")
|
| 160 |
+
break
|
| 161 |
+
for batch_X, batch_y in test_loader:
|
| 162 |
+
logging.debug(f"DataLoader test batch: X_type={type(batch_X)}, X_shape={batch_X.shape}, y_type={type(batch_y)}, y_shape={batch_y.shape}")
|
| 163 |
+
break
|
| 164 |
+
|
| 165 |
input_size = X.shape[2]
|
| 166 |
model = model_cls(input_size=input_size, hidden_size=hidden, num_layers=layers, output_size=horizon, dropout=dropout).to(device)
|
| 167 |
logging.debug(f"Model initialized: {model_cls.__name__}, input_size={input_size}, hidden={hidden}, layers={layers}")
|
|
|
|
| 195 |
logging.debug(f"Training Batch_X type: {type(batch_X)}, shape: {batch_X.shape}")
|
| 196 |
logging.debug(f"Training Batch_Y type: {type(batch_y)}, shape: {batch_y.shape}")
|
| 197 |
optimizer.zero_grad()
|
| 198 |
+
try:
|
| 199 |
+
outputs = model(batch_X)
|
| 200 |
+
logging.debug(f"Model output shape: {outputs.shape}")
|
| 201 |
+
except Exception as e:
|
| 202 |
+
logging.error(f"Model forward error: {str(e)}, batch_X_shape={batch_X.shape}")
|
| 203 |
+
raise
|
| 204 |
loss = criterion(outputs, batch_y)
|
| 205 |
loss.backward()
|
| 206 |
optimizer.step()
|
|
|
|
| 214 |
for batch_X, batch_y in test_loader:
|
| 215 |
logging.debug(f"Validation Batch_X type: {type(batch_X)}, shape: {batch_X.shape}")
|
| 216 |
logging.debug(f"Validation Batch_Y type: {type(batch_y)}, shape: {batch_y.shape}")
|
| 217 |
+
try:
|
| 218 |
+
outputs = model(batch_X)
|
| 219 |
+
logging.debug(f"Validation model output shape: {outputs.shape}")
|
| 220 |
+
except Exception as e:
|
| 221 |
+
logging.error(f"Validation model forward error: {str(e)}, batch_X_shape={batch_X.shape}")
|
| 222 |
+
raise
|
| 223 |
loss = criterion(outputs, batch_y)
|
| 224 |
val_loss += loss.item() * batch_X.size(0)
|
| 225 |
val_loss /= len(test_loader.dataset)
|