Skip to content

How can I redirect output from torchinfo.summary to logs? #240

Closed Answered by snimu
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

summary returns an object of type ModelStatistics, which has an explicit __repr__- (and, as such, an implicit __str__-) method. This is what's usually printed if you don't capture the output, or if you have set verbose to True in summary. You can easily access it with the str- or repr-function. For example:

from torchinfo import summary

model_statistics = summary(...)
your_logger.log(str(model_statistics)). # logs the summary as a string

To get more structured information than a string, you would have to either manually extract that information from the returned ModelStatistics, or from the string that is produced.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@TylerYep
Comment options

@ghost
Comment options

Answer selected by TylerYep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants