in

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: https://github.com/master0fcha0s/lstm-pytorch/blob/master/flights-lstm.ipynb, in fastai v2.

# Costum dataloader 

from torch.utils.data 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):
        super().__init__()
        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

learn.lr_find()

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



Source: https://stackoverflow.com/questions/70720057/fastai-v2-databunch-create-equivalent

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

Very Semple Auto Filter V1 Bot