CIFAR–10 Codealong

Codealong of Radek Osmulski's notebook establishing a CIFAR-10 baseline with the Fastai ImageNet WideResNet22. For a Fastai CV research collaboration.

Wayne Nixalo –– 2018/6/1


In [1]:
%matplotlib inline
%reload_ext autoreload
%autoreload 2

In [2]:
from fastai.conv_learner import *
# fastai/imagenet-fast/cifar10/models/ repo
from imagenet_fast_cifar_models.wideresnet import wrn_22
from torchvision import transforms, datasets
# allows you to enable the inbuilt cudnn auto-tuner to find the 
# best algorithm for your hardware. https://discuss.pytorch.org/t/what-does-torch-backends-cudnn-benchmark-do/5936/2
torch.backends.cudnn.benchmark = True
PATH = Path("data/cifar10")

In [3]:
classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck')
stats = (np.array([ 0.4914 ,  0.48216,  0.44653]), np.array([ 0.24703,  0.24349,  0.26159]))

In [4]:
## temp small dataset for fast iteration
# import cifar_utils
# PATH = cifar_utils.create_cifar_subset(PATH, copydirs=['train','test'], p=0.1)
PATH = Path("data/cifar10_tmp")

In [13]:
## Aside: making a small subset of the dataset for fast troubleshooting
## also bc idk how to marry pytorch dataloaders w/ csv's yet.
import cifar_utils
PATH = cifar_utils.create_cifar_subset(PATH, copydirs=['train','test'], p=0.1)

In [4]:
## Aside: checking the normalization transforms
tensor = T(np.ones((3,32,32)))
t1 = transforms.Normalize(stats[0], stats[1])(tensor)
t2 = transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))(tensor)
np.unique(np.isclose(t1, t2))


Out[4]:
array([ True])

We construct the data object manually from low level components in a way that can be used with the fastsai library.


In [5]:
def get_loaders(bs, num_workers):
    traindir = str(PATH/'train')
    valdir   = str(PATH/'test')
    tfms     = [transforms.ToTensor(),
                transforms.Normalize(*stats)]
                #transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))]
    aug_tfms = transforms.Compose([
            transforms.RandomCrop(32, padding=4),
            transforms.RandomHorizontalFlip(),
        ] + tfms)
    
    train_dataset = datasets.ImageFolder(traindir, aug_tfms)
    val_dataset   = datasets.ImageFolder(valdir, transforms.Compose(tfms))
    aug_dataset   = datasets.ImageFolder(valdir, aug_tfms)
    
    train_loader = torch.utils.data.DataLoader(
        train_dataset, batch_size=bs, shuffle=True, num_workers=num_workers, pin_memory=False)
    val_loader   = torch.utils.data.DataLoader(
        val_dataset, batch_size=bs, shuffle=False, num_workers=num_workers, pin_memory=False)
    aug_loader   = torch.utils.data.DataLoader(
        aug_dataset, batch_size=bs, shuffle=False, num_workers=num_workers, pin_memory=False)

    ## NOTE--didnt work: Want automated GPU/CPU handling so using fastai dataloaders
#     train_loader = DataLoader(train_dataset, batch_size=bs, shuffle=True, 
#                               num_workers=num_workers, pin_memory=True)
#     val_loader   = DataLoader(val_dataset, batch_size=bs, shuffle=False,
#                               num_workers=num_workers, pin_memory=True)
#     aug_loader   = DataLoader(aug_dataset, batch_size=bs, shuffle=False,
#                               num_workers=num_workers, pin_memory=True)
    
    return train_loader, val_loader, aug_loader

This is very similar to how Fastai initializes its ModelData, except Fastai uses the Pytorch default pin_memory=False.

What is the disadvantage of using pin_memory? – Pytorch docs:

by pinning your batch in cpu memory, data transfer to gpu can be much faster

Soumith:

pinned memory is page-locked memory. It's easy to shoot yourself in the foot if you enable it for everything because it can't be pre-empted. ... if you're seeing system freeze or swap being used a lot, disable it.


In [6]:
def get_data(bs, num_workers):
    trn_dl, val_dl, aug_dl = get_loaders(bs, num_workers)
    data = ModelData(PATH, trn_dl, val_dl)
    data.aug_dl = aug_dl
    data.sz = 32
    return data

def get_learner(arch, bs):
    learn = ConvLearner.from_model_data(arch.cuda(), get_data(bs, num_cpus()))
    learn.crit = nn.CrossEntropyLoss()
    learn.metrics = [accuracy]
    return learn

def get_TTA_accuracy(learn):
    preds, targs = learn.TTA()
    # combining the predictions across augmented and non augmented inputs
    preds = 0.6 * preds[0] + 0.4 * preds[1:].sum(0)
    return accuracy_np(preds, targs)

WiP Fastai DAWN Bench submission

My copy of Radek's reimplementation of the FastAI DAWN Bench submission in terms of archutecture and training parameters – from the imagenet-fast repo.


In [ ]:
# learner = get_learner(wrn_22(), 512)
# learner.lr_find(wds=1e-4)
# learner.sched.plot(n_skip_end=1)

In [35]:
learner = get_learner(wrn_22(), 16)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) type(torch.max(preds.data, dim=1)[1])
<class 'torch.cuda.LongTensor'>
(Pdb) type(y)
<class 'torch.LongTensor'>
(Pdb) torch.max(preds.data, dim=1)[1]==y
*** TypeError: eq received an invalid combination of arguments - got (torch.LongTensor), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
(Pdb) q
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-35-2267003f658c> in <module>()
      1 learner = get_learner(wrn_22(), 16)
----> 2 learner.lr_find(wds=1e-4)
      3 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in trace_dispatch(self, frame, event, arg)
     49             return # None
     50         if event == 'line':
---> 51             return self.dispatch_line(frame)
     52         if event == 'call':
     53             return self.dispatch_call(frame, arg)

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in dispatch_line(self, frame)
     68         if self.stop_here(frame) or self.break_here(frame):
     69             self.user_line(frame)
---> 70             if self.quitting: raise BdbQuit
     71         return self.trace_dispatch
     72 

BdbQuit: 

In [33]:
learner = get_learner(wrn_22(), 16)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) type(y)
<class 'torch.LongTensor'>
(Pdb) type(x[0])
<class 'torch.FloatTensor'>
(Pdb) type(preds)
<class 'torch.autograd.variable.Variable'>
(Pdb) type(preds.data)
<class 'torch.cuda.FloatTensor'>
(Pdb) q
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-33-2267003f658c> in <module>()
      1 learner = get_learner(wrn_22(), 16)
----> 2 learner.lr_find(wds=1e-4)
      3 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in trace_dispatch(self, frame, event, arg)
     49             return # None
     50         if event == 'line':
---> 51             return self.dispatch_line(frame)
     52         if event == 'call':
     53             return self.dispatch_call(frame, arg)

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in dispatch_line(self, frame)
     68         if self.stop_here(frame) or self.break_here(frame):
     69             self.user_line(frame)
---> 70             if self.quitting: raise BdbQuit
     71         return self.trace_dispatch
     72 

BdbQuit: 

In [32]:
learner = get_learner(wrn_22(), 16)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) torch.max(preds.data,dim=1)[1]==y
*** TypeError: eq received an invalid combination of arguments - got (torch.LongTensor), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
(Pdb) type(torch.max(preds,dim=1)[1])
<class 'torch.autograd.variable.Variable'>
(Pdb) type(torch.max(preds.data,dim=1)[1])
<class 'torch.cuda.LongTensor'>
(Pdb) q
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-32-2267003f658c> in <module>()
      1 learner = get_learner(wrn_22(), 16)
----> 2 learner.lr_find(wds=1e-4)
      3 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in trace_dispatch(self, frame, event, arg)
     49             return # None
     50         if event == 'line':
---> 51             return self.dispatch_line(frame)
     52         if event == 'call':
     53             return self.dispatch_call(frame, arg)

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in dispatch_line(self, frame)
     68         if self.stop_here(frame) or self.break_here(frame):
     69             self.user_line(frame)
---> 70             if self.quitting: raise BdbQuit
     71         return self.trace_dispatch
     72 

BdbQuit: 

In [21]:
learner = get_learner(wrn_22(), 8)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


 97%|█████████▋| 605/625 [00:33<00:01, 18.15it/s, loss=8.86]
 97%|█████████▋| 605/625 [00:50<00:01, 12.10it/s, loss=8.86]

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [8]:
learner = get_learner(wrn_22(), 8)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) preds
*** NameError: name 'preds' is not defined
(Pdb) x.shape
*** AttributeError: 'list' object has no attribute 'shape'
(Pdb) len(x)
1
(Pdb) x
[
( 0 , 0 ,.,.) = 
  0.6301  0.6777  0.7095  ...  -0.6240 -0.7986 -1.0050
  0.4872  0.5984  0.6777  ...   0.1221  0.0904  0.0428
  0.4396  0.4079  0.4714  ...  -0.3541 -0.3382 -0.3859
           ...             ⋱             ...          
 -0.0684 -0.0525 -0.2747  ...   0.0586 -0.1477 -0.3382
 -0.0525 -0.1001 -0.1954  ...   0.0586  0.1221 -0.2271
 -0.0366 -0.0207 -0.1795  ...   0.0110 -0.0525  0.1063

( 0 , 1 ,.,.) = 
  0.3551  0.3712  0.3712  ...  -0.8367 -0.9817 -1.1588
  0.2746  0.3712  0.4195  ...  -0.1281 -0.1442 -0.1764
  0.3068  0.2585  0.3068  ...  -0.3857 -0.3535 -0.3696
           ...             ⋱             ...          
 -0.3052 -0.2891 -0.4985  ...  -0.2730 -0.4502 -0.6112
 -0.3052 -0.3374 -0.4018  ...  -0.2891 -0.2086 -0.5629
 -0.3374 -0.3213 -0.4180  ...  -0.3052 -0.3696 -0.2086

( 0 , 2 ,.,.) = 
 -0.6276 -0.6276 -0.6276  ...  -1.0923 -1.1973 -1.3172
 -0.6276 -0.5527 -0.5077  ...  -0.8675 -0.8525 -0.8675
 -0.5077 -0.5676 -0.5377  ...  -1.0324 -0.9724 -0.9874
           ...             ⋱             ...          
 -0.8825 -0.8525 -1.0024  ...  -0.7625 -0.8825 -0.9574
 -0.8525 -0.8825 -0.8975  ...  -0.8225 -0.6876 -0.9574
 -0.8975 -0.8825 -0.9124  ...  -0.7775 -0.8525 -0.6876
      ⋮  

( 1 , 0 ,.,.) = 
 -1.9416 -1.9416 -1.9416  ...  -1.9416 -1.9416 -1.9416
 -1.9416 -1.9416 -1.9416  ...  -1.9416 -1.9416 -1.9416
 -1.9416 -1.9416 -1.9416  ...  -1.9416 -1.9416 -1.9416
           ...             ⋱             ...          
 -1.9416 -1.9416 -1.9416  ...  -1.9416 -1.9416 -1.9416
 -1.9416 -1.9416 -1.9416  ...  -1.9416 -1.9416 -1.9416
 -1.9416 -1.9416 -1.9416  ...  -1.9416 -1.9416 -1.9416

( 1 , 1 ,.,.) = 
 -1.0944 -1.1105 -1.0944  ...  -1.0944 -1.0944 -1.0944
 -1.1105 -1.1105 -1.1105  ...  -1.1105 -1.1105 -1.1105
 -1.0944 -1.1105 -1.1105  ...  -1.1105 -1.1105 -1.1105
           ...             ⋱             ...          
 -1.0944 -1.1105 -1.1105  ...  -1.1105 -1.1105 -1.1105
 -1.0944 -1.1105 -1.1105  ...  -1.1105 -1.1105 -1.1105
 -1.0944 -1.1105 -1.1105  ...  -1.1105 -1.1105 -1.1105

( 1 , 2 ,.,.) = 
 -0.5826 -0.5976 -0.5976  ...  -0.5976 -0.5976 -0.5976
 -0.5976 -0.6126 -0.6126  ...  -0.6126 -0.6126 -0.6126
 -0.5976 -0.6126 -0.6126  ...  -0.6126 -0.6126 -0.6126
           ...             ⋱             ...          
 -0.5976 -0.6126 -0.6126  ...  -0.6126 -0.6126 -0.6126
 -0.5976 -0.6126 -0.6126  ...  -0.6126 -0.6126 -0.6126
 -0.5976 -0.6126 -0.6126  ...  -0.6126 -0.6126 -0.6126
      ⋮  

( 2 , 0 ,.,.) = 
  0.7889  0.8206  0.9159  ...  -0.3224 -0.3700 -0.4335
  0.8365  0.9000  1.0270  ...  -0.3065 -0.3541 -0.4017
  0.8682  0.9476  1.0587  ...  -0.3065 -0.3541 -0.4017
           ...             ⋱             ...          
  0.1380  0.1539  0.2174  ...  -0.1636 -0.1795 -0.1636
  0.0745  0.1221  0.1698  ...  -0.1319 -0.1477 -0.1636
  0.0428  0.0586  0.0904  ...  -0.1319 -0.1477 -0.1795

( 2 , 1 ,.,.) = 
  0.8544  0.8866  0.9671  ...  -0.0153 -0.0636 -0.0636
  0.9027  0.9671  1.0960  ...   0.0008 -0.0314 -0.0475
  0.9349  1.0154  1.1443  ...   0.0169 -0.0314 -0.0475
           ...             ⋱             ...          
  0.2746  0.2746  0.3390  ...   0.2102  0.1780  0.1457
  0.2585  0.2585  0.2907  ...   0.2102  0.1780  0.1457
  0.2424  0.2263  0.2263  ...   0.1780  0.1618  0.1296

( 2 , 2 ,.,.) = 
  1.2463  1.2763  1.3662  ...   0.7816  0.7366  0.7066
  1.2913  1.3213  1.4562  ...   0.7966  0.7666  0.7516
  1.3213  1.3512  1.4262  ...   0.8116  0.7666  0.7816
           ...             ⋱             ...          
  0.7366  0.7066  0.7216  ...   0.9765  0.9465  0.9315
  0.8116  0.7516  0.7366  ...   0.9765  0.9615  0.9315
  0.8415  0.7516  0.7216  ...   0.9615  0.9465  0.9015
...     
      ⋮  

(509, 0 ,.,.) = 
 -1.8781 -1.7987 -1.6400  ...  -1.6082 -1.6082 -1.6559
 -1.8305 -1.6400 -1.4654  ...  -1.4971 -1.5606 -1.6241
 -1.6559 -1.4654 -1.3860  ...  -1.3384 -1.4177 -1.5447
           ...             ⋱             ...          
 -0.1319 -0.1319 -0.5129  ...  -1.2114 -1.2749 -1.3701
 -0.2112 -0.0366  0.0110  ...  -1.2272 -1.3066 -1.4654
 -0.3065 -0.1160 -0.0049  ...  -1.2907 -1.3542 -1.5130

(509, 1 ,.,.) = 
 -1.9158 -1.8514 -1.6903  ...  -1.8836 -1.8836 -1.8997
 -1.8836 -1.6903 -1.5292  ...  -1.7547 -1.8514 -1.8997
 -1.7225 -1.5292 -1.4487  ...  -1.5292 -1.6420 -1.7869
           ...             ⋱             ...          
 -0.4824 -0.4180 -0.7562  ...  -1.2554 -1.3199 -1.3843
 -0.5951 -0.4180 -0.3696  ...  -1.2716 -1.3521 -1.4648
 -0.6756 -0.5146 -0.4180  ...  -1.3199 -1.3843 -1.5131

(509, 2 ,.,.) = 
 -1.6920 -1.6320 -1.4821  ...  -1.7070 -1.7070 -1.6770
 -1.6620 -1.4971 -1.3322  ...  -1.6020 -1.6770 -1.6770
 -1.5271 -1.3472 -1.2722  ...  -1.4072 -1.4971 -1.5871
           ...             ⋱             ...          
 -0.3878 -0.3428 -0.6726  ...  -1.2123 -1.2572 -1.2722
 -0.4927 -0.3428 -0.2978  ...  -1.1973 -1.2722 -1.3322
 -0.5676 -0.4027 -0.3128  ...  -1.2123 -1.2722 -1.3622
      ⋮  

(510, 0 ,.,.) = 
 -0.8304 -0.9256 -0.9415  ...  -1.0526 -1.0685 -1.0367
 -0.8780 -0.9415 -0.9574  ...  -0.8621 -1.0050 -1.0367
 -0.8621 -0.8939 -0.9574  ...  -0.8145 -0.9256 -0.9891
           ...             ⋱             ...          
 -0.4017 -0.3859 -0.4811  ...  -1.1796 -1.4654 -1.3384
 -0.8939 -0.8939 -0.8939  ...  -0.7192 -1.1637 -1.2590
 -1.0050 -1.1637 -1.2590  ...   0.2967 -0.1319 -0.7986

(510, 1 ,.,.) = 
 -1.0300 -1.1266 -1.1266  ...  -1.1427 -1.2071 -1.1749
 -1.0783 -1.1427 -1.1427  ...  -1.0139 -1.1427 -1.1749
 -1.0622 -1.0944 -1.1588  ...  -1.0139 -1.0783 -1.1266
           ...             ⋱             ...          
 -0.7240 -0.7240 -0.8045  ...  -1.1588 -1.4487 -1.3199
 -1.0783 -1.0783 -1.0783  ...  -0.7240 -1.1427 -1.2393
 -1.1105 -1.2554 -1.3682  ...   0.2746 -0.1119 -0.7884

(510, 2 ,.,.) = 
 -0.8375 -0.9274 -0.9274  ...  -0.9574 -1.0024 -0.9724
 -0.8825 -0.9424 -0.9424  ...  -0.8075 -0.9424 -0.9724
 -0.8675 -0.8975 -0.9574  ...  -0.8075 -0.8825 -0.9274
           ...             ⋱             ...          
 -0.5377 -0.5377 -0.6126  ...  -0.9424 -1.2273 -1.0774
 -0.8225 -0.8375 -0.8375  ...  -0.5227 -0.9424 -1.0024
 -0.8375 -0.9874 -1.0774  ...   0.3918  0.0020 -0.5976
      ⋮  

(511, 0 ,.,.) = 
 -0.8939 -0.9256 -0.8462  ...  -1.2749 -1.4019 -1.4812
 -0.8939 -0.9574 -1.0209  ...  -1.2114 -1.2907 -1.4177
 -0.8145 -0.9415 -1.0209  ...  -1.2749 -1.2590 -1.3066
           ...             ⋱             ...          
  0.1221  0.2809  0.3761  ...  -0.6399 -0.7034 -0.7034
  0.1698  0.2332  0.3602  ...  -0.5922 -0.6875 -0.7192
  0.1698  0.2015  0.3285  ...  -0.5764 -0.6557 -0.6716

(511, 1 ,.,.) = 
 -1.0944 -1.1266 -1.0622  ...  -1.4004 -1.4648 -1.4809
 -1.0944 -1.1588 -1.2393  ...  -1.3199 -1.3360 -1.4165
 -1.0139 -1.1427 -1.2393  ...  -1.3843 -1.3038 -1.2877
           ...             ⋱             ...          
 -0.2086 -0.1764 -0.1281  ...  -0.7401 -0.8206 -0.8206
 -0.1603 -0.1603 -0.0958  ...  -0.7240 -0.8206 -0.8528
 -0.1925 -0.1764 -0.0797  ...  -0.7079 -0.7884 -0.8045

(511, 2 ,.,.) = 
 -0.8825 -0.9124 -0.8375  ...  -1.0923 -1.1523 -1.1973
 -0.8825 -0.9424 -1.0174  ...  -1.0624 -1.0774 -1.1673
 -0.8075 -0.9274 -1.0174  ...  -1.1523 -1.0923 -1.0923
           ...             ⋱             ...          
 -0.0280 -0.0430 -0.0280  ...  -0.5826 -0.6426 -0.6426
  0.0320 -0.0280  0.0170  ...  -0.5676 -0.6576 -0.7026
  0.0170 -0.0280  0.0170  ...  -0.5527 -0.6276 -0.6426
[torch.FloatTensor of size 512x3x32x32]
]
(Pdb) x[0].shape
torch.Size([512, 3, 32, 32])
(Pdb) l
213  	    batch_cnts,loss,res = [],[],[]
214  	    stepper.reset(False)
215  	    with no_grad_context():
216  	        for (*x,y) in iter(dl):
217  	            pdb.set_trace()
218  ->	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) preds
Variable containing:
1.00000e+09 *
 0.3430 -0.4839 -0.0844  ...  -0.0590  0.1992  0.1243
 0.1110 -0.1565 -0.0273  ...  -0.0191  0.0645  0.0401
 1.5416 -2.1788 -0.3765  ...  -0.2625  0.8953  0.5576
          ...             ⋱             ...          
 0.1236 -0.1740 -0.0303  ...  -0.0213  0.0716  0.0447
 1.0842 -1.5281 -0.2646  ...  -0.1856  0.6281  0.3925
 0.1488 -0.2099 -0.0363  ...  -0.0256  0.0861  0.0539
