Google Colab TensorBoard in another Chrome Tab - pytorch

I am going through the PyTorch tutorials and am currently on the TensorBoard one.
Through research, I have been able to get it to work inline and through another tab.
My preference is to have it persisent in another tab that will update automatically.
The method described below uses ngrok:
https://medium.com/#iamsdt/using-tensorboard-in-google-colab-with-pytorch-458f9bb95212
However, it is unstable because it gets to many connections and then drop:
Too many connections! The tunnel session '1Z8HZHdl5gLd1xJVdx5Vqqpl9dW' has violated the rate-limit policy of 20 connections per minute by initiating 133 connections in the last 60 seconds. Please decrease your inbound connection volume or upgrade to a paid plan for additional capacity.
The error encountered was: ERR_NGROK_702
When this happens i have to restart the whole kernal and start over. Very frustrating.
This really isn't the solution I am looking for.
Does anyone have a solution for this?
I figured google would have a solution for this.....

Update:
Here's an example cell with two buttons to open Tensorboard in another window and hide it on Colab notebook:
%load_ext tensorboard
%tensorboard --logdir="logdir"
import IPython
display(IPython.display.HTML('''
<button id='open_tb'>Open TensorBoard</button>
<button id='hide_tb'>Hide TensorBoard</button>
<script>document.querySelector('#open_tb').onclick = () => { window.open(document.querySelector('iframe').src, "__blank") }
document.querySelector('#hide_tb').onclick = () => { document.querySelector('iframe').style.display = "none" }</script>'''))
You can simple do this by copying the embedded Colab Tensorboard iFrame URL to another Tab.
See example here in a gif

Related

Python - process ended with exit code 3221225477

I've searched on this forum for a possible workaround, and tried my best, but none is working. below is the issue. I've a function which process websocket data and dump into an excel
I tried to use a wrapper/loop around the function, but still its failing.
I am utilizing, xlwings to copy data to the excel as below
def websocket_data_process():
xw.Book(xcelfile).sheets[shets1].range('A40').options(index=False).value = futDf
----where futDf is pandas datafrme
The issue is whenever, I am editing the excel at 'A40' Range manually (while the funcion is running), I am getting error like process ended with exit 3221225477. (I googled and came to its a access denied issue). Is there any way that I can workaround this crash and again resume the function, once editing is down..
Not sure if this is what you want. You can ask for a pause. The solution below will only work with windows.
import os
os.system("pause")
or this will work with any system.
input('Press <ENTER> to continue')
Of course you need an statement such as
for i in range(50):
rng = f'A{i+1}'
if rng == 'A40':
input('Press <ENTER> to continue')
# Do your things here ...
thanks for the response, but I resolved it,
The issue happens because the xlwings trying to access the existing excel which is either locked or not available to access it.
solution: I've created an instance of Excel with xlwings context manager and provided full permissions to the account which is running the excel and it's been resolved.

Google Colab - downloads some files, TypeError: Failed to fetch on others

I have a Google Colab notebook with PyTorch code running in it.
At the beginning of the train function, I create, save and download word_to_ix and tag_to_ix dictionaries without a problem, using the following code:
from google.colab import files
torch.save(tag_to_ix, pos_dict_path)
files.download(pos_dict_path)
torch.save(word_to_ix, word_dict_path)
files.download(word_dict_path)
I train the model, and then try to download it with the code:
torch.save(model.state_dict(), model_path)
files.download(model_path)
Then I get a MessageError: TypeError: Failed to fetch.
Obviously, the problem is not with the third party cookies (as suggested here), because the first files are downloaded without a problem. (I actually also tried adding the link in my Allow section, but, surprise surprise, it made no difference.)
I was originally trying to save the model as is (which, to my understanding, saves it as a Pickle), and I thought maybe Colab files doesn't handle downloading Pickles well, but as you can see above, I'm now trying to save a dict object (which is also what word_to_ix and tag_to_ix) are, and it's still not working.
Downloading the file manually with right-click isn't a solution, because sometimes I leave the code running while I do other things, and by the time I get back to it, the runtime has disconnected, and the files are gone.
Any suggestions?

Google Colab: "Unable to connect to the runtime" after uploading Pytorch model from local

