コード例 #1
0
################
# Constant
################

################
# Functions
################

################
# main
################
if __name__ == '__main__':
    with tf.Session() as sess:
        # load original data
        data = CIFAR10()
        test = data.X_test

        # load classifier and detectors
        classifier = CIFARModel('../Carlini/models/cifar', sess)
        classifier_dis = CIFARModel('../Carlini/models/cifar-distilled-100',
                                    sess)

        # load attack
        att_org = np.load(sys.argv[1])
        att_dis = np.load(sys.argv[2])
        att_name = sys.argv[3]
        groundtruth = data.y_test[:128]

        # detection and prediction
        apred = np.argmax(classifier.model.predict(att_org), axis=1)
コード例 #2
0
    def softmax(self, x):
        x = x / self.tempreture
        return np.exp(x - np.mean(x)) / np.sum(np.exp(x - np.mean(x)), axis=0)

    def JSD(self, P, Q):
        P = self.softmax(P)
        Q = self.softmax(Q)
        _P = P / norm(P, ord=1)
        _Q = Q / norm(Q, ord=1)
        _M = 0.5 * (_P + _Q)
        return 0.5 * (entropy(_P, _M) + entropy(_Q, _M))


################
# Main
################
if __name__ == '__main__':
    # init
    cifar = CIFAR10()
    detector1 = DetectorI(input_shape=cifar.IMG_SHAPE)
    #detector2 = DetectorII(input_shape=cifar.IMG_SHAPE)
    # classifier
    detector1.train(cifar.X_train,
                    cifar.X_train,
                    cifar.X_test,
                    cifar.X_test,
                    save_path='models/cifar_detector1')
    # autoencoder
    #detector2.train(mnist_move.X_train, mnist_move.X_train, mnist_move.X_test, mnist_move.X_test, save_path='models/detector2_move')