Esempio n. 1
0
def discriminator(x, is_training=True, reuse=None):
    with tf.variable_scope("discriminator", reuse=reuse) as scope:
        # Variables for classifier
        D_W1 = utils.weight_variable([4, 4, 3, K], name="D_W1")
        D_B1 = utils.bias_variable([K], name="D_B1")
        D_W2 = utils.weight_variable([4, 4, K, L], name="D_W2")
        D_B2 = utils.bias_variable([L], name="D_B2")

        D_W3 = utils.weight_variable([8 * 8 * L, M], name="D_W3")
        D_B3 = utils.bias_variable([M], name="D_B3")
        D_W4 = utils.weight_variable([M, 1], name="D_W4")
        D_B4 = utils.bias_variable([1], name="D_B4")

        stride = 2  # output is 16x16
        H1 = lrelu(
            tf.nn.conv2d(
                x, D_W1, strides=[1, stride, stride, 1], padding='SAME') +
            D_B1)
        print(H1.shape)
        stride = 2  # output is 8x8
        H2 = lrelu(
            utils.bn((tf.nn.conv2d(
                H1, D_W2, strides=[1, stride, stride, 1], padding='SAME') +
                      D_B2),
                     is_training=is_training,
                     scope="D_bn_h2"))
        print(H2.shape)

        # reshape the output from the third convolution for the fully connected layer
        HH2 = tf.reshape(H2, shape=[-1, 8 * 8 * L])

        H3 = lrelu(tf.matmul(HH2, D_W3) + D_B3)
        Ylogits = tf.matmul(H3, D_W4) + D_B4

        Ysigmoid = tf.nn.sigmoid(Ylogits)
        Ysoftmax = tf.nn.softmax(Ylogits)

        return Ysoftmax, Ysigmoid, Ylogits
    X_noisy = tf.placeholder(tf.float32, [None, 28, 28, 1])
    X_adv = tf.placeholder(tf.float32, [None, 28, 28, 1])

    GX_ = tf.placeholder(tf.float32, [None, 28, 28, 1])

    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, 10])
    GY = tf.placeholder(tf.float32, [None, 10])

    input_test_sum = tf.summary.image("input", X, 10)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, 10)
    input_adv_sum = tf.summary.image("input-adv", X_adv, 10)

with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([784, L], stddev=0.1, name="C_W1")
    C_W2 = utils.weight_variable([L, M], stddev=0.1, name="C_W2")
    C_W3 = utils.weight_variable([M, 10], stddev=0.1, name="C_W3")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([L], name="C_B1")
        C_B2 = utils.bias_variable([M], name="C_B2")
        C_B3 = utils.bias_variable([10], name="C_B3")

        XX = tf.reshape(x, [-1, 784])
        H1 = tf.nn.sigmoid(tf.matmul(XX, C_W1) + C_B1)
        H2 = tf.nn.sigmoid(tf.matmul(H1, C_W2) + C_B2)
        Ylogits = tf.matmul(H2, C_W3) + C_B3
    X_adv = tf.placeholder(tf.float32, [None, 32, 32, 3])

    GX_ = tf.placeholder(tf.float32, [None, 32, 32, 3])

    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, num_classes])
    GY = tf.placeholder(tf.float32, [None, num_classes])

    input_test_sum = tf.summary.image("input", X, num_classes)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, num_classes)
    input_adv_sum = tf.summary.image("input-adv", X_adv, num_classes)

with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([32 * 32 * 3, num_classes],
                                 stddev=0.1,
                                 name="C_W1")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([num_classes], name="C_B1")

        XX = tf.reshape(x, [-1, 32 * 32 * 3])
        Ylogits = tf.matmul(XX, C_W1) + C_B1

        Ysigmoid = tf.nn.sigmoid(Ylogits)
        Ysoftmax = tf.nn.softmax(Ylogits)

        return Ysoftmax, Ysigmoid, Ylogits
Esempio n. 4
0
    X_noisy = tf.placeholder(tf.float32, [None, 32, 32, 3])
    X_adv = tf.placeholder(tf.float32, [None, 32, 32, 3])

    GX_ = tf.placeholder(tf.float32, [None, 32, 32, 3])

    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, num_classes])
    GY = tf.placeholder(tf.float32, [None, num_classes])

    input_test_sum = tf.summary.image("input", X, num_classes)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, num_classes)
    input_adv_sum = tf.summary.image("input-adv", X_adv, num_classes)

with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([32 * 32 * 3, L], stddev=0.1, name="C_W1")
    C_W2 = utils.weight_variable([L, M], stddev=0.1, name="C_W2")
    C_W3 = utils.weight_variable([M, N], stddev=0.1, name="C_W3")
    C_W4 = utils.weight_variable([N, O], stddev=0.1, name="C_W4")
    C_W5 = utils.weight_variable([O, num_classes], stddev=0.1, name="C_W5")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([L], name="C_B1")
        C_B2 = utils.bias_variable([M], name="C_B2")
        C_B3 = utils.bias_variable([N], name="C_B3")
        C_B4 = utils.bias_variable([O], name="C_B4")
        C_B5 = utils.bias_variable([num_classes], name="C_B5")
    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, 10])
    GY = tf.placeholder(tf.float32, [None, 10])

    # variable learning rate
    lr = tf.placeholder(tf.float32)

    # variable batch size
    BS = tf.placeholder(tf.int32)

    input_test_sum = tf.summary.image("input", X, 10)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, 10)
    input_adv_sum = tf.summary.image("input-adv", X_adv, 10)

with tf.name_scope("classifier-generator"):
    C_W1 = utils.weight_variable([5, 5, 1, K], stddev=0.1, name="C_W1")
    C_W2 = utils.weight_variable([5, 5, K, L], stddev=0.1, name="C_W2")
    C_W3 = utils.weight_variable([4, 4, L, M], stddev=0.1, name="C_W3")

    C_W4 = utils.weight_variable([7 * 7 * M, N], stddev=0.1, name="C_W4")
    C_W5 = utils.weight_variable([N, 10], stddev=0.1, name="C_W5")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([K], name="C_B1")
        C_B2 = utils.bias_variable([L], name="C_B2")
        C_B3 = utils.bias_variable([M], name="C_B3")
        C_B4 = utils.bias_variable([N], name="C_B4")
        C_B5 = utils.bias_variable([10], name="C_B5")
Esempio n. 6
0
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, num_classes)
    input_adv_sum = tf.summary.image("input-adv", X_adv, num_classes)


def sample_Z(m, n):
    return np.random.uniform(-1., 1., size=[m, n])


# From tensorflow-generative-model-collections
def lrelu(x, leak=0.2):
    return tf.maximum(x, leak * x)


with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([4, 4, 3, K], name="C_W1")
    C_W2 = utils.weight_variable([4, 4, K, L], name="C_W2")

    C_W3 = utils.weight_variable([8 * 8 * L, M], name="C_W3")
    C_W4 = utils.weight_variable([M, num_classes], name="C_W4")


def classifier(x, is_training=True, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([K], name="C_B1")
        C_B2 = utils.bias_variable([L], name="C_B2")
        C_B3 = utils.bias_variable([M], name="C_B3")
        C_B4 = utils.bias_variable([num_classes], name="C_B4")

        stride = 2  # output is 16x16
Esempio n. 7
0
    X_noisy = tf.placeholder(tf.float32, [None, 28, 28, 1])
    X_adv = tf.placeholder(tf.float32, [None, 28, 28, 1])

    GX_ = tf.placeholder(tf.float32, [None, 28, 28, 1])

    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, 10])
    GY = tf.placeholder(tf.float32, [None, 10])

    input_test_sum = tf.summary.image("input", X, 10)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, 10)
    input_adv_sum = tf.summary.image("input-adv", X_adv, 10)

with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([784, 10], stddev=0.1, name="C_W1")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([10], name="C_B1")

        XX = tf.reshape(x, [-1, 784])
        Ylogits = tf.matmul(XX, C_W1) + C_B1

        Ysigmoid = tf.nn.sigmoid(Ylogits)
        Ysoftmax = tf.nn.softmax(Ylogits)

        return Ysoftmax, Ysigmoid, Ylogits
Esempio n. 8
0
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, 10)
    input_adv_sum = tf.summary.image("input-adv", X_adv, 10)


def sample_Z(m, n):
    return np.random.uniform(-1., 1., size=[m, n])


# From tensorflow-generative-model-collections
def lrelu(x, leak=0.2):
    return tf.maximum(x, leak * x)


with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([4, 4, 1, K], name="C_W1")
    C_W2 = utils.weight_variable([4, 4, K, L], name="C_W2")

    C_W3 = utils.weight_variable([7 * 7 * L, M], name="C_W3")
    C_W4 = utils.weight_variable([M, Z_dim], name="C_W4")