I am using a simple (not necessarily efficient) method for Pytorch model saving.
import torch
from google.colab import files
torch.save(model, filename) # save a trained model on the VM
files.download(filename) # download the model to local
best_model = files.upload() # select the model just downloaded
best_model[filename] # access the model
Colab disconnects during execution of the last line, and hitting RECONNECT tab always shows ALLOCATING -> CONNECTING (fails, with "unable to connect to the runtime" message in the left bottom corner) -> RECONNECT. At the same time, executing any one of the cells gives Error message "Failed to execute cell, Could not send execute message to runtime: [object CloseEvent]"
I know it is related to the last line, because I can successfully connect with my other google accounts which doesn't execute that.
Why does it happen? It seems the google accounts which have executed the last line can no longer connect to the runtime.
Edit:
One night later, I can reconnect with the google account after session expiration. I just attempted the approach in the comment, and found that just files.upload() the Pytorch model would lead to the problem. Once the upload completes, Colab disconnects.
Try disabling your ad-blocker. Worked for me
(I wrote this answer before reading your update. Think it may help.)
files.upload() is just for uploading files. We have no reason to expect it to return some pytorch type/model.
When you call a = files.upload(), a is a dictionary of filename - a big bytes array.
{'my_image.png': b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR....' }
type(a['my_image.png'])
Just like when you do open('my_image', 'b').read()
So, I think the next line best_model[filename] try to print the whole huge bytes array, which bugs the colab.

Cucumber-Capybara: save_screenshot(path, full: true) is not capturing the full browser?

I'm using the latest Chrome browser, Version 57.0.2987.133 (64-bit), with the latest chromedriver v2.29 (although I've tried with Chrome 56 and chromedriver 2.27 as well) and I've got a problem where I am not able to capture the full browser when a test fails.
This is the code I've got on my env.rb file:
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
driver.browser.save_screenshot(path, full: true)
end
However, the screenshots I am getting are just a partial part, what I can see on the screen rather than the complete browser.
Any idea if I'm doing something wrong or if I can try something different?
Thank you!
Since you're using chrome, I assume you're using the selenium driver (selenium-webdriver). The selenium driver doesn't support any options being passed to save_screenshot, and passing options to page.driver.screenshot -https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb#L34 - will raise a too many arguments error (which in your case I assume the capybara_screenshot gem catches and ignores) and not save a screenshot. If instead you call driver.save_screenshot(path, full: true) it will take a shot, but any options passed will be ignored since they aren't supported. Additionally, since the WebDriver spec is defined as taking a shot of the viewport (visible window), I would not expect selenium to support full screen shots any time soon.
If you are using selenium for your screenshots and you want larger your only option is to increase the window size before taking your screenshot.

Playing a sound in a ipython notebook

I would like to be able to play a sound file in a ipython notebook.
My aim is to be able to listen to the results of different treatments applied to a sound directly from within the notebook.
Is this possible? If yes, what is the best solution to do so?
The previous answer is pretty old. You can use IPython.display.Audio now. Like this:
import IPython
IPython.display.Audio("my_audio_file.mp3")
Note that you can also process any type of audio content, and pass it to this function as a numpy array.
If you want to display multiple audio files, use the following:
IPython.display.display(IPython.display.Audio("my_audio_file.mp3"))
IPython.display.display(IPython.display.Audio("my_audio_file.mp3"))
A small example that might be relevant : http://nbviewer.ipython.org/5507501/the%20sound%20of%20hydrogen.ipynb
it should be possible to avoid gooing through external files by base64 encoding as for PNG/jpg...
The code:
import IPython
IPython.display.Audio("my_audio_file.mp3")
may give an error of "Invalid Source" in IE11, try in other browsers it should work fine.
The other available answers added an HTML element which I disliked, so I created the ringbell, which gets you both play a custom sound as such:
from ringbell import RingBell
RingBell(
sample = "path/to/sample.wav",
minimum_execution_time = 0,
verbose = True
)
and it also gets you a one-lines to play a bell when a cell execution takes more than 1 minute (or a custom amount of time for that matter) or is fails with an exception:
import ringbell.auto
You can install this package from PyPI:
pip install ringbell
If the sound you are looking for could be also a "Text-to-Speech", I would like to mention that every time a start some long process in the background, I queue the execution of a cell like this too:
from IPython.display import clear_output, display, HTML, Javascript
display(Javascript("""
var msg = new SpeechSynthesisUtterance();
msg.text = "Process completed!";
window.speechSynthesis.speak(msg);
"""))
You can change the text you want to hear with msg.text.

Resources