Closed oGkgN closed 6 years ago
@oGkgN Good point! We do not yet have an example for tf.keras
models (and I have not yet explored it in detail). I will look into the best solution, but that will take some time as I am currently working towards a deadline. As a first answer I would recommend to look into the foolbox.models.TensorFlowModel
wrapper rather than the KerasModel
wrapper. For the TensorFlowModel
, you need to have the input tensor and the logits tensor. You might easily get them from your tf.keras
model, e.g. I guess the input
and output
attribute (maybe output is after softmax, in which case you try to navigate through the graph to the tensor before the softmax.
I looked into this now. To use a tf.keras
model, the easiest solution is to create a placeholder, apply the model (should return corresponding logits tensor), and then pass the input placeholder and the logits tensor to foolbox.models.TensorFlowModel
.
I leave this open until the documentation for this is improved / an example is added, and maybe we even want to add an alternative constructor to foolbox.models.TensorFlowModel
that directly accepts a tf.keras
model.
foolbox.models.TensorFlowModel
now has an alternative from_keras
constructor that makes this even simpler
Hey,
I'm new to tensorflow and according to this video and also this video it is recommended, that I use
tf.keras
for prototyping and »playing with« machine learning models, especially neural networks. Consider this MWE (lenet5.h5
is a convolutional neural network in HDF5 file format, built and trained by tf.keras):If I comment in the first
network = ...
line and comment out the second line, the result of the above script iswhereas in the current state, the following exceptions occur:
(I replaced my project path by »...« and I'm working with a virtual environment located in .env).
So my question/issue is: How to use foolbox and tf.keras? I would like to avoid needing to learn (for now) the complex tensorflow graph structure and therefore it's not an option to use the native tensorflow api of foolbox. Also I'd like to avoid importing regular keras just for this single purpose – I wish to stay clean within tensorflow.