For the sake of practice, I’m trying to build a model that will get an image of 3 and return an image of 7.
My Xs are 3 tensors my y’s are 7 tensors.
I managed to run the following model which seems to be doing the job:
simple_net = nn.Sequential(
nn.Linear(28*28,30),
nn.ReLU(),
nn.Linear(30,28*28)
)
def loss(p,t):
p=p.sigmoid()
criterion = nn.MSELoss()
return criterion(p, t)
learn=Learner(dls,simple_net,opt_func=SGD,loss_func = loss)
learn.fit(80,0.1)
preds,targs = learn.get_preds()
show_image(preds[11].view(28,28)), show_image(targs[0].view(28,28))
results in this:
However, when I try to use the cnn_learner function I’m getting an error:
learn = cnn_learner(dls, resnet18, pretrained=False,
loss_func=loss)
AssertionError Traceback (most recent call last)
in ()
1 learn = cnn_learner(dls, resnet18, pretrained=False,
----> 2 loss_func=loss)
1 frames
/usr/local/lib/python3.6/dist-packages/fastai/vision/learner.py in cnn_learner(dls, arch, loss_func, pretrained, cut, splitter, y_range, config, n_out, normalize, **kwargs)
170 meta = model_meta.get(arch, _default_meta)
171 if n_out is None: n_out = get_c(dls)
–> 172 assert n_out, "n_out
is not defined, and could not be inferred from data, set dls.c
or pass n_out
"
173 if normalize: _add_norm(dls, meta, pretrained)
174 if y_range is None and ‘y_range’ in config: y_range = config.pop(‘y_range’)
AssertionError: n_out
is not defined, and could not be inferred from data, set dls.c
or pass n_out
Can you please help me figure out how to make the cnn_learner code work?