本文主要是介绍noisy labels and label smothing,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我要看懂这个代码!!
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as pltnp.random.seed(0) # for reproducibilityX = np.random.randint(0, 3, (32*1100, 10), np.int32) # inputs
Y = np.equal(np.concatenate((np.ones_like(X[:, :1]), np.sign(X[:, :-1])), 1), 0).astype(np.int32) # labels# Split them into training and validation data.
X_train, X_test = np.split(X, [32*1000], axis=0)
Y_train, Y_test = np.split(Y, [32*1000], axis=0)noise_rates=[0., 0.3]
confidence_rates=[0.7., 1.2]
'''corruption rates: A list of two floating numbers.
If a corruption rate is 0, label can be corrupted.'''# Corruption
chances = np.random.uniform(size=(32*1000, 10))
condlist = [np.logical_and(Y_train==0, chances>=noise_rates[0]), np.logical_and(Y_train==0, chances<noise_rates[0]),np.logical_and(Y_train==1, chances>=noise_rates[1]),np.logical_and(Y_train==1, chances<noise_rates[1])]
choicelist = [0, 1, 1, 0]
Z_train = np.select(condlist, choicelist)
Y_train | chances | condlist | Z_train |
0 | 0.2 | [1,1,0,0] | [0,1,0,0] |
0 | 0.8 | [1,0,0,0] | [0,0,0,0] |
1 | 0.2 | [0,0,0,1] | [0,0,0,0] |
1 | 0.8 | [0,0,1,1] | [0,0,1,0] |
np.select类似于condlist跟choicelist取并了。
condlist (4,32000,10) choicelist(32000,10) Z_train (32000,10)
print(Y_train[0])
print(chances[0])
print(Z_train[0])
找出正样本
这篇关于noisy labels and label smothing的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!