Skip to content

Commit

Permalink
fixes #203
Browse files Browse the repository at this point in the history
  • Loading branch information
“oguiza” committed Sep 10, 2021
1 parent d24e572 commit 50f8767
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 79 deletions.
35 changes: 0 additions & 35 deletions nbdev_jekyll.py

This file was deleted.

68 changes: 37 additions & 31 deletions nbs/060_callback.core.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@
"\n",
"Checking folder: /Users/nacho/Documents/Machine_Learning/Jupyter_Notebooks/tsai/tsai\n",
"Correct conversion! 😃\n",
"Total time elapsed 245 s\n",
"Saturday 04/09/21 14:10:34 CEST\n"
"Total time elapsed 304 s\n",
"Friday 10/09/21 18:13:29 CEST\n"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ host = github
lib_name = tsai
user = timeseriesAI
branch = main
version = 0.2.22
version = 0.2.23
description = Practical Deep Learning for Time Series / Sequential Data library based on fastai & Pytorch
keywords = fastai time-series time-series-classification time-series-regression deep-learning Pytorch
author = Ignacio Oguiza and contributors
Expand Down
2 changes: 1 addition & 1 deletion tsai/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.22"
__version__ = "0.2.23"
13 changes: 4 additions & 9 deletions tsai/callback/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,15 @@ def before_fit(self):
self.reduction = getattr(self.learn.loss_func, 'reduction', None)
self.learn.loss_func = _PerInstanceLoss(crit=self.learn.loss_func)
assert len(self.instance_weights) == len(self.learn.dls.train.dataset) + len(self.learn.dls.valid.dataset)
self.instance_weights = tensor(self.instance_weights).to(self.learn.dls.device)
self.instance_weights = torch.as_tensor(self.instance_weights, device=self.learn.dls.device)

def before_batch(self):
if self.training:
original_idxs = tensor([self.learn.dls.train.split_idxs[self.learn.dls.train.idxs]], device=self.x.device)[0]
self.learn.loss_func.weights = self.instance_weights[original_idxs]
else:
original_idxs = tensor([self.learn.dls.valid.split_idxs[self.learn.dls.valid.idxs]], device=self.x.device)[0]
self.learn.loss_func.weights = self.instance_weights[original_idxs]
input_idxs = self.learn.dls.train.input_idxs if self.training else self.learn.dls.valid.input_idxs
self.learn.loss_func.weights = self.instance_weights[input_idxs]

def after_fit(self):
self.learn.loss_func = self.old_loss
if self.reduction is not None:
self.learn.loss_func.reduction = self.reduction
if self.reduction is not None: self.learn.loss_func.reduction = self.reduction


class _PerInstanceLoss(Module):
Expand Down

0 comments on commit 50f8767

Please sign in to comment.