pytorch
canari_ml.models.networks.pytorch
¶
Main module.
canari_ml.models.networks.pytorch.CACHE_SYMLINK_DIR = 'cache_dir'
module-attribute
¶
canari_ml.models.networks.pytorch.NORMALISATION_SYMLINK_DIR = 'normalisation_dir'
module-attribute
¶
canari_ml.models.networks.pytorch.BaseNetwork(dataset, run_name, callbacks_additional=None, callbacks_default=None, network_folder=None, seed=42)
¶
Base class for managing network training, prediction, and callback handling.
This class is a parent class for creating, training, and evaluating neural networks.
It manages the model folder structure, seed setup for reproducibility, and handles
default callbacks. Subclasses must implement the train and predict methods.
Attributes:
| Name | Type | Description |
|---|---|---|
_network_folder |
Path to the directory where network outputs are stored. |
|
_dataset |
The dataset used for training/prediction. |
|
_callbacks |
List of callback objects for monitoring/training procedures. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
CANARIMLDataSetTorch
|
The dataset to be used for training/prediction. |
required |
run_name
|
object
|
Identifier for the current run, used in folder naming. |
required |
callbacks_additional
|
list | None
|
List of additional callback objects to add. |
None
|
callbacks_default
|
list | None
|
List of default callbacks (if not using defaults). |
None
|
network_folder
|
object | None
|
Custom path for the network output directory. |
None
|
seed
|
int
|
Random seed for reproducibility. |
42
|
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.BaseNetwork.callbacks
property
¶
canari_ml.models.networks.pytorch.BaseNetwork.dataset
property
¶
canari_ml.models.networks.pytorch.BaseNetwork.network_folder
property
¶
canari_ml.models.networks.pytorch.BaseNetwork.run_name
property
¶
canari_ml.models.networks.pytorch.BaseNetwork.seed
property
¶
canari_ml.models.networks.pytorch.BaseNetwork.add_callback(callback)
¶
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.BaseNetwork.get_default_callbacks()
¶
canari_ml.models.networks.pytorch.BaseNetwork.create_normalisation_symlink(target_path)
¶
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.BaseNetwork.create_cache_symlink(target_path)
¶
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.BaseNetwork.save_prediction(predictions, dates, output_folder)
¶
Save raw prediction outputs to numpy files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
tensor
|
Tensor containing model forecasts. |
required |
dates
|
list[datetime]
|
List of date objects corresponding to predictions. |
required |
output_folder
|
str
|
Directory path where files will be saved. |
required |
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.BaseNetwork.train(epochs, model_creator, train_dataset, model_creator_kwargs=None, save=True)
abstractmethod
¶
Train the neural network.
Must be implemented by subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epochs
|
int
|
Number of training epochs. |
required |
model_creator
|
callable
|
Callable to instantiate the model. |
required |
train_dataset
|
object
|
Dataset for training. |
required |
model_creator_kwargs
|
dict
|
Keyword arguments for model creation. |
None
|
save
|
bool
|
Whether to save the trained model. |
True
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not overridden in subclass. |
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.BaseNetwork.predict()
abstractmethod
¶
Evaluate a pre-trained neural network.
Must be implemented by subclasses.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not overridden in subclass. |
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.HYDRAPytorchNetwork(cfg, *args, run_type='train', verbose=False, **kwargs)
¶
Bases: BaseNetwork
Source code in src/canari_ml/models/networks/pytorch.py
canari_ml.models.networks.pytorch.HYDRAPytorchNetwork.train()
¶
Source code in src/canari_ml/models/networks/pytorch.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
canari_ml.models.networks.pytorch.HYDRAPytorchNetwork.predict(test_set=False)
¶
Source code in src/canari_ml/models/networks/pytorch.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |