You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Segmented data are exported in COCO Format from CVAT.
The code below was adapted from the UNET Tutorial:
# create a parser
parser=parsers.COCOMaskParser(annotations_filepath=annotation_file, img_dir=images_dir)
class_map=parser.class_map
Output is 100%
# Transforms
# size is set to 384 because EfficientDet requires its inputs to be divisible by 128
image_size = 256
train_tfms = tfms.A.Adapter([*tfms.A.aug_tfms(size=image_size, presize=256), tfms.A.Normalize()])
valid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(image_size), tfms.A.Normalize()])
# Datasets
train_ds = Dataset(train_records, train_tfms)
valid_ds = Dataset(valid_records, valid_tfms)
# Show an element of the train_ds with augmentation transformations applied
samples = [train_ds[0] for _ in range(3)]
show_samples(samples=samples,display_label=False, ncols=3, figsize=(25,10))
Output as expected!
model_type=models.fastai.unet
train_dl = model_type.train_dl(train_ds, batch_size=8, num_workers=0, shuffle=True)
valid_dl = model_type.valid_dl(valid_ds, batch_size=8, num_workers=0, shuffle=False)
backbone = model_type.backbones.resnet34()
model = model_type.model(backbone=backbone, num_classes=class_map.num_classes, img_size=image_size)
# def accuracy_cavid copied into code and was left out here
learn = model_type.fastai.learner(dls=[train_dl, valid_dl], model=model, metrics=[accuracy_camvid])
learn.lr_find()
Results with:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/user/Documents/IceVision/icevision_unet_class.ipynb Cell 15' in <cell line: 1>()
----> 1 learn.lr_find()
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/callback/schedule.py:285, in lr_find(self, start_lr, end_lr, num_it, stop_div, show_plot, suggest_funcs)
[283](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/callback/schedule.py?line=282) n_epoch = num_it//len(self.dls.train) + 1
[284](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/callback/schedule.py?line=283) cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div)
--> [285](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/callback/schedule.py?line=284) with self.no_logging(): self.fit(n_epoch, cbs=cb)
[286](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/callback/schedule.py?line=285) if suggest_funcs is not None:
[287](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/callback/schedule.py?line=286) lrs, losses = tensor(self.recorder.lrs[num_it//10:-5]), tensor(self.recorder.losses[num_it//10:-5])
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:221, in Learner.fit(self, n_epoch, lr, wd, cbs, reset_opt)
[219](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=218) self.opt.set_hypers(lr=self.lr if lr is None else lr)
[220](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=219) self.n_epoch = n_epoch
--> [221](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=220) self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:163, in Learner._with_events(self, f, event_type, ex, final)
[162](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=161) def _with_events(self, f, event_type, ex, final=noop):
--> [163](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=162) try: self(f'before_{event_type}'); f()
[164](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=163) except ex: self(f'after_cancel_{event_type}')
[165](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=164) self(f'after_{event_type}'); final()
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:212, in Learner._do_fit(self)
[210](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=209) for epoch in range(self.n_epoch):
[211](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=210) self.epoch=epoch
--> [212](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=211) self._with_events(self._do_epoch, 'epoch', CancelEpochException)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:163, in Learner._with_events(self, f, event_type, ex, final)
[162](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=161) def _with_events(self, f, event_type, ex, final=noop):
--> [163](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=162) try: self(f'before_{event_type}'); f()
[164](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=163) except ex: self(f'after_cancel_{event_type}')
[165](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=164) self(f'after_{event_type}'); final()
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:206, in Learner._do_epoch(self)
[205](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=204) def _do_epoch(self):
--> [206](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=205) self._do_epoch_train()
[207](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=206) self._do_epoch_validate()
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:198, in Learner._do_epoch_train(self)
[196](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=195) def _do_epoch_train(self):
[197](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=196) self.dl = self.dls.train
--> [198](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=197) self._with_events(self.all_batches, 'train', CancelTrainException)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:163, in Learner._with_events(self, f, event_type, ex, final)
[162](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=161) def _with_events(self, f, event_type, ex, final=noop):
--> [163](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=162) try: self(f'before_{event_type}'); f()
[164](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=163) except ex: self(f'after_cancel_{event_type}')
[165](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=164) self(f'after_{event_type}'); final()
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py:169, in Learner.all_batches(self)
[167](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=166) def all_batches(self):
[168](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=167) self.n_iter = len(self.dl)
--> [169](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/learner.py?line=168) for o in enumerate(self.dl): self.one_batch(*o)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py:109, in DataLoader.__iter__(self)
[107](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=106) self.before_iter()
[108](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=107) self.__idxs=self.get_idxs() # called in context of main process (not workers/subprocesses)
--> [109](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=108) for b in _loaders[self.fake_l.num_workers==0](self.fake_l):
[110](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=109) if self.device is not None: b = to_device(b, self.device)
[111](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=110) yield self.after_batch(b)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py:521, in _BaseDataLoaderIter.__next__(self)
[519](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=518) if self._sampler_iter is None:
[520](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=519) self._reset()
--> [521](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=520) data = self._next_data()
[522](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=521) self._num_yielded += 1
[523](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=522) if self._dataset_kind == _DatasetKind.Iterable and \
[524](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=523) self._IterableDataset_len_called is not None and \
[525](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=524) self._num_yielded > self._IterableDataset_len_called:
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py:561, in _SingleProcessDataLoaderIter._next_data(self)
[559](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=558) def _next_data(self):
[560](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=559) index = self._next_index() # may raise StopIteration
--> [561](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=560) data = self._dataset_fetcher.fetch(index) # may raise StopIteration
[562](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=561) if self._pin_memory:
[563](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/dataloader.py?line=562) data = _utils.pin_memory.pin_memory(data)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py:39, in _IterableDatasetFetcher.fetch(self, possibly_batched_index)
[37](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py?line=36) raise StopIteration
[38](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py?line=37) else:
---> [39](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py?line=38) data = next(self.dataset_iter)
[40](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py?line=39) return self.collate_fn(data)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py:118, in DataLoader.create_batches(self, samps)
[116](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=115) if self.dataset is not None: self.it = iter(self.dataset)
[117](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=116) res = filter(lambda o:o is not None, map(self.do_item, samps))
--> [118](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=117) yield from map(self.do_batch, self.chunkify(res))
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py:[144](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/fastai/data/load.py?line=143), in DataLoader.do_batch(self, b)
--> 144 def do_batch(self, b): return self.retain(self.create_batch(self.before_batch(b)), b)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/engines/fastai/adapters/convert_dataloader_to_fastai.py:18, in convert_dataloader_to_fastai.<locals>.FastaiDataLoaderWithCollate.create_batch(self, b)
[17](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/engines/fastai/adapters/convert_dataloader_to_fastai.py?line=16) def create_batch(self, b):
---> [18](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/engines/fastai/adapters/convert_dataloader_to_fastai.py?line=17) return (dataloader.collate_fn, raise_error_convert)[self.prebatched](b)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py:88, in unload_records.<locals>.inner(records)
[87](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=86) def inner(records):
---> [88](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=87) tupled_output, records = build_batch(records)
[89](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=88) for record in records:
[90](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=89) record.unload()
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py:79, in apply_batch_tfms.<locals>.inner(records)
[77](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=76) if batch_tfms is not None:
[78](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=77) records = batch_tfms(records)
---> [79](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/utils.py?line=78) return build_batch(records, **build_batch_kwargs)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py:59, in build_train_batch(records)
[55](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=54) for record in records:
[56](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=55) # can be optimzed to be converted to tensor once at the end
[57](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=56) tensor_images.append(im2tensor(record.img))
[58](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=57) tensor_masks.append(
---> [59](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=58) tensor(record.segmentation.mask_array.data).long().squeeze()
[60](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=59) )
[62](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=61) tensor_images = torch.stack(tensor_images)
[63](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/models/fastai/unet/dataloaders.py?line=62) tensor_masks = torch.stack(tensor_masks)
File ~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/core/components/composite.py:46, in TaskComposite.__getattr__(self, name)
[43](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/core/components/composite.py?line=42) except KeyError:
[44](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/core/components/composite.py?line=43) pass
---> [46](file:///~/anaconda3/envs/icevision/lib/python3.8/site-packages/icevision/core/components/composite.py?line=45) raise AttributeError(f"{self.__class__.__name__} has no attribute {name}")
AttributeError: BaseRecord has no attribute segmentation
Expected behavior
For it to work...
Screenshots
No applicable screenshots.
Desktop (please complete the following information):
OS: CentOS8
The text was updated successfully, but these errors were encountered:
🐛 Bug
When trying to use instance segmentation with unet, the learn.lr_find() throws this error.
AttributeError: BaseRecord has no attribute segmentation
To Reproduce
Steps to reproduce the behavior:
The code below was adapted from the UNET Tutorial:
Output is 100%
Output as expected!
learn.lr_find()
Results with:
Expected behavior
For it to work...
Screenshots
No applicable screenshots.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: