Hi,
When I need to keep my calculations reproducible, shouldn’t I define a decimal point for the cross-entropy error weights? (Such as [1.0, 100.0, 50.0, 30.0, 20.0])
I am working on a semantic segmentation. The training set has 5 different classes. I applied torch.nn.CrossEntropyLoss and set weights option:
def calc_weights(cat0_num, cat1_num, cat2_num, cat3_num, cat4_num):
catnum = \
np.array([cat0_num, cat1_num, cat2_num, cat3_num, cat4_num],
dtype=np.float32)
cat_sum = catnum.sum()
catnum = catnum / cat_sum
catnum = 1.0 / catnum
catnum = np.round(catnum, decimals=5) # !!!decimals=5!!!
catnum = torch.FloatTensor(catnum)
return catnum
But with this setting, the loss value is different every time the calculation is performed.
On the other hand, the following settings always give the same result.
def calc_weights(cat0_num, cat1_num, cat2_num, cat3_num, cat4_num):
catnum = \
np.array([cat0_num, cat1_num, cat2_num, cat3_num, cat4_num], dtype=np.float32)
cat_sum = catnum.sum()
catnum = catnum / cat_sum
catnum = 1.0 / catnum
catnum = np.round(catnum, decimals=0) # !!!decimals=0!!!
catnum = torch.FloatTensor(catnum)
return catnum
Shouldn’t I define a decimal point for the cross-entropy error weights?
I already manually make the model deterministic by setting these properties:
def init_seed(seed=1234):
np.random.seed(seed)
random.seed(seed)
torch.manual_seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
def worker_init_fn(worker_id):
new_seed = np.random.get_state()[1][0] + worker_id
np.random.seed(new_seed)
random.seed(new_seed)
return
Pardon my broken English.
Thanks,
Ryo.