training metrics . fix cnn model

This commit is contained in:
Dobromir Popov
2025-09-09 03:43:20 +03:00
parent a3029d09c2
commit 55fb865e7f
2 changed files with 59 additions and 21 deletions

View File

@@ -293,14 +293,34 @@ class TradingOrchestrator:
result = load_best_checkpoint("cnn")
if result:
file_path, metadata = result
self.model_states['cnn']['initial_loss'] = 0.412
self.model_states['cnn']['current_loss'] = metadata.loss or 0.0187
self.model_states['cnn']['best_loss'] = metadata.loss or 0.0134
self.model_states['cnn']['checkpoint_loaded'] = True
self.model_states['cnn']['checkpoint_filename'] = metadata.checkpoint_id
checkpoint_loaded = True
loss_str = f"{metadata.loss:.4f}" if metadata.loss is not None else "N/A"
logger.info(f"CNN checkpoint loaded: {metadata.checkpoint_id} (loss={loss_str})")
# Actually load the model weights from the checkpoint
try:
checkpoint_data = torch.load(file_path, map_location=self.device)
if 'model_state_dict' in checkpoint_data:
self.cnn_model.load_state_dict(checkpoint_data['model_state_dict'])
logger.info(f"CNN model weights loaded from: {file_path}")
elif 'state_dict' in checkpoint_data:
self.cnn_model.load_state_dict(checkpoint_data['state_dict'])
logger.info(f"CNN model weights loaded from: {file_path}")
else:
# Try loading directly as state dict
self.cnn_model.load_state_dict(checkpoint_data)
logger.info(f"CNN model weights loaded directly from: {file_path}")
# Update model states
self.model_states['cnn']['initial_loss'] = checkpoint_data.get('initial_loss', 0.412)
self.model_states['cnn']['current_loss'] = metadata.loss or checkpoint_data.get('loss', 0.0187)
self.model_states['cnn']['best_loss'] = metadata.loss or checkpoint_data.get('best_loss', 0.0134)
self.model_states['cnn']['checkpoint_loaded'] = True
self.model_states['cnn']['checkpoint_filename'] = metadata.checkpoint_id
checkpoint_loaded = True
loss_str = f"{metadata.loss:.4f}" if metadata.loss is not None else "N/A"
logger.info(f"CNN checkpoint loaded: {metadata.checkpoint_id} (loss={loss_str})")
except Exception as load_error:
logger.warning(f"Failed to load CNN model weights: {load_error}")
# Continue with fresh model but mark as loaded for metadata purposes
self.model_states['cnn']['checkpoint_loaded'] = True
checkpoint_loaded = True
except Exception as e:
logger.warning(f"Error loading CNN checkpoint: {e}")