RuntimeError Traceback (most recent call last)
in
1 learn = cnn_learner(dls, resnet18, metrics=error_rate)
----> 2 learn.fine_tune(4)
C:\github\fastai_v4\fastai\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()
C:\github\fastai_v4\fastai\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
C:\github\fastai_v4\fastai\fastai\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
210 self.opt.set_hypers(lr=self.lr if lr is None else lr)
211 self.n_epoch = n_epoch
–> 212 self._with_events(self._do_fit, ‘fit’, CancelFitException, self._end_cleanup)
213
214 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None
C:\github\fastai_v4\fastai\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()
C:\github\fastai_v4\fastai\fastai\learner.py in _do_fit(self)
201 for epoch in range(self.n_epoch):
202 self.epoch=epoch
–> 203 self._with_events(self._do_epoch, ‘epoch’, CancelEpochException)
204
205 def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):
C:\github\fastai_v4\fastai\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()
C:\github\fastai_v4\fastai\fastai\learner.py in _do_epoch(self)
195
196 def _do_epoch(self):
–> 197 self._do_epoch_train()
198 self._do_epoch_validate()
199
C:\github\fastai_v4\fastai\fastai\learner.py in _do_epoch_train(self)
187 def _do_epoch_train(self):
188 self.dl = self.dls.train
–> 189 self._with_events(self.all_batches, ‘train’, CancelTrainException)
190
191 def _do_epoch_validate(self, ds_idx=1, dl=None):
C:\github\fastai_v4\fastai\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()
C:\github\fastai_v4\fastai\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):
C:\github\fastai_v4\fastai\fastai\data\load.py in iter(self)
111 if self.device is not None and multiprocessing.get_start_method().lower() == “fork”:
112 b = to_device(b, self.device)
–> 113 yield self.after_batch(b)
114 self.after_iter()
115 if hasattr(self, ‘it’): del(self.it)
C:\github\fastai_v4\fastcore\fastcore\transform.py in call(self, o)
196 self.fs.append(t)
197
–> 198 def call(self, o): return compose_tfms(o, tfms=self.fs, split_idx=self.split_idx)
199 def repr(self): return f"Pipeline: {’ -> '.join([f.name for f in self.fs if f.name != ‘noop’])}"
200 def getitem(self,i): return self.fs[i]
C:\github\fastai_v4\fastcore\fastcore\transform.py in compose_tfms(x, tfms, is_enc, reverse, **kwargs)
148 for f in tfms:
149 if not is_enc: f = f.decode
–> 150 x = f(x, **kwargs)
151 return x
152
C:\github\fastai_v4\fastcore\fastcore\transform.py in call(self, x, **kwargs)
71 @property
72 def name(self): return getattr(self, ‘_name’, _get_name(self))
—> 73 def call(self, x, **kwargs): return self._call(‘encodes’, x, **kwargs)
74 def decode (self, x, **kwargs): return self._call(‘decodes’, x, **kwargs)
75 def repr(self): return f’{self.name}:\nencodes: {self.encodes}decodes: {self.decodes}’
C:\github\fastai_v4\fastcore\fastcore\transform.py in _call(self, fn, x, split_idx, **kwargs)
81 def _call(self, fn, x, split_idx=None, **kwargs):
82 if split_idx!=self.split_idx and self.split_idx is not None: return x
—> 83 return self._do_call(getattr(self, fn), x, **kwargs)
84
85 def _do_call(self, f, x, **kwargs):
C:\github\fastai_v4\fastcore\fastcore\transform.py in do_call(self, f, x, **kwargs)
88 ret = f.returns(x) if hasattr(f,‘returns’) else None
89 return retain_type(f(x, **kwargs), x, ret)
—> 90 res = tuple(self.do_call(f, x, **kwargs) for x in x)
91 return retain_type(res, x)
92
C:\github\fastai_v4\fastcore\fastcore\transform.py in (.0)
88 ret = f.returns(x) if hasattr(f,‘returns’) else None
89 return retain_type(f(x, **kwargs), x, ret)
—> 90 res = tuple(self.do_call(f, x, **kwargs) for x_ in x)
91 return retain_type(res, x)
92
C:\github\fastai_v4\fastcore\fastcore\transform.py in do_call(self, f, x, **kwargs)
87 if f is None: return x
88 ret = f.returns(x) if hasattr(f,‘returns’) else None
—> 89 return retain_type(f(x, **kwargs), x, ret)
90 res = tuple(self.do_call(f, x, **kwargs) for x in x)
91 return retain_type(res, x)
C:\github\fastai_v4\fastcore\fastcore\dispatch.py in call(self, *args, **kwargs)
116 elif self.inst is not None: f = MethodType(f, self.inst)
117 elif self.owner is not None: f = MethodType(f, self.owner)
–> 118 return f(*args, **kwargs)
119
120 def get(self, inst, owner):
C:\github\fastai_v4\fastai\fastai\data\transforms.py in encodes(self, x)
360 self.mean,self.std = x.mean(self.axes, keepdim=True),x.std(self.axes, keepdim=True)+1e-7
361
–> 362 def encodes(self, x:TensorImage): return (x-self.mean) / self.std
363 def decodes(self, x:TensorImage):
364 f = to_cpu if x.device.type==‘cpu’ else noop
C:\github\fastai_v4\fastai\fastai\torch_core.py in torch_function(self, func, types, args, kwargs)
327 convert=False
328 if _torch_handled(args, self._opt, func): convert,types = type(self),(torch.Tensor,)
–> 329 res = super().torch_function(func, types, args=args, kwargs=kwargs)
330 if convert: res = convert(res)
331 if isinstance(res, TensorBase): res.set_meta(self, as_copy=True)
C:\ProgramData\Anaconda3_2020\envs\fastAI2021\lib\site-packages\torch\tensor.py in torch_function(cls, func, types, args, kwargs)
960
961 with _C.DisableTorchFunction():
–> 962 ret = func(*args, **kwargs)
963 return _convert(ret, cls)
964
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!