[torch.cuda.FloatTensor of size 512x10 (GPU 0)]

(Pdb) l
214  	    stepper.reset(False)
215  	    with no_grad_context():
216  	        for (*x,y) in iter(dl):
217  	            pdb.set_trace()
218  	            preds, l = stepper.evaluate(VV(x), VV(y))
219  ->	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
224  	
(Pdb) len(y)
512
(Pdb) y[0]
0
(Pdb) y[0].type
*** AttributeError: 'int' object has no attribute 'type'
(Pdb) type(y[0])
<class 'int'>
(Pdb) preds.data.type
<bound method _CudaBase.type of 
1.00000e+09 *
 0.3430 -0.4839 -0.0844  ...  -0.0590  0.1992  0.1243
 0.1110 -0.1565 -0.0273  ...  -0.0191  0.0645  0.0401
 1.5416 -2.1788 -0.3765  ...  -0.2625  0.8953  0.5576
          ...             ⋱             ...          
 0.1236 -0.1740 -0.0303  ...  -0.0213  0.0716  0.0447
 1.0842 -1.5281 -0.2646  ...  -0.1856  0.6281  0.3925
 0.1488 -0.2099 -0.0363  ...  -0.0256  0.0861  0.0539
[torch.cuda.FloatTensor of size 512x10 (GPU 0)]
>
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) n
TypeError: eq received an invalid combination of arguments - got (torch.LongTensor), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) l
217  	            pdb.set_trace()
218  	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  ->	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
224  	
225  	def get_prediction(x):
226  	    if is_listy(x): x=x[0]
227  	    return x.data
(Pdb) y

 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 1
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 2
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 3
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 4
 5
 5
 5
 5
 5
 5
 5
 5
 5
 5
 5
 5
