Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such file or directory: 'mmseg/utils/sampler/city_lbl2idx.pth' #5

Open
fangli333 opened this issue Jan 30, 2023 · 2 comments
Open

Comments

@fangli333
Copy link

hi, when i try to reproduce your work for retraining on cityscapes dataset. It seems like I still miss one checkpoint. Can you help me to tackle this problem? thank you!

@whiteinblue
Copy link

the same question ? how to generate file of xx_lbl2idx.pth ?

@leonnnop
Copy link
Owner

Sorry for the confusion and inconvenience caused. In this work, we assume a uniform prior for class probabilities, but in practice, segmentation datasets like ADE20K, Cityscapes, and COCO-Stuff have long-tailed pixel distributions.

To address this issue, we propose a pixel balanced sampler to rebalance the pixel distribution as a uniform distribution. You can find the relevant code for the sampler in the following link:

class BatchBalanceClassSampler(Sampler):
def __init__(
self,
dataset,
cfg
):
"""Sampler initialisation."""
super().__init__(dataset)
logger = get_root_logger()
logger.info(f'Enable Sampling Mode [BALANCE] ')
self._num_classes = 1 # * one class per batch
self._batch_size = 1
self._num_batches = len(dataset) // self._batch_size
self._labels, self.lbl2idx = self.gather_labels(dataset)
def gather_labels(self, dataset):
num_labels = len(dataset.CLASSES)
labels = list(range(num_labels))
_dataset_dict = {
# * only compatible with ADE20K, Cityscapes and COCO-Stuff
# TODO hard-coded: ugly, may fix
150: 'mmseg/utils/sampler/ade_lbl2idx.pth',
19: 'mmseg/utils/sampler/city_lbl2idx.pth',
171: 'mmseg/utils/sampler/cocos_lbl2idx.pth',
}
lbl2idx = torch.load(_dataset_dict[num_labels])
return labels, lbl2idx
def __len__(self) -> int:
"""
Returns:
number of samples in an epoch
"""
return self._num_batches
def __iter__(self) -> Iterator[int]:
"""
Returns:
indeces for sampling dataset elems during an epoch
"""
indices = []
for _ in range(self._num_batches):
cls_id = random.sample(self._labels, self._num_classes)[0]
replace_flag = self._batch_size > len(self.lbl2idx[cls_id])
batch_indices = np.random.choice(
self.lbl2idx[cls_id], self._batch_size, replace=replace_flag
).tolist()
indices.append(batch_indices[0])
return iter(indices)

Regarding the xx_lbl2idx.pth files, they contain the mapping of each label to pixel indexes within the corresponding label class.

We are currently working on releasing both the code for generating these files and the files themselves. Please stay tuned for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants