Esempio n. 1
0
    y_test = keras.utils.to_categorical(y_test, 10)
    score = model.evaluate(x_test, y_test)
    return score[1]


if __name__=='__main__':
    model_path='../ModelB_raw.hdf5'
    model=load_model(model_path)    
    bound_data_lst = boundary.get_bound_data_mnist(model,10)#第一是第二的10倍以内,算边界值
    unbound_data_lst = boundary.get_unbound_data_mnist(model,10)
    
    path_lst=glob.glob('./mutated/MODEL_B/*.hdf5')
    bound_acc_list=[]#变异模型在边界值集合上的准确率
    unbound_acc_list=[]#变异模型在非边界值集合上的准确率
    acc_list=[]
    print('swj')
    for index,path in enumerate(path_lst):
        print index
        mutant_model=load_model(path)
        acc = accuracy_mnist(mutant_model,mnist)
        acc_list.append(acc)
        bound_acc =boundary.accuracy_in_bound_data_mnist(mutant_model,bound_data_lst)
        unbound_acc =boundary.accuracy_in_unbound_data_mnist(mutant_model,unbound_data_lst)
        bound_acc_list.append(bound_acc)
        unbound_acc_list.append(unbound_acc)
        print bound_acc
        print unbound_acc
        
    name=['normal_acc','bound_acc','unbound_acc']
    dataframe = pd.DataFrame({'normal_acc':acc_list,'bound_acc':bound_acc_list,'unbound_acc':unbound_acc_list})
    dataframe.to_csv('result_model_B.csv')
Esempio n. 2
0
    y_test = keras.utils.to_categorical(y_test, 10)
    score = model.evaluate(x_test, y_test)
    return score[1]


if __name__ == '__main__':
    model_path = '../ModelB_raw.hdf5'
    model = load_model(model_path)
    score = accuracy_mnist(model)
    print('Origin Test accuracy: %.4f' % score)

    bound_data_lst = get_bound_data_mnist(model, 10)
    acclst = []
    index = np.random.choice(200, 50)
    for i in range(50):
        print i
        model_change = neuron_act_inverse(model,
                                          Layer='dense_1',
                                          neuron_index=index[i])
        model_change.compile(loss='categorical_crossentropy',
                             optimizer='sgd',
                             metrics=['accuracy'])
        #print 'Mutated Test accuracy: ',accuracy_cifar(model_change)
        acc = accuracy_in_bound_data_mnist(model_change, bound_data_lst)
        acclst.append(acc)
        model_change.save('mutated/MODEL_B/ModelB_NeuActInv' + str(i) +
                          '.hdf5')
    print 'Mutated accuracy in bound data(dense1):', [
        round(i, 4) for i in acclst
    ]