[torch.LongTensor of size 512]

(Pdb) preds.data

1.00000e+09 *
 0.3430 -0.4839 -0.0844  ...  -0.0590  0.1992  0.1243
 0.1110 -0.1565 -0.0273  ...  -0.0191  0.0645  0.0401
 1.5416 -2.1788 -0.3765  ...  -0.2625  0.8953  0.5576
          ...             ⋱             ...          
 0.1236 -0.1740 -0.0303  ...  -0.0213  0.0716  0.0447
 1.0842 -1.5281 -0.2646  ...  -0.1856  0.6281  0.3925
 0.1488 -0.2099 -0.0363  ...  -0.0256  0.0861  0.0539
[torch.cuda.FloatTensor of size 512x10 (GPU 0)]

(Pdb) l
228  	
229  	def predict(m, dl):
230  	    preda,_ = predict_with_targs_(m, dl)
231  	    return np.concatenate(preda)
232  	
233  	def predict_batch(m, x):
234  	    m.eval()
235  	    if hasattr(m, 'reset'): m.reset()
236  	    return m(VV(x))
237  	
238  	def predict_with_targs_(m, dl):
(Pdb) l
239  	    m.eval()
240  	    if hasattr(m, 'reset'): m.reset()
241  	    res = []
242  	    for *x,y in iter(dl): res.append([get_prediction(to_np(m(*VV(x)))),to_np(y)])
243  	    return zip(*res)
244  	
245  	def predict_with_targs(m, dl):
246  	    preda,targa = predict_with_targs_(m, dl)
247  	    return np.concatenate(preda), np.concatenate(targa)
248  	
249  	# From https://github.com/ncullen93/torchsample
(Pdb) n
--Return--
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()->None
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) l
217  	            pdb.set_trace()
218  	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  ->	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
224  	
225  	def get_prediction(x):
226  	    if is_listy(x): x=x[0]
227  	    return x.data
(Pdb) c
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-2b295187dffd> in <module>()
      1 learner = get_learner(wrn_22(), 512)
----> 2 learner.lr_find(wds=1e-4)
      3 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/model.py in <listcomp>(.0)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/metrics.py in accuracy(preds, targs)
      8 def accuracy(preds, targs):
      9     preds = torch.max(preds, dim=1)[1]
---> 10     return (preds==targs).float().mean()
     11 
     12 def accuracy_thresh(thresh):

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/tensor.py in __eq__(self, other)
    358 
    359     def __eq__(self, other):
--> 360         return self.eq(other)
    361 
    362     def __ne__(self, other):

TypeError: eq received an invalid combination of arguments - got (torch.LongTensor), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)

Fastai DAWN Bench submission w/ fastai dataloaders

I've been having trouble getting the pytorch dataloaders above to play nice: for some reason they won't return cuda tensors, only cpu float tensors... but the model is waiting to run on data on the gpu...

I don't want to manually build fastai dataloaders either – since in that case they require a validation split and more low-level thinking that'll distract a lot from wider issues; so I'm using the automated fastai way.


In [18]:
bs=8; sz=32; fulldata=False

In [19]:
aug_tfms   = [RandomFlip(), RandomCrop(32)] # hopefully this is the same as aug_tfms above
tfms       = tfms_from_stats(stats, sz=32, aug_tfms=aug_tfms, pad=4)

if not fulldata:
    # quick prototyping csv (10% dataset)
    val_idxs = get_cv_idxs(n=pd.read_csv(PATH/'tmp.csv').count()[0])
    model_data = ImageClassifierData.from_csv(
        PATH, 'train', PATH/'tmp.csv', bs=bs, tfms=tfms, val_idxs=val_idxs)
else:
    # full dataset
    model_data = ImageClassifierData.from_paths(
        PATH, bs=bs, tfms=tfms, trn_name='train',val_name='test')

In [34]:
learner = ConvLearner.from_model_data(wrn_22(), model_data)
learner.crit = nn.CrossEntropyLoss(); learner.metrics = [accuracy]
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) type(x[0])
<class 'torch.cuda.FloatTensor'>
(Pdb) type(y)
<class 'torch.cuda.LongTensor'>
(Pdb) type(preds), type(preds.data)
(<class 'torch.autograd.variable.Variable'>, <class 'torch.cuda.FloatTensor'>)
(Pdb) torch.cuda.FloatTensor(1) == torch.cuda.LongTensor(1)
*** TypeError: eq received an invalid combination of arguments - got (torch.cuda.LongTensor), but expected one of:
 * (float value)
      didn't match because some of the arguments have invalid types: (torch.cuda.LongTensor)
 * (torch.cuda.FloatTensor other)
      didn't match because some of the arguments have invalid types: (torch.cuda.LongTensor)
(Pdb) type(torch.max(preds.data, dim=1)[1])
<class 'torch.cuda.LongTensor'>
(Pdb) torch.max(preds.data, dim=1)[1]==y

 0
 0
 0
 0
 0
 0
 0
 0
[torch.cuda.ByteTensor of size 8 (GPU 0)]

(Pdb) q
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-34-540bcc4d9c3b> in <module>()
      1 learner = ConvLearner.from_model_data(wrn_22(), model_data)
      2 learner.crit = nn.CrossEntropyLoss(); learner.metrics = [accuracy]
----> 3 learner.lr_find(wds=1e-4)
      4 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in trace_dispatch(self, frame, event, arg)
     49             return # None
     50         if event == 'line':
---> 51             return self.dispatch_line(frame)
     52         if event == 'call':
     53             return self.dispatch_call(frame, arg)

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in dispatch_line(self, frame)
     68         if self.stop_here(frame) or self.break_here(frame):
     69             self.user_line(frame)
---> 70             if self.quitting: raise BdbQuit
     71         return self.trace_dispatch
     72 

BdbQuit: 

In [20]:
learner = ConvLearner.from_model_data(wrn_22(), model_data)
learner.crit = nn.CrossEntropyLoss(); learner.metrics = [accuracy]
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) type(y)
<class 'torch.cuda.LongTensor'>
(Pdb) l
213  	    batch_cnts,loss,res = [],[],[]
214  	    stepper.reset(False)
215  	    with no_grad_context():
216  	        for (*x,y) in iter(dl):
217  	            pdb.set_trace()
218  ->	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) type(preds), type(preds.data)
(<class 'torch.autograd.variable.Variable'>, <class 'torch.cuda.FloatTensor'>)
(Pdb) type(y)
<class 'torch.cuda.LongTensor'>
(Pdb) torch.max(preds.data,dim=1)[1]==y

 0
 0
 0
 0
 0
 0
 0
 0
[torch.cuda.ByteTensor of size 8 (GPU 0)]

(Pdb) type(torch.max(preds.data,dim=1)[1])
<class 'torch.cuda.LongTensor'>
(Pdb) type(preds.data)
<class 'torch.cuda.FloatTensor'>
(Pdb) type(torch.max(preds,dim=1)[1])
<class 'torch.autograd.variable.Variable'>
(Pdb) type(preds.data)
<class 'torch.cuda.FloatTensor'>
(Pdb) type(x)
<class 'list'>
(Pdb) type(x[0])
<class 'torch.cuda.FloatTensor'>
(Pdb) q
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-20-540bcc4d9c3b> in <module>()
      1 learner = ConvLearner.from_model_data(wrn_22(), model_data)
      2 learner.crit = nn.CrossEntropyLoss(); learner.metrics = [accuracy]
