Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vision tutorial failed at learner.fine_tune(1) #3283

Closed
Metal-joker opened this issue Mar 26, 2021 · 5 comments
Closed

vision tutorial failed at learner.fine_tune(1) #3283

Metal-joker opened this issue Mar 26, 2021 · 5 comments
Labels

Comments

@Metal-joker
Copy link

Metal-joker commented Mar 26, 2021

Please confirm you have the latest versions of fastai, fastcore, and nbdev prior to reporting a bug (delete one): YES / NO
YES

Describe the bug
In the 23_tutorial.vision.ipynb notebook, it fails to fine_tune cnn_learner in the section titled: "Cats vs dogs"

To Reproduce
Steps to reproduce the behavior:

  1. open in jupyter lab, run all

Expected behavior
successfully fine tuned model

Error with full stack trace

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-4362f1306de0> in <module>
      1 learn = cnn_learner(dls, resnet34)
----> 2 learn.fine_tune(1)

/opt/conda/lib/python3.7/site-packages/fastai/callback/schedule.py in fine_tune(self, epochs, base_lr, freeze_epochs, lr_mult, pct_start, div, **kwargs)
    155     "Fine tune with `freeze` for `freeze_epochs` then with `unfreeze` from `epochs` using discriminative LR"
    156     self.freeze()
--> 157     self.fit_one_cycle(freeze_epochs, slice(base_lr), pct_start=0.99, **kwargs)
    158     base_lr /= 2
    159     self.unfreeze()

/opt/conda/lib/python3.7/site-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
    110     scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
    111               'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 112     self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
    113 
    114 # Cell

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    209             self.opt.set_hypers(lr=self.lr if lr is None else lr)
    210             self.n_epoch = n_epoch
--> 211             self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
    212 
    213     def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    158 
    159     def _with_events(self, f, event_type, ex, final=noop):
--> 160         try: self(f'before_{event_type}');  f()
    161         except ex: self(f'after_cancel_{event_type}')
    162         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_fit(self)
    200         for epoch in range(self.n_epoch):
    201             self.epoch=epoch
--> 202             self._with_events(self._do_epoch, 'epoch', CancelEpochException)
    203 
    204     def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    158 
    159     def _with_events(self, f, event_type, ex, final=noop):
--> 160         try: self(f'before_{event_type}');  f()
    161         except ex: self(f'after_cancel_{event_type}')
    162         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_epoch(self)
    194 
    195     def _do_epoch(self):
--> 196         self._do_epoch_train()
    197         self._do_epoch_validate()
    198 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_epoch_train(self)
    186     def _do_epoch_train(self):
    187         self.dl = self.dls.train
--> 188         self._with_events(self.all_batches, 'train', CancelTrainException)
    189 
    190     def _do_epoch_validate(self, ds_idx=1, dl=None):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    158 
    159     def _with_events(self, f, event_type, ex, final=noop):
--> 160         try: self(f'before_{event_type}');  f()
    161         except ex: self(f'after_cancel_{event_type}')
    162         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in all_batches(self)
    164     def all_batches(self):
    165         self.n_iter = len(self.dl)
--> 166         for o in enumerate(self.dl): self.one_batch(*o)
    167 
    168     def _do_one_batch(self):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in one_batch(self, i, b)
    182         self.iter = i
    183         self._split(b)
--> 184         self._with_events(self._do_one_batch, 'batch', CancelBatchException)
    185 
    186     def _do_epoch_train(self):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    158 
    159     def _with_events(self, f, event_type, ex, final=noop):
--> 160         try: self(f'before_{event_type}');  f()
    161         except ex: self(f'after_cancel_{event_type}')
    162         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_one_batch(self)
    167 
    168     def _do_one_batch(self):
--> 169         self.pred = self.model(*self.xb)
    170         self('after_pred')
    171         if len(self.yb):

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/container.py in forward(self, input)
    115     def forward(self, input):
    116         for module in self:
--> 117             input = module(input)
    118         return input
    119 

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/container.py in forward(self, input)
    115     def forward(self, input):
    116         for module in self:
--> 117             input = module(input)
    118         return input
    119 

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/conv.py in forward(self, input)
    421 
    422     def forward(self, input: Tensor) -> Tensor:
--> 423         return self._conv_forward(input, self.weight)
    424 
    425 class Conv3d(_ConvNd):

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight)
    418                             _pair(0), self.dilation, self.groups)
    419         return F.conv2d(input, weight, self.bias, self.stride,
--> 420                         self.padding, self.dilation, self.groups)
    421 
    422     def forward(self, input: Tensor) -> Tensor:

TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not list

