Beispiel #1
0
    start = time.time()
    model.fit_generator(generator=my_training_batch_generator,
                          epochs=5,
                          verbose=1,
                          shuffle=True,
                          validation_data=my_validation_batch_generator)

    model.save_weights('/home/shayan/Codes/DenseNet-Keras-master/adversarial_weights_tf_' + str(ib) + '.h5')

    end = time.time()

    train_time = end - start

    start = time.time()

    score = model.evaluate(X_testNP, Y_test, verbose=0)

    print(score[0])
    print(score[1])

    end = time.time()

    test_time = end - start

    f = open("/home/shayan/Codes/DenseNet-Keras-master/Stat_Knowledge_" + str(ib) + ".txt", "w")

    f.write(str(['Test loss: ', score[0]]))
    f.write('\n')

    f.write(str(['Test accuracy: ', score[1]]))
    f.write('\n')
Beispiel #2
0
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())

X_test = np.array(X_test)
Y_test = np.array(Y_test)
Y_test = to_categorical(Y_test)

model.fit_generator(generator=my_training_batch_generator,
                    epochs=1,
                    verbose=1,
                    shuffle=True,
                    validation_data=my_validation_batch_generator)

score = model.evaluate(X_test, Y_test, verbose=0)

X_adv_fgsm = X_test
X_adv_jsma = X_test
X_adv_deepfool = X_test
X_adv_cw = X_test

for i in range(len(X_test)):

    xorg, y0 = X_test[i], Y_test[i]

    xorg = np.expand_dims(xorg, axis=0)

    xadvs = [
        make_fgsm(sess, env, xorg, eps=0, epochs=1),
        make_jsma(sess, env, xorg, eps=0, epochs=1),