----> 3 learner.lr_find(wds=1e-4)
      4 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    217             pdb.set_trace()
    218             preds, l = stepper.evaluate(VV(x), VV(y))
--> 219             if isinstance(x,list): batch_cnts.append(len(x[0]))
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    217             pdb.set_trace()
    218             preds, l = stepper.evaluate(VV(x), VV(y))
--> 219             if isinstance(x,list): batch_cnts.append(len(x[0]))
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in trace_dispatch(self, frame, event, arg)
     49             return # None
     50         if event == 'line':
---> 51             return self.dispatch_line(frame)
     52         if event == 'call':
     53             return self.dispatch_call(frame, arg)

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in dispatch_line(self, frame)
     68         if self.stop_here(frame) or self.break_here(frame):
     69             self.user_line(frame)
---> 70             if self.quitting: raise BdbQuit
     71         return self.trace_dispatch
     72 

BdbQuit: 

In [ ]:


In [ ]:


In [16]:
learner = ConvLearner.from_model_data(wrn_22(), model_data)
learner.crit = nn.CrossEntropyLoss(); learner.metrics = [accuracy]
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) !f
*** NameError: name 'f' is not defined
(Pdb) metrics[0]
<function accuracy at 0x7f11e1985e18>
(Pdb) metrics[0](preds.data,y)
0.216796875
(Pdb) torch.max(preds, dim=1)[1].type()
*** TypeError: type() missing 1 required positional argument: 't'
(Pdb) torch.max(preds, dim=1)[1].shape
torch.Size([512])
(Pdb) torch.max(preds,dim=1)[1][0].type()
*** TypeError: type() missing 1 required positional argument: 't'
(Pdb) torch.max(preds,dim=1)[1]
Variable containing:
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
[torch.cuda.LongTensor of size 512 (GPU 0)]

(Pdb) torch.max(preds,dim=1)[1].type()
*** TypeError: type() missing 1 required positional argument: 't'
(Pdb) torch.max(preds,dim=1)[1].type
<bound method Variable.type of Variable containing:
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
[torch.cuda.LongTensor of size 512 (GPU 0)]
>
(Pdb) torch.max(preds,dim=1)
(Variable containing:
1.00000e+07 *
  4.0392
  4.1468
  5.8601
  4.2385
  2.5417
  2.3997
  6.7867
  1.4630
  3.2100
  2.8931
  4.2387
  1.9264
  1.7660
  4.2974
  3.5536
  4.3952
  4.2509
  1.4900
  2.7522
  4.1528
  1.6523
  4.0332
  2.5563
  7.8511
  2.5951
  5.2292
  2.7871
  5.4395
  1.5079
  5.7303
  2.9879
  2.6084
  2.5021
  2.9332
  2.5833
  2.9209
  3.8904
  2.6388
  3.9448
  4.6829
  4.1853
  3.1159
  2.6777
  4.1759
  4.4718
  3.2736
  3.8347
  6.6849
  4.7905
  4.5519
  4.8166
  3.9791
  3.7505
  2.6857
  4.6101
  3.9275
  3.2797
  1.9143
  4.3791
  5.0744
  2.2947
  3.0366
  4.7892
  1.7009
  4.2721
  2.1616
  6.1062
  4.2583
  4.7483
  2.2848
  3.4242
  3.8705
  3.0482
  4.3295
  2.8899
  5.2279
  1.2939
  2.0133
  2.6952
  3.9301
  2.1392
  5.0359
  2.2762
  1.9056
  3.9361
  3.3380
  4.1366
  3.8850
  1.9464
  1.6275
  1.1332
  2.4347
  4.7174
  1.0255
  2.8924
  3.4944
  5.2467
  5.2033
  4.6731
  4.1017
  2.8707
  4.6318
  3.9577
  3.3028
  4.0394
  5.0349
  4.9115
  1.7352
  3.7047
  2.9537
  3.3333
  1.5916
  2.9056
  1.8495
  2.8557
  2.5761
  2.1842
  4.2391
  4.4220
  4.3321
  2.3082
  1.0021
  1.6003
  3.5566
  2.2080
  3.9518
  2.7927
  3.4402
  1.4958
  2.9433
  3.0189
  2.2666
  2.7982
  0.7563
  4.4271
  3.1653
  2.9158
  4.0148
  4.7931
  2.8310
  1.4889
  3.5334
  2.1111
  1.9951
  2.9841
  2.4514
  5.3923
  2.4297
  1.8448
  2.3624
  1.8193
  4.0746
  2.0032
  2.2156
  0.6427
  3.6544
  3.2578
  1.3094
  2.5165
  2.8164
  3.5352
  2.7617
  2.5843
  2.7862
  2.6705
  3.1346
  2.8763
  3.4317
  2.3481
  2.2851
  1.7128
  2.6810
  4.3486
  2.5157
  4.2040
  2.8797
  4.5223
  3.7462
  3.5710
  1.7610
  2.9465
  2.2358
  3.1578
  3.0342
  3.0258
  2.7155
  4.5942
  2.4239
  3.5239
  3.5165
  3.0127
  1.8420
  2.3173
  3.0509
  3.7355
  2.6433
  3.3377
  2.1024
  2.9569
  1.8387
  3.0211
  3.6281
  3.6596
  3.3525
  3.4230
  1.2629
  2.5152
  3.6331
  2.1226
  1.7768
  1.9869
  1.6915
  3.1805
  1.9227
  3.1678
  2.9217
  1.7854
  2.0939
  1.0813
  0.4801
  0.5215
  3.5181
  0.6203
  1.2593
  1.6636
  2.5947
  1.8433
  4.1036
  5.0927
  3.7639
  3.3053
  2.3909
  0.6393
  2.9871
  0.9227
  4.1248
  1.7063
  1.5592
  2.7090
  3.9170
  4.5646
  1.9737
  4.4900
  1.4862
  1.3106
  1.0591
  1.3503
  2.1723
  2.1597
  1.5250
  2.1176
  1.3116
  3.8520
  0.0981
  4.2215
  2.8420
  2.6666
  1.5994
  1.3512
  3.1406
  0.6855
  2.2787
  2.4757
  4.6460
  4.5660
  3.5282
  1.9017
  3.0963
  4.3984
  1.8432
  1.6055
  3.0375
  2.0950
  0.9761
  4.1820
  2.2198
  2.8790
  4.9339
  1.5121
  1.6779
  2.1806
  2.6497
  2.6244
  1.0528
  3.4162
  1.4728
  0.8946
  3.2822
  1.8100
  3.5642
  0.5455
  4.3148
  4.3589
  1.3286
  2.5447
  1.0925
  3.1856
  2.5596
  2.6316
  2.2522
  2.6919
  1.9401
  1.6299
  1.6143
  2.5138
  0.9610
  1.4898
  1.0330
  0.7806
  0.3259
  2.1185
  1.9897
  3.6021
  1.2962
  2.3490
  2.6854
  2.2567
  1.5482
  2.6440
  2.3902
  2.6999
  2.4743
  4.1317
  2.4322
  2.1577
  3.6693
  2.2753
  2.0241
  4.9596
  2.2538
  0.7364
  2.4466
  1.1256
  2.9355
  1.7880
  1.8567
  4.4149
  3.5812
  2.1494
  2.0412
  2.3207
  2.9271
  3.2637
  3.4287
  1.7866
  4.0233
  0.1972
  1.6670
  4.2291
  3.7243
  2.3640
  1.4458
  2.0193
  2.2186
  2.7212
  3.4317
  1.8559
  1.7986
  2.2249
  1.7322
  1.8666
  2.7539
  1.3703
  2.1029
  1.0872
  2.6710
  4.7443
  4.4875
  3.3779
  1.4821
  1.9450
  4.8744
  2.1207
  2.2023
  1.4788
  2.5534
  0.7420
  3.2247
  2.8397
  2.6337
  1.1705
  1.8599
  2.5587
  3.4528
  2.1315
  0.7695
  1.0192
  4.2159
  4.2155
  1.5510
  1.8026
  1.3693
  2.9695
  1.5121
  1.9879
  1.2064
  2.2649
  0.3128
  3.7007
  2.4266
  1.9813
  3.3304
  1.8824
  4.3359
  2.5438
  1.5596
  0.0757
  0.9548
  2.5032
  1.0830
  3.2142
  2.2675
  2.1074
  2.4667
  2.1432
  1.6317
  3.3118
  4.3614
  0.7218
  1.5744
  4.5823
  1.9724
  0.5444
  1.4634
  2.5024
  0.6535
  1.1691
  1.4516
  0.7050
  1.5802
  4.5908
  2.8527
  3.3740
  1.8508
  1.3525
  2.7861
  0.9436
  1.6482
  0.6425
  0.7836
  1.6971
  1.2879
  3.0431
  1.6493
  1.7211
  1.1465
  0.9232
  2.2191
  1.6158
  2.1208
  0.9932
  1.3308
  0.3839
  2.5328
  2.0631
  0.6964
  4.0689
  0.2792
  1.5710
  5.1742
  2.2566
  2.1692
  0.6453
  2.3390
  0.7107
  0.8291
  1.7323
  2.7984
  0.8137
  1.2285
  0.8222
  2.3836
  3.7223
  0.0113
  0.8234
  1.3945
  2.5440
  1.0062
  0.5311
  1.8373
  1.6700
  0.6279
  3.0612
  3.8628
  0.3725
  1.3641
  1.0644
  1.6457
  2.7249
  1.1325
  0.4460
  0.2412
  4.0414
  1.2680
  0.5675
  1.2743
  1.5024
  1.2551
  1.5439
  0.2576
  1.9348
  1.8410
  3.8517
  1.1343
  1.6551
  2.4885
  2.5944
  1.7619
  2.0735
  3.0587
  2.0447
  1.6318
[torch.cuda.FloatTensor of size 512 (GPU 0)]
, Variable containing:
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
[torch.cuda.LongTensor of size 512 (GPU 0)]
)
(Pdb) type(torch.max(preds,dim=1)[1])
<class 'torch.autograd.variable.Variable'>
(Pdb) len(torch.max(preds,dim=1)[1])
512
(Pdb) torch.max(preds,dim=1)[1].__dict__
{}
(Pdb) preds.type()
*** TypeError: type() missing 1 required positional argument: 't'
(Pdb) len(preds)
512
(Pdb) preds[0]
Variable containing:
1.00000e+07 *
  4.0392
 -8.2422
  1.2356
  1.3654
 -4.5605
 -0.1626
  0.6589
  0.3052
  3.2308
  1.8972
[torch.cuda.FloatTensor of size 10 (GPU 0)]

(Pdb) preds.dtype
*** AttributeError: 'Variable' object has no attribute 'dtype'
(Pdb) preds.__attr__
*** AttributeError: 'Variable' object has no attribute '__attr__'
(Pdb) preds.__dict__
{}
(Pdb) preds.type
<bound method Variable.type of Variable containing:
 4.0392e+07 -8.2422e+07  1.2356e+07  ...   3.0517e+06  3.2308e+07  1.8972e+07
 4.1468e+07 -8.4591e+07  1.2687e+07  ...   3.1213e+06  3.3149e+07  1.9459e+07
 5.8601e+07 -1.1950e+08  1.7922e+07  ...   4.3952e+06  4.6815e+07  2.7472e+07
                ...                   ⋱                   ...                
 3.0587e+07 -6.2361e+07  9.3445e+06  ...   2.2965e+06  2.4433e+07  1.4340e+07
 2.0447e+07 -4.1697e+07  6.2522e+06  ...   1.5346e+06  1.6335e+07  9.5872e+06
 1.6318e+07 -3.3290e+07  4.9899e+06  ...   1.2337e+06  1.3046e+07  7.6617e+06
[torch.cuda.FloatTensor of size 512x10 (GPU 0)]
>
(Pdb) preds[:2]
Variable containing:
1.00000e+07 *
  4.0392 -8.2422  1.2356  1.3654 -4.5605 -0.1626  0.6589  0.3052  3.2308  1.8972
  4.1468 -8.4591  1.2687  1.4020 -4.6809 -0.1678  0.6765  0.3121  3.3149  1.9459
[torch.cuda.FloatTensor of size 2x10 (GPU 0)]

(Pdb) y[:2]

 0
 0
[torch.cuda.LongTensor of size 2 (GPU 0)]

(Pdb) torch.max(preds,dim=1)[1][:2]
Variable containing:
 0
 0
[torch.cuda.LongTensor of size 2 (GPU 0)]

(Pdb) targs[0]
*** NameError: name 'targs' is not defined
(Pdb) l
217  	            pdb.set_trace()
218  	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  ->	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
224  	
225  	def get_prediction(x):
226  	    if is_listy(x): x=x[0]
227  	    return x.data
(Pdb) y[:@]
*** SyntaxError: invalid syntax
(Pdb) torch.max(preds,dim=1)[1][:2]==y[:2]
*** RuntimeError: eq() received an invalid combination of arguments - got (torch.cuda.LongTensor), but expected one of:
 * (float other)
      didn't match because some of the arguments have invalid types: (torch.cuda.LongTensor)
 * (Variable other)
      didn't match because some of the arguments have invalid types: (torch.cuda.LongTensor)
(Pdb) torch.max(preds,dim=1)[1]==y
*** RuntimeError: eq() received an invalid combination of arguments - got (torch.cuda.LongTensor), but expected one of:
 * (float other)
      didn't match because some of the arguments have invalid types: (torch.cuda.LongTensor)
 * (Variable other)
      didn't match because some of the arguments have invalid types: (torch.cuda.LongTensor)
(Pdb) torch.max(preds.data,dim=1)[1][:@]
*** SyntaxError: invalid syntax
(Pdb) torch.max(preds.data,dim=1)[1][:2]

 0
 0
[torch.cuda.LongTensor of size 2 (GPU 0)]

(Pdb) torch.max(preds.data,dim=1)[1][:2]==y[:2]

 1
 1
[torch.cuda.ByteTensor of size 2 (GPU 0)]

(Pdb) preds[:2]
Variable containing:
1.00000e+07 *
  4.0392 -8.2422  1.2356  1.3654 -4.5605 -0.1626  0.6589  0.3052  3.2308  1.8972
  4.1468 -8.4591  1.2687  1.4020 -4.6809 -0.1678  0.6765  0.3121  3.3149  1.9459
[torch.cuda.FloatTensor of size 2x10 (GPU 0)]

(Pdb) preds.data[:2]

1.00000e+07 *
  4.0392 -8.2422  1.2356  1.3654 -4.5605 -0.1626  0.6589  0.3052  3.2308  1.8972
  4.1468 -8.4591  1.2687  1.4020 -4.6809 -0.1678  0.6765  0.3121  3.3149  1.9459
[torch.cuda.FloatTensor of size 2x10 (GPU 0)]

(Pdb) type(preds.data)
<class 'torch.cuda.FloatTensor'>
(Pdb) type(preds)
<class 'torch.autograd.variable.Variable'>
(Pdb) type(y)
<class 'torch.cuda.LongTensor'>
(Pdb) l
228  	
229  	def predict(m, dl):
230  	    preda,_ = predict_with_targs_(m, dl)
231  	    return np.concatenate(preda)
232  	
233  	def predict_batch(m, x):
234  	    m.eval()
235  	    if hasattr(m, 'reset'): m.reset()
236  	    return m(VV(x))
237  	
238  	def predict_with_targs_(m, dl):
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(216)validate()
-> for (*x,y) in iter(dl):
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(217)validate()
-> pdb.set_trace()
(Pdb) c
> /home/ubuntu/Kaukasos/research/fastai/model.py(218)validate()
-> preds, l = stepper.evaluate(VV(x), VV(y))
(Pdb) l
213  	    batch_cnts,loss,res = [],[],[]
214  	    stepper.reset(False)
215  	    with no_grad_context():
216  	        for (*x,y) in iter(dl):
217  	            pdb.set_trace()
218  ->	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(219)validate()
-> if isinstance(x,list): batch_cnts.append(len(x[0]))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(221)validate()
-> loss.append(to_np(l))
(Pdb) n
> /home/ubuntu/Kaukasos/research/fastai/model.py(222)validate()
-> res.append([f(preds.data, y) for f in metrics])
(Pdb) l
217  	            pdb.set_trace()
218  	            preds, l = stepper.evaluate(VV(x), VV(y))
219  	            if isinstance(x,list): batch_cnts.append(len(x[0]))
220  	            else: batch_cnts.append(len(x))
221  	            loss.append(to_np(l))
222  ->	            res.append([f(preds.data, y) for f in metrics])
223  	    return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
224  	
225  	def get_prediction(x):
226  	    if is_listy(x): x=x[0]
227  	    return x.data
(Pdb) type(preds)
<class 'torch.autograd.variable.Variable'>
(Pdb) type(preds.data)
<class 'torch.cuda.FloatTensor'>
(Pdb) type(y)
<class 'torch.cuda.LongTensor'>
(Pdb) type(torch.max(preds.data,dim=1)[1])
<class 'torch.cuda.LongTensor'>
(Pdb) type(torch.max(preds,dim=1)[1])
<class 'torch.autograd.variable.Variable'>
(Pdb) q
---------------------------------------------------------------------------
BdbQuit                                   Traceback (most recent call last)
<ipython-input-16-540bcc4d9c3b> in <module>()
      1 learner = ConvLearner.from_model_data(wrn_22(), model_data)
      2 learner.crit = nn.CrossEntropyLoss(); learner.metrics = [accuracy]
----> 3 learner.lr_find(wds=1e-4)
      4 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    220             else: batch_cnts.append(len(x))
    221             loss.append(to_np(l))
--> 222             res.append([f(preds.data, y) for f in metrics])
    223     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    224 

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in trace_dispatch(self, frame, event, arg)
     49             return # None
     50         if event == 'line':
---> 51             return self.dispatch_line(frame)
     52         if event == 'call':
     53             return self.dispatch_call(frame, arg)

~/src/anaconda3/envs/fastai/lib/python3.6/bdb.py in dispatch_line(self, frame)
     68         if self.stop_here(frame) or self.break_here(frame):
     69             self.user_line(frame)
---> 70             if self.quitting: raise BdbQuit
     71         return self.trace_dispatch
     72 

BdbQuit: 

In [ ]:


In [ ]:


In [ ]:

scrap


In [6]:
DataLoader.__init__


Out[6]:
<function fastai.dataloader.DataLoader.__init__(self, dataset, batch_size=1, shuffle=False, sampler=None, batch_sampler=None, pad_idx=0, num_workers=None, pin_memory=False, drop_last=False, pre_pad=True, half=False, transpose=False, transpose_y=False)>

In [7]:
torch.utils.data.DataLoader.__init__


Out[7]:
<function torch.utils.data.dataloader.DataLoader.__init__(self, dataset, batch_size=1, shuffle=False, sampler=None, batch_sampler=None, num_workers=0, collate_fn=<function default_collate at 0x7f9a854cb048>, pin_memory=False, drop_last=False, timeout=0, worker_init_fn=None)>

In [42]:
def get_loaders(bs, num_workers):
    traindir = str(PATH/'train')
    valdir   = str(PATH/'test')
    tfms     = [transforms.ToTensor(),
                transforms.Normalize(stats[0], stats[1])]
                #transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))]
    aug_tfms = transforms.Compose([
            transforms.RandomCrop(32, padding=4),
            transforms.RandomHorizontalFlip(),
        ] + tfms)
    
    train_dataset = datasets.ImageFolder(traindir, aug_tfms)
    val_dataset   = datasets.ImageFolder(valdir, transforms.Compose(tfms))
    aug_dataset   = datasets.ImageFolder(valdir, aug_tfms)
    
    train_loader = torch.utils.data.DataLoader(
        train_dataset, batch_size=bs, shuffle=True, num_workers=num_workers, pin_memory=False)
    val_loader   = torch.utils.data.DataLoader(
        val_dataset, batch_size=bs, shuffle=False, num_workers=num_workers, pin_memory=False)
    aug_loader   = torch.utils.data.DataLoader(
        aug_dataset, batch_size=bs, shuffle=False, num_workers=num_workers, pin_memory=False)

    ## Want automated GPU/CPU handling so using fastai dataloaders
#     train_loader = DataLoader(train_dataset, batch_size=bs, shuffle=True, 
#                               num_workers=num_workers, pin_memory=True)
#     val_loader   = DataLoader(val_dataset, batch_size=bs, shuffle=False,
#                               num_workers=num_workers, pin_memory=True)
#     aug_loader   = DataLoader(aug_dataset, batch_size=bs, shuffle=False,
#                               num_workers=num_workers, pin_memory=True)
    
    return train_loader, val_loader, aug_loader

In [ ]:


In [130]:
bs=64; sz=32; num_workers=1

traindir = str(PATH/'train')
valdir   = str(PATH/'test')
tfms     = [transforms.ToTensor(),
            transforms.Normalize(stats[0], stats[1])]
            #transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))]
aug_tfms = transforms.Compose([
        transforms.RandomCrop(32, padding=4),
        transforms.RandomHorizontalFlip(),
    ] + tfms)

train_dataset = datasets.ImageFolder(traindir, aug_tfms)
val_dataset   = datasets.ImageFolder(valdir, transforms.Compose(tfms))
aug_dataset   = datasets.ImageFolder(valdir, aug_tfms)

train_loader = torch.utils.data.DataLoader(
    train_dataset, batch_size=bs, shuffle=True, num_workers=num_workers, pin_memory=True)
val_loader   = torch.utils.data.DataLoader(
    val_dataset, batch_size=bs, shuffle=False, num_workers=num_workers, pin_memory=True)
aug_loader   = torch.utils.data.DataLoader(
    aug_dataset, batch_size=bs, shuffle=False, num_workers=num_workers, pin_memory=True)

In [131]:
train_loader.cuda()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-131-e71a52d21156> in <module>()
----> 1 train_loader.cuda()

AttributeError: 'DataLoader' object has no attribute 'cuda'


In [ ]:


In [ ]:


In [132]:
x,y = next(iter(train_loader))

In [133]:
x[0].type()


Out[133]:
'torch.FloatTensor'

In [135]:
type(y[0])


Out[135]:
int

In [29]:
tfms = tfms_from_stats(stats, sz=32)
md   = ImageClassifierData.from_csv(PATH, 'train', PATH/'tmp.csv', tfms=tfms)

In [30]:
next(iter(md.trn_dl))[0].type()


Out[30]:
'torch.cuda.FloatTensor'

In [33]:
md.trn_ds.


Out[33]:
<fastai.dataset.FilesIndexArrayDataset at 0x7f9a54499898>

In [34]:
train_dataset.


