I use editable installations of fastai2
and fastcore
, following the instruction: https://github.com/fastai/fastai2
The following code ran into the error:
Learner' object has no attribute 'pbar'
Any one encountered the same error?
fastcore version: 0.1.17
fastai2 version: 0.0.17
pytorch version: 1.4.0
Appendix:
Full code:
import fastai2
from fastai2.vision.all import *
import numpy as np
import torch
path = untar_data(URLs.MNIST_SAMPLE)
threes = (path/'train'/'3').ls().sorted()
sevens = (path/'train'/'7').ls().sorted()
stacked_threes = torch.stack(
tensors=[torch.tensor(np.array(Image.open(i))).float() / 255. for i in threes],
dim=0
)
stacked_sevens = torch.stack(
tensors=[torch.tensor(np.array(Image.open(i))).float() / 255. for i in sevens],
dim=0
)
train_x = torch.cat([stacked_threes, stacked_sevens]).view(-1, 28 * 28)
train_y = torch.tensor([1] * stacked_threes.shape[0] + [0] * stacked_sevens.shape[0]).unsqueeze(1)
train_dset = list(zip(train_x, train_y))
train_dl = DataLoader(train_dset, batch_size=256, shuffle=True)
def mnist_binary_loss(logits, targets):
preds = logits.sigmoid()
return torch.where(targets == 1, 1.0 - preds, preds).mean()
def batch_accuracy(logits, yb):
correct = (logits > 0) == yb
return correct.float().mean()
dls = DataLoader(train_dl)
learn = Learner(
dls,
nn.Linear(28 * 28, 1),
opt_func=SGD,
loss_func=mnist_binary_loss,
metrics=batch_accuracy
)
learn.fit(20, 0.1)