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

Output Not Captured #7

Closed
terrytangyuan opened this issue Feb 11, 2017 · 16 comments
Closed

Output Not Captured #7

terrytangyuan opened this issue Feb 11, 2017 · 16 comments

Comments

@terrytangyuan
Copy link
Contributor

See this part of the code: https://github.com/rstudio/tflearn/blob/master/tests/testthat/test-hooks.R#L17
where the output doesn't seem to be captured using py_capture_stdout. Is this the correct way to use it? The capture.output from R only captures the output for the return value of linear_dnn_combined_regression. Is py_capture_stdout able to capture loggings from TF?

@terrytangyuan
Copy link
Contributor Author

Seems like probably an issue regarding how TF tells whether RStudio is an interactive environment. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/tf_logging.py#L55
Perhaps we can also have a function for capturing standard error which is where logs in non-interactive environment go to.

@jjallaire
Copy link
Member

Yes, py_capture_output only captures output. We do however already have some hooks to interact with the TF logging system (we use them in py_suppress_warnings. If you let me know exactly the behavior you want here (perhaps with a simple repro) I can make some combination of py_capture_output and py_suppress_warnings make it happen.

@terrytangyuan
Copy link
Contributor Author

Oh I see. Yea I am expecting the following as part of the output:

INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Saving checkpoints for 2 into /var/folders/ln/c7r_x26x46b7vzpftbfh64zc0000gp/T//RtmpbD66eR/tflearn_a32c5e4d2404/model.ckpt.
INFO:tensorflow:loss = 438.822, step = 2
INFO:tensorflow:global_step = 2
INFO:tensorflow:global_step = 6 (0.016 sec)
INFO:tensorflow:global_step = 10 (0.002 sec)

@jjallaire
Copy link
Member

I think the problem may be here:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/tf_logging.py#L39-L56

You can that TF is trying to determine whether the session is interactive. In the case that it is it will pipe output to stdout (which we could then capture) however in the case where it's not it sends it to stderr. That relies on the state of sys.flags.interactive which we maybe able to set by passing the correct command line flag to startup.

@jjallaire
Copy link
Member

Okay, the function is now renamed py_capture_output. By default it captures both stdout and stderr but it can be configured to capture just one or the other:

2071de8

This should get you what you are looking for, let me know if it doesn't.

@terrytangyuan
Copy link
Contributor Author

Thanks, will try!

@jjallaire
Copy link
Member

Closing this. Feel free to re-open if you have additional issues.

@terrytangyuan
Copy link
Contributor Author

Just gave it a try. Still looks like not able to capture those output. Not a blocker though.

@jjallaire
Copy link
Member

jjallaire commented Feb 15, 2017 via email

@jjallaire jjallaire reopened this Feb 15, 2017
@terrytangyuan
Copy link
Contributor Author

Here it is:

> output <- reticulate::py_capture_output(tf$logging$warn("asdf"))
WARNING:tensorflow:asdf
> output
[1] ""

@jjallaire
Copy link
Member

Interesting, for me this actually successfully captures the output! Here's my exact code as executed (I think it's the same):

library(tensorflow)
output <- reticulate::py_capture_output(tf$logging$warn("asdf"))

Are you certain you've upgraded to the latest versions of tensorflow and reticulate?

@terrytangyuan
Copy link
Contributor Author

Yes, I've removed all packages and reinstalled everything. Otherwise py_capture_output won't be available in old versions.

@jjallaire
Copy link
Member

jjallaire commented Feb 17, 2017 via email

@terrytangyuan
Copy link
Contributor Author

Okay apologize that I didn't clean up my environment properly. That one worked as expected. However, here's what's weird:

> library(tensorflow)
> tf$logging$get_verbosity()
[1] 30
> tf$logging$WARN
[1] 30
> tf$logging$set_verbosity(tf$logging$INFO)
> tf$logging$get_verbosity()
[1] 20
> output <- reticulate::py_capture_output(tf$logging$info("asdf"))
INFO:tensorflow:asdf
> output
[1] ""

Verbosity is set to info correctly but the output is not captured.

Could you try if you can reproduce it?

@jjallaire
Copy link
Member

It looks to me like the INFO stream is bypassing stderr. If I write this then the output is correctly captured:

output <- reticulate::py_capture_output({
  sys <- import("sys")
  sys$stderr$write("foo")  
})

Are you just trying to prevent INFO messages from being printed at all? If so we could do something like we do for py_suppress_warnings:

https://github.com/rstudio/tensorflow/blob/master/R/package.R#L35-L45

@terrytangyuan
Copy link
Contributor Author

I am trying to capture a regex in the output. But it's not super important. I think this is an issue on the Python API end. I'll reopen if this turns out to be very critical.

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