Out[34]:
<torchvision.datasets.folder.ImageFolder at 0x7f9a5449ec88>

In [ ]:


In [ ]:


In [13]:
train_loader,_,_ = get_loaders(bs=64, num_workers=1)

In [14]:
next(iter(train_loader))[0].type()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-a5c90ef8ad22> in <module>()
----> 1 next(iter(train_loader))[0].type()

~/Kaukasos/research/fastai/dataloader.py in __iter__(self)
     86                 # avoid py3.6 issue where queue is infinite and can result in memory exhaustion
     87                 for c in chunk_iter(iter(self.batch_sampler), self.num_workers*10):
---> 88                     for batch in e.map(self.get_batch, c):
     89                         yield get_tensor(batch, self.pin_memory, self.half)
     90 

~/src/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/_base.py in result_iterator()
    584                     # Careful not to keep a reference to the popped future
    585                     if timeout is None:
--> 586                         yield fs.pop().result()
    587                     else:
    588                         yield fs.pop().result(end_time - time.time())

~/src/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
    430                 raise CancelledError()
    431             elif self._state == FINISHED:
--> 432                 return self.__get_result()
    433             else:
    434                 raise TimeoutError()

~/src/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

~/src/anaconda3/envs/fastai/lib/python3.6/concurrent/futures/thread.py in run(self)
     54 
     55         try:
---> 56             result = self.fn(*self.args, **self.kwargs)
     57         except BaseException as exc:
     58             self.future.set_exception(exc)

~/Kaukasos/research/fastai/dataloader.py in get_batch(self, indices)
     73 
     74     def get_batch(self, indices):
---> 75         res = self.np_collate([self.dataset[i] for i in indices])
     76         if self.transpose:   res[0] = res[0].T
     77         if self.transpose_y: res[1] = res[1].T

~/Kaukasos/research/fastai/dataloader.py in np_collate(self, batch)
     69             return {key: self.np_collate([d[key] for d in batch]) for key in b}
     70         elif isinstance(b, collections.Sequence):
---> 71             return [self.np_collate(samples) for samples in zip(*batch)]
     72         raise TypeError(("batch must contain numbers, dicts or lists; found {}".format(type(b))))
     73 

~/Kaukasos/research/fastai/dataloader.py in <listcomp>(.0)
     69             return {key: self.np_collate([d[key] for d in batch]) for key in b}
     70         elif isinstance(b, collections.Sequence):
---> 71             return [self.np_collate(samples) for samples in zip(*batch)]
     72         raise TypeError(("batch must contain numbers, dicts or lists; found {}".format(type(b))))
     73 

~/Kaukasos/research/fastai/dataloader.py in np_collate(self, batch)
     70         elif isinstance(b, collections.Sequence):
     71             return [self.np_collate(samples) for samples in zip(*batch)]
---> 72         raise TypeError(("batch must contain numbers, dicts or lists; found {}".format(type(b))))
     73 
     74     def get_batch(self, indices):

TypeError: batch must contain numbers, dicts or lists; found <class 'torch.FloatTensor'>


In [13]:
## Aside: making a small subset of the dataset for fast troubleshooting
## also bc idk how to marry pytorch dataloaders w/ csv's yet.
import cifar_utils
PATH = cifar_utils.create_cifar_subset(PATH, copydirs=['train','test'], p=0.1)

In [28]:
# df.head()

In [38]:
import cifar_utils

In [53]:
df = cifar_utils.generate_csv(PATH)
df.to_csv(PATH/'tmp.csv', index=False)

In [54]:
df = pd.read_csv(PATH/'tmp.csv', index_col=0, header=0, dtype=str)

In [56]:
fnames = df.index.values
# fnames = df.iloc[:,0].values
df.iloc[:,0] = df.iloc[:,0].str.split(' ')
fnames,csv_labels= sorted(fnames), list(df.to_dict().values())[0]

In [60]:
fnames[:10], list(csv_labels.items())[:10]


Out[60]:
(['airplane/10243_airplane.png',
  'airplane/10267_airplane.png',
  'airplane/10297_airplane.png',
  'airplane/1039_airplane.png',
  'airplane/10493_airplane.png',
  'airplane/10681_airplane.png',
  'airplane/10741_airplane.png',
  'airplane/10798_airplane.png',
  'airplane/10989_airplane.png',
  'airplane/11002_airplane.png'],
 [('frog/5176_frog.png', ['frog']),
  ('frog/11728_frog.png', ['frog']),
  ('frog/36842_frog.png', ['frog']),
  ('frog/48940_frog.png', ['frog']),
  ('frog/24519_frog.png', ['frog']),
  ('frog/26268_frog.png', ['frog']),
  ('frog/18585_frog.png', ['frog']),
  ('frog/8564_frog.png', ['frog']),
  ('frog/11404_frog.png', ['frog']),
  ('frog/3311_frog.png', ['frog'])])


In [44]:
learner = get_learner(wrn_22(), 512)

In [45]:
x,y = next(iter(learner.data.trn_dl))

In [46]:
type(x[0]), type(y[0])


Out[46]:
(torch.FloatTensor, int)


In [21]:
next(iter(learner.data.val_dl))[0].type(), next(iter(learner.data.trn_dl))[0].type()


Out[21]:
('torch.FloatTensor', 'torch.FloatTensor')


In [23]:
tfms = tfms_from_stats(stats, sz=32)
md   = ImageClassifierData.from_csv(PATH, 'train', PATH/'tmp.csv', tfms=tfms)

In [26]:
next(iter(md.trn_dl))[0].type()


Out[26]:
'torch.cuda.FloatTensor'

In [ ]:


In [47]:
learner = get_learner(wrn_22(), 512)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)


                                                         
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-47-2b295187dffd> in <module>()
      1 learner = get_learner(wrn_22(), 512)
----> 2 learner.lr_find(wds=1e-4)
      3 learner.sched.plot(n_skip_end=1)

~/Kaukasos/research/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

~/Kaukasos/research/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

~/Kaukasos/research/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    157 
    158         if not all_val:
--> 159             vals = validate(model_stepper, cur_data.val_dl, metrics)
    160             stop=False
    161             for cb in callbacks: stop = stop or cb.on_epoch_end(vals)

~/Kaukasos/research/fastai/model.py in validate(stepper, dl, metrics)
    219             else: batch_cnts.append(len(x))
    220             loss.append(to_np(l))
--> 221             res.append([f(preds.data, y) for f in metrics])
    222     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    223 

~/Kaukasos/research/fastai/model.py in <listcomp>(.0)
    219             else: batch_cnts.append(len(x))
    220             loss.append(to_np(l))
--> 221             res.append([f(preds.data, y) for f in metrics])
    222     return [np.average(loss, 0, weights=batch_cnts)] + list(np.average(np.stack(res), 0, weights=batch_cnts))
    223 

~/Kaukasos/research/fastai/metrics.py in accuracy(preds, targs)
      8 def accuracy(preds, targs):
      9     preds = torch.max(preds, dim=1)[1]
---> 10     return (preds==targs).float().mean()
     11 
     12 def accuracy_thresh(thresh):

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/tensor.py in __eq__(self, other)
    358 
    359     def __eq__(self, other):
--> 360         return self.eq(other)
    361 
    362     def __ne__(self, other):

TypeError: eq received an invalid combination of arguments - got (torch.LongTensor), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)

TypeError: eq received an invalid combination of arguments - got (torch.LongTensor), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)
 * (torch.cuda.LongTensor other)
      didn't match because some of the arguments have invalid types: (torch.LongTensor)

In [ ]:
learner = get_learner(wrn_22(), 512)
learner.lr_find(wds=1e-4)
learner.sched.plot(n_skip_end=1)