ProGamerGov / neural-style-pt

PyTorch implementation of neural style transfer algorithm
MIT License
834 stars 178 forks source link

Add verbose option #16

Open momo-the-monster opened 4 years ago

momo-the-monster commented 4 years ago

Thanks for all your work on this project! I'm using it for Colab notebook experiments and found that it printed more lines to the console than I would like, so I added this -verbose flag in for myself so I could set it to 0 when I don't need as many updates.

momo-the-monster commented 4 years ago

Hi @ProGamerGov! Just fixed the merged conflicts introduced with the latest and greatest from the master branch so I'm bumping this up for visibility. The -verbose flag is super helpful when running in Colab notebooks, especially as I have this in front of a group of designers at our company right now. Let me know if you have a thought on another way you'd like to see this implemented. Thanks!

ProGamerGov commented 4 years ago

@momo-the-monster Nice work!

I'm not sure about using a ton of if statements to block all the print statements. It's fine to use that once in CaffeLoader to block printing the conv layers, but it looks a bit ugly to use it for every print statement.

I guess one could use: sys.stdout = open(os.devnull, 'w') to completely block printing until some point, but reenabling printing could be tricky.

Also, the verbose parameter doesn't need to use integers. It can just be a boolean flag.

momo-the-monster commented 4 years ago

Hm, agreed. I don't work in Python much -what do you think about using the built-in logging library (or a third-party one like loguru) where the user could configure what level they want to print? That way I could easily supress anything error or below.

momo-the-monster commented 4 years ago

@ProGamerGov - had another go at this, much simpler this time around.

I just added a -log_level parameter and switched all the print() commands to logging.info() commands.

The log level is INFO by default, so everything shows up. If you pass -log_level 30 or higher, then you get no outputs. Future-compatible because any new code can just log using the appropriate level, the param supports all Python log levels.

It looks like you've got a couple of branches in various states so I made this off the latest master. Happy to redo it off another branch if that makes it more likely to get merged.