I have 5 classes arranged in 5 folders for my training set. For my test set, I have image samples in a single folder without any classes at all(not arranged in folders according to class or you can’t extract labels from image name).
NB: Training set is in path
and test set is in unlabelled_path
data = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(valid_pct=0.2, seed=42),
get_y=parent_label,
item_tfms=Resize(224))
dls = data.dataloaders(path).test_dl(get_image_files(unlabelled_path))
learner = cnn_learner(dls, resnet34, metrics = [accuracy],n_out=5)
When I run the cell containing the learning, I get the error
/usr/local/lib/python3.6/dist-packages/fastcore/logargs.py in _f(*args, **kwargs)
50 log_dict = {**func_args.arguments, **{f'{k} (not in signature)':v for k,v in xtra_kwargs.items()}}
51 log = {f'{f.__qualname__}.{k}':v for k,v in log_dict.items() if k not in but}
---> 52 inst = f(*args, **kwargs) if to_return else args[0]
53 init_args = getattr(inst, 'init_args', {})
54 init_args.update(log)
/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)
174 if y_range is None and 'y_range' in config: y_range = config.pop('y_range')
175 model = create_cnn_model(arch, n_out, ifnone(cut, meta['cut']), pretrained, y_range=y_range, **config)
--> 176 learn = Learner(dls, model, loss_func=loss_func, splitter=ifnone(splitter, meta['split']), **kwargs)
177 if pretrained: learn.freeze()
178 return learn
/usr/local/lib/python3.6/dist-packages/fastcore/logargs.py in _f(*args, **kwargs)
54 init_args.update(log)
55 setattr(inst, 'init_args', init_args)
---> 56 return inst if to_return else f(*args, **kwargs)
57 return _f
/usr/local/lib/python3.6/dist-packages/fastai/learner.py in __init__(self, dls, model, loss_func, opt_func, lr, splitter, cbs, metrics, path, model_dir, wd, wd_bn_bias, train_bn, moms)
86 path = Path(path) if path is not None else getattr(dls, 'path', Path('.'))
87 if loss_func is None:
---> 88 loss_func = getattr(dls.train_ds, 'loss_func', None)
89 assert loss_func is not None, "Could not infer loss function from the data, please pass a loss function."
90 self.dls,self.model = dls,model
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __getattr__(self, k)
156 if self._component_attr_filter(k):
157 attr = getattr(self,self._default,None)
--> 158 if attr is not None: return getattr(attr,k)
159 raise AttributeError(k)
160 def __dir__(self): return custom_dir(self,self._dir())
/usr/local/lib/python3.6/dist-packages/fastai/data/core.py in __getattr__(self, k)
315 return res if is_indexer(it) else list(zip(*res))
316
--> 317 def __getattr__(self,k): return gather_attrs(self, k, 'tls')
318 def __dir__(self): return super().__dir__() + gather_attr_names(self, 'tls')
319 def __len__(self): return len(self.tls[0])
/usr/local/lib/python3.6/dist-packages/fastcore/transform.py in gather_attrs(o, k, nm)
163 att = getattr(o,nm)
164 res = [t for t in att.attrgot(k) if t is not None]
--> 165 if not res: raise AttributeError(k)
166 return res[0] if len(res)==1 else L(res)
167
AttributeError: train_ds
Fastai version 2.0.15