-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from benoitmartin88/rc
release 0.2.0
- Loading branch information
Showing
14 changed files
with
236 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Changelog | ||
========= | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
# Unreleased | ||
|
||
|
||
# # [0.2.0] - 2019-09-20 | ||
## New | ||
- Add `ModuleTrainer.evaluate` method | ||
- Add CsvWriter to evaluate method | ||
- Add `filename_transform_function` argument to `SaveBestCheckpointCallback` | ||
- Metric step method now return the intermediate computed values | ||
- Rename `CsvWriter`'s `extra` argument to `extra_data_function` | ||
- `CsvWriter` can now be called with the `extra_data` extra argument to define the extra data that will be logged | ||
- Add `ModuleTrainer.load` method | ||
|
||
## Change | ||
- Rename `dateset_loader` to `dataloader` | ||
|
||
|
||
# [0.1.0] - 2019-09-16 | ||
## New | ||
- `ModuleTrainer` object | ||
- `EarlyStopping`: stop training after a configurable period of stagnation | ||
- Checkpointing: save model and estimator at regular intervals | ||
- CSV file writer to output logs | ||
- Several metrics are available: all default PyTorch loss functions, Accuracy, MAE | ||
- Progress bar from console | ||
- SIGINT handling: handle CTRL-C | ||
- Model's data type (float32, float64) | ||
- Full use of Pytorch's Cuda support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
__version__ = '0.1.0' | ||
__version__ = '0.2.0' | ||
|
||
|
||
from .trainer import create_default_trainer, ModuleTrainer, State | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,14 @@ | ||
import torch | ||
from .callback import Callback | ||
|
||
|
||
class ValidationCallback(Callback): | ||
def __init__(self, dataset_loader, metric, device=None, dtype=None, non_blocking=False): | ||
def __init__(self, dataloader, metric, device=None, dtype=None, non_blocking=False): | ||
super().__init__(state_attribute_name="last_validation_%s" % metric.name, state_attribute_default_value=metric.default_value) | ||
self.dataset_loader = dataset_loader | ||
self.dataloader = dataloader | ||
self.metric = metric | ||
self.device = device | ||
self.dtype = dtype | ||
self.non_blocking = non_blocking | ||
|
||
def __call__(self, trainer): | ||
setattr(trainer.state, self.state_attribute_name, self._validation_function(trainer.model, trainer.prepare_batch_function)) | ||
|
||
def _validation_function(self, model, prepare_batch_function): | ||
model.eval() | ||
|
||
device_to_use = self.device | ||
models_device = next(model.parameters()).device | ||
|
||
if self.device is None: | ||
# use the model's device | ||
device_to_use = models_device | ||
|
||
model.to(device_to_use) | ||
|
||
self.metric.reset() | ||
|
||
with torch.no_grad(): | ||
for batch in self.dataset_loader: | ||
x, y, model_args = prepare_batch_function(batch, device=device_to_use, dtype=self.dtype, non_blocking=self.non_blocking) | ||
y_pred = model(x, **model_args) | ||
self.metric.step(y, y_pred) | ||
|
||
model.to(models_device) # this will be a no-op if the device has not changed | ||
return self.metric.compute() | ||
|
||
setattr(trainer.state, self.state_attribute_name, trainer.evaluate(self.dataloader, self.metric)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.