lucid
lucid copied to clipboard
Support for tf.keras
As tf.keras
is now the official TF high level API, are there any plans to support models trained in tf.keras
?
Only to note, this seems to be related to the issue i posted #162 . Seems to be that there is no compatibility although the both inherit from TF metaclass.
Hello! Like any TensorFlow model, you can export keras models for visualization using Model.save()
.
(1) Construct the model in your default graph.
(2) Run Model.suggest_save_args()
.
(3) Fill in any arguments that couldn't be inferred, sanity check the others, and call Model.save(...)
Hey @colah . Thank you for the information. I will try it out and will let you know if it works the way as expected
Wonderful! Excited to hear about your experiences!
We just tried this workflow with @ncammarata successfully. One impediment to it working out of the box is that keras doesn't register its session as a default session, which our Model saving code expects.
Temporary(?) workaround:
with K.get_session().as_default():
…
Model.save(…)
…
An additional issue (which may just be me not knowing Keras, like, at all) is that lucid can only deal with an "inference mode" graph, so e.g. no stochastic Dropout at eval time. I'm not sure how/whether one defines different graphs for training and evaluation time in Keras.
@ludwigschubert
Can you please elaborate exactly what I need to do to export my keras model? Do I need to follow the modelzoo tutorial and convert it to a graph def?
Can someone clarify what function is being referred to by Model.save()
Is it tf.keras.Model.save()?
https://www.tensorflow.org/api_docs/python/tf/keras/Model#save
This is lucid's Model.save. I've written up instructions on using it here:
https://github.com/tensorflow/lucid/wiki/Importing-Models-into-Lucid
I am sorry but I am using lucid version 0.3.8 and the Model class imported from lucid.modelzoo.vision_models doesn't have the save or suggest_save_args methods. I used pip to install the lucid package. Do you have any idea what's it can be caused by ?
@colah I have been trying to import my Keras model into Lucid from the "weights.h5" , I have tried to export my model in a compatible format but so far no success.
Do you think you could please provide an example of this part from your instructions:
# <Code to construct & load your model inference graph goes here> # ...
Specifically how to pass from the h5 keras weights to inference graph format compatible with lucid. thank you very much.