Fastai v2 – DataBunch.create equivalent

I found a nice repo that uses fastai to train costume model on costume time series data.

However, it uses old version of fastai and thus some methods do not work.

I would like to ask how to replicate this small example:, in fastai v2.

# Costum dataloader 

from import Dataset, DataLoader
class DS(Dataset):
    def __init__(self, X_train, y_train):
        self.X_train = X_train
        self.y_train = y_train

    def __len__(self):
        return len(self.y_train)

    def __getitem__(self, idx):
        data = self.X_train[idx, :]
        labels = self.y_train[idx, :]
        return data, labels

class Model(nn.Module):
    def __init__(self, input_size, hidden_size=100):
        input_size = input_size

        self.lstm1 = nn.LSTM(input_size=input_size, hidden_size=hidden_size, num_layers=1, batch_first=True, bidirectional=False)
        self.lstm2 = nn.LSTM(hidden_size, hidden_size*2, num_layers=1, batch_first=True, bidirectional=False)
        self.fc = nn.Linear(hidden_size*2, 1)
    def forward(self,x):

        # print(x.shape)
        x, _ = self.lstm1(x)
        x, _ = self.lstm2(x)
        # print(x.shape)
        x = self.fc(x)
        # print(x.shape)
        return x

model = Model(input_size=len(train_cols))
db = DataBunch.create(DS(X_train, y_train), valid_ds=None, bs=8)
learn = Learner(db, model, loss_func=nn.MSELoss())

Then, calling


does not work – ‘Model’ object has no attribute ‘lr_find’


LGBTQ Remotely — A job board for remote work for the LGBTQ community

Very Semple Auto Filter V1 Bot