timeseriesAI / tsai

Time series Timeseries Deep Learning Machine Learning Python Pytorch fastai | State-of-the-art Deep Learning library for Time Series and Sequences in Pytorch / fastai
https://timeseriesai.github.io/tsai/
Apache License 2.0
5.07k stars 633 forks source link

Mixed augmentations on my time series batch #683

Closed Willtl closed 1 year ago

Willtl commented 1 year ago

Is there a way that I can use mixed augmentations on my batch, as in the code below?

    for epoch in range(1, EPOCHS + 1):
        for i, batch in enumerate(train_dl):
            series, targets = batch
            if torch.cuda.is_available():
                series = series.cuda(non_blocking=True)
                targets = targets.cuda(non_blocking=True)

            # Apply CutMix1d on my batch
            series, targets = CutMix1d(series, targets)

            # Feedfoward, backward, and adjust model
            output = model(series,targets)
            loss = ...
            step ...           
oguiza commented 1 year ago

Hi @Willtl, I'm not sure I understand what you want to do? CutMix1d is available as a callback in tsai. You can pass it to any Learner (tslearner, TSClassifier, etc). You just need to add cbs=CutMix1d(). The callback will apply CutMix to every batch during training. Does this answer your question?

Willtl commented 1 year ago

Hello @oguiza, I appreciate your response!

My objective is to incorporate CutMix1d into my training loop. Specifically, I want to use it on each batch of series and targets to obtain the CutMix1d output. However, it appears that CutMix1d can only be used as a callback from a Leaner.

In essence, my goal is to use CutMix1d from the tsai library in my PyTorch project without relying on other components such as the Learner.

oguiza commented 1 year ago

Ok, I understand. You’ll need to look into the CutMix1d code, extract what you need and adapt it to your code.