Nico-Curti / NumPyNet

Neural Networks library in pure numpy
https://nico-curti.github.io/NumPyNet
Other
65 stars 6 forks source link

Display in jupyter notebook #2

Closed bblais closed 2 years ago

bblais commented 4 years ago

In the Network.fit() method, there is no way to either shut off the printing (e.g. verbose flag) or a way to display properly in a jupyter notebook. The first is easy to implement, the second might need something like:

    try:
        from IPython.core.display import clear_output
        have_ipython = True
    except ImportError:
        have_ipython = False

and then

      try:
          clear_output(wait=True)
      except Exception:
          # terminal IPython has no clear_output
          pass

perhaps a better way would be to use a package like tqdm which works in either notebook or console mode.

Nico-Curti commented 4 years ago

Thanks for reporting this. I added an other way to fix the verbosity problem (more portable). You can find a new function in the utility module L272 which redirects the stdout output to devnull using a contextmanager. The same idea can be used also for writing the output on file or other loggers. The same contextmanager was propagated to the fit and predict functions of the network object.

I prefer not to use the tqdm package just to minimize project dependencies. tqdm is certainly the best solution to solve the progress-bar problem, but in this case I prefer to use a customized version of it also to show how it is possible to create something like that from scratch (which is the main idea behind this repository!)

As always, thanks for your comments