mirror of
https://github.com/open-mmlab/mmsegmentation.git
synced 2025-06-03 22:03:48 +08:00
[Fix] Set random seed for generating palette
if not given. (#1152)
* Fix colors * fix comments * Add comments * Add comments. Add random seed in datasets
This commit is contained in:
parent
e0b4f556d4
commit
44d4c3877e
@ -349,7 +349,16 @@ class CustomDataset(Dataset):
|
||||
|
||||
elif palette is None:
|
||||
if self.PALETTE is None:
|
||||
# Get random state before set seed, and restore
|
||||
# random state later.
|
||||
# It will prevent loss of randomness, as the palette
|
||||
# may be different in each iteration if not specified.
|
||||
# See: https://github.com/open-mmlab/mmdetection/issues/5844
|
||||
state = np.random.get_state()
|
||||
np.random.seed(42)
|
||||
# random palette
|
||||
palette = np.random.randint(0, 255, size=(len(class_names), 3))
|
||||
np.random.set_state(state)
|
||||
else:
|
||||
palette = self.PALETTE
|
||||
|
||||
|
@ -245,8 +245,17 @@ class BaseSegmentor(BaseModule, metaclass=ABCMeta):
|
||||
seg = result[0]
|
||||
if palette is None:
|
||||
if self.PALETTE is None:
|
||||
# Get random state before set seed,
|
||||
# and restore random state later.
|
||||
# It will prevent loss of randomness, as the palette
|
||||
# may be different in each iteration if not specified.
|
||||
# See: https://github.com/open-mmlab/mmdetection/issues/5844
|
||||
state = np.random.get_state()
|
||||
np.random.seed(42)
|
||||
# random palette
|
||||
palette = np.random.randint(
|
||||
0, 255, size=(len(self.CLASSES), 3))
|
||||
np.random.set_state(state)
|
||||
else:
|
||||
palette = self.PALETTE
|
||||
palette = np.array(palette)
|
||||
|
Loading…
x
Reference in New Issue
Block a user