bdzyubak / tensorflow-sandbox

A repository for studying applications of Deep Learning across fields, and demonstrating samples of my code and project managment
0 stars 0 forks source link

Integrate Tensorboard into Python functions cleanly #2

Closed bdzyubak closed 2 years ago

bdzyubak commented 2 years ago

Background: When running in Colab, tensorboard is lunched within the code using the below two lines which causes the board to appear inline in the browser. This is very clean behavior.

%load_ext tensorboard
%tensorboard --logdir logs 

Issue: In Python without Jupiter, this does not work. A log dir is specified in training, and a Tensorboard callback is connected to drop training information into the log directory.

logdir = os.path.join(script_dir,"logs")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=logdir)
model.fit(train_ds, validation_data=val_ds, epochs=15, callbacks=[tensorboard_callback])

Then, tensorboard must be started outside of Python in command prompt/shell: tensorboard --logdir=[path]\[to]\logs Which yields a local url that needs to be posted into the web browser to see the board. TensorBoard 2.7.0 at http://localhost:6006/

ToFix: Implement a utility for cleaner integration that can be used by other functions. For example, this can make an OS call, fetch the URL and open a browser with it as a target. Perhaps, Tensorboard has innate clean ways to run inline with a python script, but I have not found them yet.

bdzyubak commented 2 years ago

Tensorboard integration has been implemented in the February 2021 VS Code Python extension. Custom integration will not need to be implemented. https://devblogs.microsoft.com/python/python-in-visual-studio-code-february-2021-release/


To start a TensorBoard session, open the command palette (Ctrl/Cmd + Shift + P) and search for the command “Python: Launch TensorBoard”. Afterwards, you will be prompted to select the folder where your TensorBoard log files are located. By default, we will use your current working directory and automatically detect your TensorBoard log files within any subdirectories, but you can also specify your own directory. VS Code will then open a new tab with TensorBoard and its lifecycle will be managed by VS Code as well.