tensorboard: Error using TensorBoard in a Jupyter Notebook on the Google Cloud Platform

I followed instructions to launch TensorBoard like this:

`get_ipython().system_raw( “tensorboard --logdir {} --host 0.0.0.0 --port 6006 &” .format(OUTDIR) )

get_ipython().system_raw(“./assets/ngrok http 6006 &”)

!curl -s http://localhost:4040/api/tunnels | python3 -c
“import sys, json; print(json.load(sys.stdin)[‘tunnels’][0][‘public_url’])” `

The following error messages show up:

Traceback (most recent call last): File “”, line 1, in File “/usr/lib/python3.5/json/init.py”, line 268, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File “/usr/lib/python3.5/json/init.py”, line 319, in loads return _default_decoder.decode(s) File “/usr/lib/python3.5/json/decoder.py”, line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File “/usr/lib/python3.5/json/decoder.py”, line 357, in raw_decode raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Before running this code, I had already trained a Tensorflow model and exported it to the directory “OUTDIR”. The tunnel connection is not set up and therefore no public URL is generated.

Can anyone kindly give me some advice as to how to solve it? Thank you very much!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 29 (1 by maintainers)

Most upvoted comments

I think the easiest way to workaround this is to run tensorboard in a JupyterLab console: tensorboard --port=7000 --logdir logs

And then setup port forwarding using gcloud command: gcloud beta compute ssh --zone “{your zone}” “{your instance name}” --project “{your project name}” – -L 7000:localhost:7000

You can copy this command for your VM from gcloud console VM instance details page, click SSH drop down and select ‘view gcloud command’. Then just add port you want to forward as – -L 7000:localhost:7000

After this you should be able to access tensorboard running on your cloud VM as localhost:7000

Same issue using GCP AI Platform notebook (TF 2.1 image) image

I was told by the GCP AI Platform notebook team that this scenario is not supported because TensorBoard widget is trying to do port forwarding under the hood and the AI Platform notebook proxy prevents it from connecting to non-HTTPS ports.

  1. Is there a tricks to run in another way to avoid this issue (even if TensorBoard in not running in a jupyter cell
  2. Is there a plan to be able to have TensorBoard running on GCP AI Platform notebook ? I think this will be great for data scientist working on GCP and it is also use in GCP ML training

+1 on this. I get the same issue as @tarrade has shown above. I’m sort of getting around this by installing and using the jupyterlab-tensorboard extension (which required a pip install jupyter-tenorboard). This is less then ideal though and buggy. It’s a holdover that might work temporarily for others while this gets sorted.

Would be ideal to have things “just work” like docs and examples as @tarrade shows above and also make sure the TB version is compatible with the TF version (which is not the case with the other extension).

Anyone have any updates on this getting fixed in GCP AI Hub notebooks?

@tarrade thanks for your comment here. I have had to manually port forward while the model was training through SSH to my local and start tensorboard there instead. I can confirm that this method works as an alternative to using jupyter notebook on GCP

This should work now in AI Notebooks I just tested it successfully, back in October 2021 we made some env variable changes:

%tensorboard --logdir logs/fit

image

Here are some suggestions:

  • This process is a bit more involved. If you can write your event logs to a GCS Bucket and then trigger a TensorBoard instance from a Cloud Shell pointing towards the GCS Bucket that would work (you would need to change the ports for Web Preview).
  • This one I tried with AWS EC2 but the same concept can be applied here as well. If you have SSH access to the instance then you can SSH into the instance with the particular board and launch your TensorBoard instance from there. The workflow for this one would be:
$ ssh -i ~/.ssh/id_rsa -L localhost:port_number:localhost:port_number username@ip_address
  • After you are able to successfully log in you should be able to launch TensorBoard.

Hope this helps.