Comments (11)
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.
Oh right, forgot you can set the learning phase manually. Thanks!
from foolbox.
Do you think it would be better to set it internally and add a parameter to KerasModel?
from foolbox.
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.
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.
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.
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.
@AngusG Can you explain in more detail?
from foolbox.
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.
In principle we could expose this as an argument during the initialisation of the TF model. @jonasrauber What do you think?
from foolbox.
@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)
- Are there any plans to support attacks on TFLite models? HOT 1
- Changing CUDA device at runtime HOT 1
- Logit optimization
- about PGD attack HOT 2
- specifying criterion fails with TypeError HOT 2
- "nll_loss_forward_no_reduce_cuda_kernel_index" not implemented for 'Float' HOT 3
- Deprecation warning using old scipy namespace for gaussian_filter
- how to define the bounds HOT 2
- About the pgd attacks HOT 1
- how to use GaussianBlurAttack HOT 1
- FGSM TargetedMisclassfication HOT 1
- Use foolbox for multi-label classification HOT 1
- Local datasets supported?
- Is there a criterion for query budget? HOT 1
- It seems like the 'success' value in the return of the 'attack' function is overconfident. HOT 2
- About Carlini-Wagner Attack
- Are the wrong classified images sorted out? HOT 1
- It seems your CI/CD has a bug. HOT 1
- How to load datasets that are not among the sample?
- criteria: Misclassification
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foolbox.