Giter VIP home page Giter VIP logo

Comments (16)

terrytangyuan avatar terrytangyuan commented on July 24, 2024

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.

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

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.

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

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)

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

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.

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

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.

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

Thanks, will try!

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

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

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

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

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

Here it is:

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

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

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?

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

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

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

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?

from reticulate.

jjallaire avatar jjallaire commented on July 24, 2024

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

from reticulate.

terrytangyuan avatar terrytangyuan commented on July 24, 2024

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.

from reticulate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.