I am trying to train a model with multiple outputs of RegressionBlock
s.
The dataset is composed of multiple record
s each of which is a JSON object which looks like:
{'_index': 74,
'_timestamp': 1587330810,
'cam/image_array': '/home/rahulrav/Workspace/Donkey/Simulator/Run-1_2/data/tub_2/images/74_cam_image_array_.jpg',
'track/lap': 0,
'track/loc': 0,
'user/angle': 0.0,
'user/mode': 'user',
'user/throttle': 0.886987566947937,
'_image_base_path': '/home/rahulrav/Workspace/Donkey/Simulator/Run-1_2/data/tub_2/images'}
I am trying to build a model where the input is an image and the output is 2 RegressionBlock
s. Here is the DataBlock
I defined:
def get_records(*args, **kwargs):
return records
def get_x(record):
return record['cam/image_array']
def get_y_1(record):
return record['user/angle']
def get_y_2(record):
return record['user/throttle']
block = DataBlock(blocks=(ImageBlock, RegressionBlock, RegressionBlock),
n_inp=1,
get_items=get_records,
splitter=RandomSplitter(),
get_x = get_x,
get_y = [get_y_1, get_y_2],
item_tfms=Resize(160)
)
loader = block.dataloaders('.')
Next, i tried to load a batch of data.
batch = loader.one_batch()
print(batch[0].shape)
print(batch[1].shape)
print(batch[2].shape)
Gives me:
torch.Size([64, 3, 160, 160])
torch.Size([64])
torch.Size([64])
When I try and create a Learner
for the dataloader
s I run into the following problem:
learner = cnn_learner(loader, resnet34, loss_func=mse)
TypeError Traceback (most recent call last)
<ipython-input-98-667b5ed52417> in <module>
----> 1 learner = cnn_learner(loader, resnet34, loss_func=mse)
~/Workspace/FastAi/fastcore/fastcore/utils.py in _f(*args, **kwargs)
424 log_dict = {**func_args.arguments, **{f'{k} (not in signature)':v for k,v in xtra_kwargs.items()}}
425 log = {f'{f.__qualname__}.{k}':v for k,v in log_dict.items() if k not in but}
--> 426 inst = f(*args, **kwargs) if to_return else args[0]
427 init_args = getattr(inst, 'init_args', {})
428 init_args.update(log)
~/Workspace/FastAi/fastai2/fastai2/vision/learner.py in cnn_learner(dls, arch, loss_func, pretrained, cut, splitter, y_range, config, n_out, normalize, **kwargs)
174 if normalize: _add_norm(dls, meta, pretrained)
175 if y_range is None and 'y_range' in config: y_range = config.pop('y_range')
--> 176 model = create_cnn_model(arch, n_out, ifnone(cut, meta['cut']), pretrained, y_range=y_range, **config)
177 learn = Learner(dls, model, loss_func=loss_func, splitter=ifnone(splitter, meta['split']), **kwargs)
178 if pretrained: learn.freeze()
~/Workspace/FastAi/fastai2/fastai2/vision/learner.py in create_cnn_model(arch, n_out, cut, pretrained, n_in, init, custom_head, concat_pool, **kwargs)
102 if custom_head is None:
103 nf = num_features_model(nn.Sequential(*body.children())) * (2 if concat_pool else 1)
--> 104 head = create_head(nf, n_out, concat_pool=concat_pool, **kwargs)
105 else: head = custom_head
106 model = nn.Sequential(body, head)
~/Workspace/FastAi/fastai2/fastai2/vision/learner.py in create_head(nf, n_out, lin_ftrs, ps, concat_pool, bn_final, lin_first, y_range)
85 if lin_first: layers.append(nn.Dropout(ps.pop(0)))
86 for ni,no,p,actn in zip(lin_ftrs[:-1], lin_ftrs[1:], ps, actns):
---> 87 layers += LinBnDrop(ni, no, bn=True, p=p, act=actn, lin_first=lin_first)
88 if lin_first: layers.append(nn.Linear(lin_ftrs[-2], n_out))
89 if bn_final: layers.append(nn.BatchNorm1d(lin_ftrs[-1], momentum=0.01))
~/Workspace/FastAi/fastai2/fastai2/layers.py in __init__(self, n_in, n_out, bn, p, act, lin_first)
168 layers = [BatchNorm(n_out if lin_first else n_in, ndim=1)] if bn else []
169 if p != 0: layers.append(nn.Dropout(p))
--> 170 lin = [nn.Linear(n_in, n_out, bias=not bn)]
171 if act is not None: lin.append(act)
172 layers = lin+layers if lin_first else layers+lin
~/.virtualenvs/torch/lib/python3.6/site-packages/torch/nn/modules/linear.py in __init__(self, in_features, out_features, bias)
70 self.in_features = in_features
71 self.out_features = out_features
---> 72 self.weight = Parameter(torch.Tensor(out_features, in_features))
73 if bias:
74 self.bias = Parameter(torch.Tensor(out_features))
TypeError: new() received an invalid combination of arguments - got (L, int), but expected one of:
* (torch.device device)
* (torch.Storage storage)
* (Tensor other)
* (tuple of ints size, torch.device device)
didn't match because some of the arguments have invalid types: (L, int)
* (object data, torch.device device)
didn't match because some of the arguments have invalid types: (L, int)
Any ideas on what I might be doing wrong ?