Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default session for the TensorFlowModel #37

Closed
ivust opened this issue Jul 18, 2017 · 4 comments
Closed

Default session for the TensorFlowModel #37

ivust opened this issue Jul 18, 2017 · 4 comments
Assignees

Comments

@ivust
Copy link

ivust commented Jul 18, 2017

As I understood from the code (https://github.com/bethgelab/foolbox/blob/master/foolbox/models/tensorflow.py), the constructor of the TensorFlowModel tries to use the default session, otherwise it creates a new one, where all variables need to be reinitialised. That means that if there is a running session with initialised variables in it, then the TensorFlowModel should be created with this session being a default one:

with sess.as_default():
    model = foolbox.models.TensorFlowModel(...)

Maybe that is obvious, but it took me some time to figure what was going on, so you guys may consider adding a note on that to the documentation :-)

@ivust ivust changed the title Default session for the TensorFlow model Default session for the TensorFlowModel Jul 18, 2017
@jonasrauber
Copy link
Member

jonasrauber commented Jul 20, 2017

Thanks Ivan, we certainly need to improve the documentation.

Would you have expected a different syntax to specify a custom session? Maybe we can make it easier to use TensorFlowModel.

@ivust
Copy link
Author

ivust commented Jul 20, 2017

Maybe there could be an optional argument for a user-defined session in the TensorFlowModel:

TensorFlowModel(images, logits, bounds, channel_axis=3, user_session=None)

If no session if provided, then TensorFlowModel can do what it does now, but maybe also throw a warning that a new session has been created and some variables have been initialised to their default values.

@jonasrauber jonasrauber self-assigned this Jul 21, 2017
@jonasrauber
Copy link
Member

I added a new page in the documentation with examples, in particular lot's of examples of the different ways to create a foolbox.models.TensorFlowModel: https://foolbox.readthedocs.io/en/latest/user/examples.html

@ivust What you are using right now is basically Option 4. Have a look at the other options, I think Option 1, Option 2 and Option 3 are nicer.

Your proposal,

session = tf.Session()
restorer.restore(session, '/path/to/vgg_19.ckpt')
model = foolbox.models.TensorFlowModel(images, logits, (0, 255), session=session)
print(np.argmax(model.predictions(image)))
session.close()

is basically a fifth option that's almost identical to Option 3 and therefore will not be implemented for now (I would however accept pull-requests for this, if you really want it).

@jonasrauber
Copy link
Member

Considering this solved. @ivust let me know if I missed something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants