Giter Site home page Giter Site logo

Comments (10)

schien1729 avatar schien1729 commented on June 23, 2024 1

The issue might be that by default, tf.losses.mean_squared_error aggregates the losses over all the examples it's given. Can you try this instead?

cost = tf.losses.mean_squared_error(labels=y_true,
    predictions=y_pred, reduction=Reduction.NONE
)

from privacy.

schien1729 avatar schien1729 commented on June 23, 2024

Thanks for bringing this up, MADONOKOUKI. Can I ask what the value of batch_size is?

from privacy.

MADONOKOUKI avatar MADONOKOUKI commented on June 23, 2024

@schien1729
Thank you for replying.
batch size is 256

from privacy.

schien1729 avatar schien1729 commented on June 23, 2024

It seems that the code thinks that the loss you're passing (the variable cost) has length 1, and therefore can't split it into two microbatches. cost should be a vector of length 256 (your batch size). Is it possible that you've turned it into a scalar, perhaps by using a reduce function?

from privacy.

MADONOKOUKI avatar MADONOKOUKI commented on June 23, 2024

I took mean squared error due to minimizing the error between input and output.
So I wrote

ae_net = Autoencoder(inputDim, l2scale, compressDims, aeActivation, decompressDims,
                           dataType)  # autoencoder network
clipnorm = 5.0
standard_deviation = 0.0001


# tf Graph input (only pictures)
X = tf.placeholder("float", [None, inputDim])

# Construct model
loss, latent, output  = ae_net(X)
print(output.shape)
# Prediction
y_pred = output
# Targets (Labels) are the input data.
y_true = X

cost = tf.reduce_mean(tf.pow(y_true - y_pred, 2))
print(y_pred)
print(y_true)
cost = tf.losses.mean_squared_error(labels=y_true,
    predictions=y_pred,
)
# Calculate loss as a vector (to support microbatches in DP-SGD).
#vector_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
#labels=y_true, logits=y_pred)

#cost =  tf.reduce_mean(vector_loss)
# optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost) # in medgan
      # Use DP version of GradientDescentOptimizer. For illustration purposes,
      # we do that here by calling optimizer_from_args() explicitly, though DP
      # versions of standard optimizers are available in dp_optimizer.
optimizer = dp_optimizer.DPGradientDescentGaussianOptimizer(
          l2_norm_clip=1.0,
          noise_multiplier=1.1,
          num_microbatches=256,
          learning_rate=.15,
          population_size=60000).minimize(cost)

But is this cost function wrong? In this time, which cost function in tensorflow should I use?

from privacy.

MADONOKOUKI avatar MADONOKOUKI commented on June 23, 2024

Thanks!!!!

cost = tf.losses.mean_squared_error(labels=y_true,
    predictions=y_pred, reduction="none"
)

I can train my code by this function. I can`t import Reduction, So I directlt write "None"

from privacy.

amanoel avatar amanoel commented on June 23, 2024

Hi, I'm having this same error on the MNIST Keras example shipped with the package

ValueError: Dimension size must be evenly divisible by 250 but is 1 for 'training/TFOptimizer/Reshape' (op: 'Reshape') with input shapes: [], [2] and with input tensors computed as partial shapes: input[1] = [250,?].

but only in Tensorflow 1.13, in 1.12 it works fine. Any ideas? Thanks!

from privacy.

npapernot avatar npapernot commented on June 23, 2024

Have you made the one liner modification documented at the top of the MNIST keras example ?

from privacy.

amanoel avatar amanoel commented on June 23, 2024

Sorry, completely missed it :) I just copied the relevant code somewhere else, so I ended up not looking at the docstring.

So I guess this is just #21, never mind my comment!

from privacy.

Viserion-nlper avatar Viserion-nlper commented on June 23, 2024

I also met the same problem
How to solve this problem, please

from privacy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.