Additional context
Version Info

Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: fastai in /opt/conda/lib/python3.7/site-packages (2.2.7)
Requirement already satisfied: pyyaml in /opt/conda/lib/python3.7/site-packages (from fastai) (5.3.1)
Requirement already satisfied: fastcore<1.4,>=1.3.8 in /opt/conda/lib/python3.7/site-packages (from fastai) (1.3.19)
Requirement already satisfied: pillow>6.0.0 in /opt/conda/lib/python3.7/site-packages (from fastai) (8.1.0)
Requirement already satisfied: scipy in /opt/conda/lib/python3.7/site-packages (from fastai) (1.4.1)
Requirement already satisfied: packaging in /opt/conda/lib/python3.7/site-packages (from fastai) (20.9)
Requirement already satisfied: pip in /opt/conda/lib/python3.7/site-packages (from fastai) (21.0.1)
Requirement already satisfied: torchvision<0.9,>=0.8 in /opt/conda/lib/python3.7/site-packages (from fastai) (0.8.2)
Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from fastai) (2.25.1)
Requirement already satisfied: torch<1.8,>=1.7.0 in /opt/conda/lib/python3.7/site-packages (from fastai) (1.7.1)
Requirement already satisfied: scikit-learn in /opt/conda/lib/python3.7/site-packages (from fastai) (0.22.1)
Requirement already satisfied: pandas in /opt/conda/lib/python3.7/site-packages (from fastai) (1.2.0)
Requirement already satisfied: spacy<3 in /opt/conda/lib/python3.7/site-packages (from fastai) (2.3.5)
Requirement already satisfied: matplotlib in /opt/conda/lib/python3.7/site-packages (from fastai) (3.3.3)
Requirement already satisfied: fastprogress>=0.2.4 in /opt/conda/lib/python3.7/site-packages (from fastai) (1.0.0)
Requirement already satisfied: numpy in /opt/conda/lib/python3.7/site-packages (from fastprogress>=0.2.4->fastai) (1.19.2)
Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (1.0.5)
Requirement already satisfied: srsly<1.1.0,>=1.0.2 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (1.0.5)
Requirement already satisfied: plac<1.2.0,>=0.9.6 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (1.1.3)
Requirement already satisfied: blis<0.8.0,>=0.4.0 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (0.7.4)
Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (2.0.5)
Requirement already satisfied: catalogue<1.1.0,>=0.0.7 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (1.0.0)
Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (4.55.2)
Requirement already satisfied: thinc<7.5.0,>=7.4.1 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (7.4.5)
Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (52.0.0.post20210125)
Requirement already satisfied: wasabi<1.1.0,>=0.4.0 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (0.8.2)
Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from spacy<3->fastai) (3.0.5)
Requirement already satisfied: importlib-metadata>=0.20 in /opt/conda/lib/python3.7/site-packages (from catalogue<1.1.0,>=0.0.7->spacy<3->fastai) (1.7.0)
Requirement already satisfied: zipp>=0.5 in /opt/conda/lib/python3.7/site-packages (from importlib-metadata>=0.20->catalogue<1.1.0,>=0.0.7->spacy<3->fastai) (3.4.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->fastai) (2020.12.5)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->fastai) (1.26.2)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->fastai) (2.10)
Requirement already satisfied: chardet<5,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->fastai) (3.0.4)
Requirement already satisfied: typing-extensions in /opt/conda/lib/python3.7/site-packages (from torch<1.8,>=1.7.0->fastai) (3.7.4.3)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /opt/conda/lib/python3.7/site-packages (from matplotlib->fastai) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.7/site-packages (from matplotlib->fastai) (0.10.0)
Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/lib/python3.7/site-packages (from matplotlib->fastai) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.7/site-packages (from matplotlib->fastai) (1.3.1)
Requirement already satisfied: six in /opt/conda/lib/python3.7/site-packages (from cycler>=0.10->matplotlib->fastai) (1.15.0)
Requirement already satisfied: pytz>=2017.3 in /opt/conda/lib/python3.7/site-packages (from pandas->fastai) (2021.1)
Requirement already satisfied: joblib>=0.11 in /opt/conda/lib/python3.7/site-packages (from scikit-learn->fastai) (0.17.0)
root@tutorials-0:/ml_workspace# 
@Isaac-Flath
Copy link
Contributor

I opened the notebook in colab and ran all. I did not get an error in colab on fastai 2.2.7 and was not able to replicate.

@Metal-joker
Copy link
Author

I opened the notebook in colab and ran all. I did not get an error in colab on fastai 2.2.7 and was not able to replicate.

I use KVM CPU and Tesla T4 GPU with cuda 10.2. What information do you need to reproduce this, please let me know.

@muellerzr
Copy link
Contributor

@Metal-joker we also need:

Your version of fastai
Your version of fastcore
Your version of torch.

Run:

from fastai.test_utils import show_install
show_install()

And copy its output to here please!

@hamelsmu hamelsmu added the bug label May 1, 2021
@tmabraham
Copy link
Contributor

Original poster has not responded and issue cannot be replicated
@jph00 this can be closed...

@jph00 jph00 closed this as completed May 7, 2022
@zenz
Copy link

zenz commented Jan 4, 2023

I hit the same issue and here's my version info:

=== Software === 
python       : 3.9.15
fastai       : 2.7.10
fastcore     : 1.5.27
fastprogress : 1.0.3
torch        : 1.13.0
torch cuda   : None / is **Not available** 

=== Hardware === 
No GPUs available 

=== Environment === 
platform     : macOS-13.1-arm64-arm-64bit
conda env    : ml
python       : /opt/homebrew/anaconda3/envs/ml/bin/python
sys.path     : /Users/simon/Programs/ML
/opt/homebrew/anaconda3/envs/ml/lib/python39.zip
/opt/homebrew/anaconda3/envs/ml/lib/python3.9
/opt/homebrew/anaconda3/envs/ml/lib/python3.9/lib-dynload
/opt/homebrew/anaconda3/envs/ml/lib/python3.9/site-packages
no supported gpus found on this system

Please make sure to include opening/closing 

And here's my code

from fastai.vision.all import *
path = untar_data(URLs.PETS)/'images'

def is_cat(x): return x[0].isupper()
dls = ImageDataLoaders.from_name_func(
    path, get_image_files(path), valid_pct=0.2, seed=42,
    label_func=is_cat, item_tfms=Resize(224)
)
dls.device=torch.device('mps')
learn = vision_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants