Wednesday, February 17, 2021

Colabtricks

Colab

Colab’s tricks

Save code

  1. Save cell’s code
    %%writefile name.py
    import torch
    a=torch.tensor([1,2,3,4])
    print(a)
    
    Note that %%writefile code.py should be put at the beginning of the cell

Open a Github notebook using Colab

Change the domain from 'github.com' to 'githubtocolab.com'. The notebook will open in Colab. See other tricks.

Convert ipynb notebook

  1. to pdf

    • Go to Colab
    • Upload your IPython notebook to Colab
    • run these following commands
      #intall nbconvert for Linux system
      !sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-generic-recommended
      #convert command
      !jupyter nbconvert --to pdf ttl.ipynb
      
    • A pdf file will appear next to the your notebook, just download it.
  2. to interactive html
    (the original technique is here, as an example visit this post)

    • Go to Colab
    • Upload your notebook to Colab
    • run these following commands
      #intall nbinteract
      !pip install nbinteract
      #convert command
      !nbinteract {notebook_filename}.ipynb -s {GitHub_UserName}/{Gist_ID}
      
    • An html file will appear next to the your notebook, just download it and make necessary modification if needed.

Popular Posts