Hi @jamesp, I’m encountering a similar problem with the latest fastai v1, and I’m afraid I’m still a beginner and have been relying on ImageDataBunch
and its factory methods.
I’ve set up a custom simple CNN:
class SimpleCNN(nn.Module):
def __init__(self, pretrained=False): # `pretrained` kw seems to be needed for `create_cnn`
super(SimpleCNN, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(3, 16, kernel_size=5, padding=2),
nn.BatchNorm2d(16),
nn.ReLU(),
nn.MaxPool2d(2))
self.layer2 = nn.Sequential(
nn.Conv2d(16, 32, kernel_size=5, padding=2),
nn.BatchNorm2d(32),
nn.ReLU(),
nn.MaxPool2d(2))
self.fc = nn.Linear(32*32*32, 1)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.view(out.size(0), -1)
out = self.fc(out)
return out
and then run
learn = create_cnn(data, arch=SimpleCNN, pretrained=False, metrics=[RMSE])
lr = 1e-2
learn.fit_one_cycle(5, slice(lr), pct_start=0.9)
I end up with a long traceback:
TypeError Traceback (most recent call last)
<ipython-input-87-d8be187b950e> in <module>
1 lr = 1e-2
----> 2 learn.fit_one_cycle(5, lr)
~/anaconda3/lib/python3.6/site-packages/fastai/train.py in fit_one_cycle(learn, cyc_len, max_lr, moms, div_factor, pct_start, wd, callbacks, **kwargs)
20 callbacks.append(OneCycleScheduler(learn, max_lr, moms=moms, div_factor=div_factor,
21 pct_start=pct_start, **kwargs))
---> 22 learn.fit(cyc_len, max_lr, wd=wd, callbacks=callbacks)
23
24 def lr_find(learn:Learner, start_lr:Floats=1e-7, end_lr:Floats=10, num_it:int=100, stop_div:bool=True, **kwargs:Any):
~/anaconda3/lib/python3.6/site-packages/fastai/basic_train.py in fit(self, epochs, lr, wd, callbacks)
176 callbacks = [cb(self) for cb in self.callback_fns] + listify(callbacks)
177 fit(epochs, self.model, self.loss_func, opt=self.opt, data=self.data, metrics=self.metrics,
--> 178 callbacks=self.callbacks+callbacks)
179
180 def create_opt(self, lr:Floats, wd:Floats=0.)->None:
~/anaconda3/lib/python3.6/site-packages/fastai/utils/mem.py in wrapper(*args, **kwargs)
83
84 try:
---> 85 return func(*args, **kwargs)
86 except Exception as e:
87 if "CUDA out of memory" in str(e) or tb_clear_frames=="1":
~/anaconda3/lib/python3.6/site-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
98 except Exception as e:
99 exception = e
--> 100 raise e
101 finally: cb_handler.on_train_end(exception)
102
~/anaconda3/lib/python3.6/site-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
93 if not data.empty_val:
94 val_loss = validate(model, data.valid_dl, loss_func=loss_func,
---> 95 cb_handler=cb_handler, pbar=pbar)
96 else: val_loss=None
97 if cb_handler.on_epoch_end(val_loss): break
~/anaconda3/lib/python3.6/site-packages/fastai/basic_train.py in validate(model, dl, loss_func, cb_handler, pbar, average, n_batch)
55 if not is_listy(yb): yb = [yb]
56 nums.append(yb[0].shape[0])
---> 57 if cb_handler and cb_handler.on_batch_end(val_losses[-1]): break
58 if n_batch and (len(nums)>=n_batch): break
59 nums = np.array(nums, dtype=np.float32)
~/anaconda3/lib/python3.6/site-packages/fastai/callback.py in on_batch_end(self, loss)
256 "Handle end of processing one batch with `loss`."
257 self.state_dict['last_loss'] = loss
--> 258 stop = np.any(self('batch_end', not self.state_dict['train']))
259 if self.state_dict['train']:
260 self.state_dict['iteration'] += 1
~/anaconda3/lib/python3.6/site-packages/fastai/callback.py in __call__(self, cb_name, call_mets, **kwargs)
197 def __call__(self, cb_name, call_mets=True, **kwargs)->None:
198 "Call through to all of the `CallbakHandler` functions."
--> 199 if call_mets: [getattr(met, f'on_{cb_name}')(**self.state_dict, **kwargs) for met in self.metrics]
200 return [getattr(cb, f'on_{cb_name}')(**self.state_dict, **kwargs) for cb in self.callbacks]
201
~/anaconda3/lib/python3.6/site-packages/fastai/callback.py in <listcomp>(.0)
197 def __call__(self, cb_name, call_mets=True, **kwargs)->None:
198 "Call through to all of the `CallbakHandler` functions."
--> 199 if call_mets: [getattr(met, f'on_{cb_name}')(**self.state_dict, **kwargs) for met in self.metrics]
200 return [getattr(cb, f'on_{cb_name}')(**self.state_dict, **kwargs) for cb in self.callbacks]
201
~/anaconda3/lib/python3.6/site-packages/fastai/callback.py in on_batch_end(self, last_output, last_target, **kwargs)
291 if not is_listy(last_target): last_target=[last_target]
292 self.count += last_target[0].size(0)
--> 293 self.val += last_target[0].size(0) * self.func(last_output, *last_target).detach().cpu()
294
295 def on_epoch_end(self, **kwargs):
TypeError: object() takes no parameters
Is this at all related to what you’ve discussed above, and or would you be able to supply some simple working code?
Thanks!
EDIT: I have all this in a Jupyter notebook that might be a little more self-explanatory. Ignore the README file since it is referring to fastai v0.7.