Replace Console.WriteLine with MessageHandler
I've found several places with the code such as:
Console.WriteLine($"Restoring parameters from {save_path}");
This becomes a bit troublesome if I'm using TensorFlow.NET in a Windows Service.
May I suggest something like this instead?
public void DefaultMessageHandler(string sMessage)
{
Console.WriteLine(sMessage);
}
public delegate void OneStringArgDelegate(string sWhat); public OneStringDelegate NonDefaultMessageHandler;
public void MessageHandler(string sMessage)
{
if (NonDefaultMessageHandler == null)
DefaultMessageHandler(sMessage);
else
NonDefaultMessageHandler(sMessage);
}
@nick2893 Thanks for pointing out this issue. I'm not sure about it, does Windows Service has issue to handle console output? can you paste the error message?
We're not that far along yet, but Windows Service can be installed to run with a different windows login name, and to be unable to interact with the local desktop session. It's no trouble to write any messages to the Windows Event Log instead, as long as we have a way to do it. We will also have an application with a GUI, so in that scenario, a console window popping up will confuse the end user.
Should we inject logger somewhere?
@kerryjiang That's a good idea. Logger should be added to TF.NET instead of Console.Write. @nick2893 Your concern make sense. ILogger is a better solution.
This is another message that I saw; it was notable to me because it seems to originate from tensorflow.dll
2019-12-13 12:34:19.988143: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
@nick2893 You have to compile your own tensorflow binary to remove the message.
@Oceania2018 was that message written to the console by tensorflow.dll?
This one is YES. 2019-12-13 12:34:19.988143: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
@Oceania2018 does TensorFlow.net support some way to write this TensorFlow output to a file? Something like this is used in Python:
import logging
// get TF logger log = logging.getLogger('tensorflow') log.setLevel(logging.DEBUG)
// create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
// create file handler which logs even debug messages fh = logging.FileHandler('tensorflow.log') fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) log.addHandler(fh)