def classifier(x, is_training=True, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([K], name="C_B1")
        C_B2 = utils.bias_variable([L], name="C_B2")
        C_B3 = utils.bias_variable([M], name="C_B3")
        C_B4 = utils.bias_variable([Z_dim], name="C_B4")

        stride = 2  # output is 14x14
    X_noisy = tf.placeholder(tf.float32, [None, 28, 28, 1])
    X_adv = tf.placeholder(tf.float32, [None, 28, 28, 1])

    GX_ = tf.placeholder(tf.float32, [None, 28, 28, 1])

    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, 10])
    GY = tf.placeholder(tf.float32, [None, 10])

    input_test_sum = tf.summary.image("input", X, 10)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, 10)
    input_adv_sum = tf.summary.image("input-adv", X_adv, 10)

with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([784, L], stddev=0.1, name="C_W1")
    C_W2 = utils.weight_variable([L, M], stddev=0.1, name="C_W2")
    C_W3 = utils.weight_variable([M, N], stddev=0.1, name="C_W3")
    C_W4 = utils.weight_variable([N, O], stddev=0.1, name="C_W4")
    C_W5 = utils.weight_variable([O, 10], stddev=0.1, name="C_W5")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([L], name="C_B1")
        C_B2 = utils.bias_variable([M], name="C_B2")
        C_B3 = utils.bias_variable([N], name="C_B3")
        C_B4 = utils.bias_variable([O], name="C_B4")
        C_B5 = utils.bias_variable([10], name="C_B5")
Esempio n. 10
0
    X_noisy = tf.placeholder(tf.float32, [None, 32, 32, 3])
    X_adv = tf.placeholder(tf.float32, [None, 32, 32, 3])

    GX_ = tf.placeholder(tf.float32, [None, 32, 32, 3])

    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, num_classes])
    GY = tf.placeholder(tf.float32, [None, num_classes])

    input_test_sum = tf.summary.image("input", X, num_classes)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, num_classes)
    input_adv_sum = tf.summary.image("input-adv", X_adv, num_classes)

with tf.name_scope("classifier-generator"):
    # Weights for classifier and generator
    C_W1 = utils.weight_variable([32 * 32 * 3, L], stddev=0.1, name="C_W1")
    C_W2 = utils.weight_variable([L, M], stddev=0.1, name="C_W2")
    C_W3 = utils.weight_variable([M, num_classes], stddev=0.1, name="C_W3")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([L], name="C_B1")
        C_B2 = utils.bias_variable([M], name="C_B2")
        C_B3 = utils.bias_variable([num_classes], name="C_B3")

        XX = tf.reshape(x, [-1, 32 * 32 * 3])
        H1 = tf.nn.sigmoid(tf.matmul(XX, C_W1) + C_B1)
        H2 = tf.nn.sigmoid(tf.matmul(H1, C_W2) + C_B2)
        Ylogits = tf.matmul(H2, C_W3) + C_B3
Esempio n. 11
0
    # output Y_ & input GY: labels for classification and generation
    Y_ = tf.placeholder(tf.float32, [None, num_classes])
    GY = tf.placeholder(tf.float32, [None, num_classes])

    # variable learning rate
    lr = tf.placeholder(tf.float32)

    # variable batch size
    BS = tf.placeholder(tf.int32)

    input_test_sum = tf.summary.image("input", X, num_classes)
    input_noisy_sum = tf.summary.image("input-noisy", X_noisy, num_classes)
    input_adv_sum = tf.summary.image("input-adv", X_adv, num_classes)

with tf.name_scope("classifier-generator"):
    C_W1 = utils.weight_variable([5, 5, 3, K], stddev=0.1, name="C_W1")
    C_W2 = utils.weight_variable([5, 5, K, L], stddev=0.1, name="C_W2")
    C_W3 = utils.weight_variable([4, 4, L, M], stddev=0.1, name="C_W3")

    C_W4 = utils.weight_variable([8 * 8 * M, N], stddev=0.1, name="C_W4")
    C_W5 = utils.weight_variable([N, num_classes], stddev=0.1, name="C_W5")


def classifier(x, reuse=None):
    with tf.variable_scope("classifier", reuse=reuse) as scope_c:
        # Variables for classifier
        C_B1 = utils.bias_variable([K], name="C_B1")
        C_B2 = utils.bias_variable([L], name="C_B2")
        C_B3 = utils.bias_variable([M], name="C_B3")
        C_B4 = utils.bias_variable([N], name="C_B4")
        C_B5 = utils.bias_variable([num_classes], name="C_B5")