Esempio n. 1
0
batch_size = 128
INCV_epochs = 50
INCV_iter = 4
epochs = 200
INCV_name = 'INCV_ResNet32'
save_dir = 'saved_model'
if not os.path.isdir(save_dir):
    os.makedirs(save_dir)
filepath_INCV = os.path.join(save_dir,INCV_name+'-noisy.h5')

#################################################################################################################################
""" Data preparation """

if dataset=='cifar10':
    x_train, y_train, _, _, x_test, y_test = data.prepare_cifar10_data(data_dir='data/cifar-10-batches-py')
    Num_top = 1 #using top k prediction
    
y_train_noisy = data.flip_label(y_train, pattern=noise_pattern, ratio=noise_ratio, one_hot=True)
input_shape = list(x_train.shape[1:])
n_classes = y_train.shape[1]
n_train = x_train.shape[0]
np.save('y_train_total.npy',y_train)
np.save('y_train_noisy_total.npy',y_train_noisy)
clean_index = np.array([(y_train_noisy[i,:]==y_train[i,:]).all() for i in range(n_train)])# For tracking only, unused during training
noisy_index = np.array([not i for i in clean_index])

# Generator for data augmantation
datagen = ImageDataGenerator(width_shift_range=4./32,  # randomly shift images horizontally (fraction of total width)
                             height_shift_range=4./32,  # randomly shift images vertically (fraction of total height)
                             horizontal_flip=True)  # randomly flip images       
Esempio n. 2
0
INCV_iter = 4  ## number of iterations of INCV
epochs = 200  ## number of epochs of training the network on the new data ( after INCV ) => Co-teaching method
INCV_name = 'INCV_ResNet32'  ## the network used in INCV
save_dir = 'saved_model'
if not os.path.isdir(save_dir):
    os.makedirs(save_dir)
filepath_INCV = os.path.join(save_dir, INCV_name + '-noisy.h5')

## DONE

#################################################################################################################################
""" Data preparation """

if dataset == 'cifar10':
    x_train, y_train, _, _, x_test, y_test = data.prepare_cifar10_data(
        data_dir='data/cifar-10-batches-py'
    )  ## forms the training and testing data
    ## DONE
    Num_top = 1  #using top k prediction
    ## DONE

y_train_noisy = data.flip_label(
    y_train, pattern=noise_pattern, ratio=noise_ratio, one_hot=True
)  ## y_train_noisy is the noisy labels where we randomly change labels of some examples
input_shape = list(
    x_train.shape[1:])  ## shape of the given as input to the models (IMP)
n_classes = y_train.shape[1]
n_train = x_train.shape[0]
np.save('y_train_total.npy', y_train)
np.save('y_train_noisy_total.npy', y_train_noisy)
clean_index = np.array([
Esempio n. 3
0
dataset = args.dataset
batch_size = 128
INCV_epochs = 20
INCV_iter = 4
save_dir = os.path.join('results', dataset, noise_pattern, str(noise_ratio))
#h合并路径
if not os.path.isdir(save_dir):
    os.makedirs(save_dir)  #把路径搞成save_dir
filepath_INCV = os.path.join(save_dir, 'INCV_model.h5')
#弄file_path

####################################################

####################################################
if dataset == 'cifar10':
    x_train, y_train, _, _, x_test, y_test = data.prepare_cifar10_data(
        data_dir='data')
    Num_top = 1  #using top k prediction
elif dataset == 'cifar100':
    x_train, y_train, _, _, x_test, y_test = data.prepare_cifar100_data(
        data_dir='data')
    Num_top = 1  #using top k prediction to select samples


def modify(y_tr, x_tr, x_tst, y_tst, simple_N, noise_pattern, noise_ratio):
    idx0123 = (np.argmax(y_tr, axis=1) <= 3)
    simple_index = range(simple_N)
    x_tr = x_tr[idx0123, :][simple_index, :]
    y_tr = y_tr[idx0123, 0:4][simple_index, 0:4]

    idx0123_test = (np.argmax(y_tst, axis=1) <= 3)
    x_tst = x_tst[idx0123_test, :]