Coder Social home page Coder Social logo

Comments (11)

jonasrauber avatar jonasrauber commented on May 24, 2024 1

Can't you just set the learning phase like this before running your code:

import keras
keras.backend.set_learning_phase(0)

For me, this seems to work.

You can also have a look at the example in the readme which actually uses Keras and sets the learning phase: https://github.com/bethgelab/foolbox#example

If I misunderstood the problem or you have an idea how we can improve Foolbox to make it easier to use with Keras, let us know.

from foolbox.

williamwwang avatar williamwwang commented on May 24, 2024

Oh right, forgot you can set the learning phase manually. Thanks!

from foolbox.

jonasrauber avatar jonasrauber commented on May 24, 2024

Do you think it would be better to set it internally and add a parameter to KerasModel?

from foolbox.

williamwwang avatar williamwwang commented on May 24, 2024

That might be a useful feature, though I can't really imagine why a user would want to set the learning phase to 1 while using the KerasModel since it doesn't have any training methods. I think in native Keras, the predict function is implemented with the learning phase set to 0. Maybe you could add learning phase as a parameter with default value 0?

from foolbox.

jonasrauber avatar jonasrauber commented on May 24, 2024

Reopening this until I added code to set the learning phase to 0 by default if it has not been set before. This will also simplify the example in the README and apparently is more intuitive for Keras users.

from foolbox.

jonasrauber avatar jonasrauber commented on May 24, 2024

Looked into this in more detail. Unfortunately, keras does not make it as easy as I thought to set the learning phase from within foolbox because constant learning phase values must be set before creating the keras model. Instead, I would need to feed the learning phase value for every function call and handle several cases separately. I don't think it's worth adding this complexity at the moment, so the recommended way is to just set the learning phase after the keras import as done in the resnet example in the readme.

from foolbox.

AngusG avatar AngusG commented on May 24, 2024

I almost filed a similar issue for the TensorFlow model wrapper, but tf.placeholder_with_default does the job for things like dropout and batch norm.

from foolbox.

wielandbrendel avatar wielandbrendel commented on May 24, 2024

@AngusG Can you explain in more detail?

from foolbox.

AngusG avatar AngusG commented on May 24, 2024

It was just a comment that since feed_dict isn't exposed by the wrapper, an easy workaround if you just need to set a dropout rate or pass a state to the model which is different than in training, is to use the tf.placeholder_with_default mechanism. This was enough for my immediate needs, but it could be nice to let the user provide their own feed_dict for some use cases. I'm not sure what the best way to do that would be while maintaining a framework-neutral API.

from foolbox.

wielandbrendel avatar wielandbrendel commented on May 24, 2024

In principle we could expose this as an argument during the initialisation of the TF model. @jonasrauber What do you think?

from foolbox.

jonasrauber avatar jonasrauber commented on May 24, 2024

@AngusG @wielandbrendel I am not sure I understand the use case. The TensorFlowModel accepts arbitrary tensors (and thus graphs) so that one can specify everything the way one wants to have it during test time. A small example showing how additional feed_dict arguments could help would be nice (preferably in a new GitHub issue); if it's useful we could indeed add this functionality.

from foolbox.

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.