With Colaboratory (referred to as Colab), you can write and execute Python code in the browser, and: without any configuration, free use of GPU, easy to share.
Most people first used Colab to squeeze Google’s wool for free. Colab was born around 18 years ago. The most resounding slogan is the free GPU/TPU. Free computing power is waiting for you. After all, it is a habit. game. Sure enough, at the beginning of 2020, the Colab Pro membership policy started, paying to allocate better computing power (V100/T4/K80 gives priority to V100 XD), longer code continuous calculation time (general user code runs 12H automatically), and Balabala’s differentiated solution. Besides, if you run large-scale algorithms on Colab, whether the data set behind it is placed on Drive or GCS, it will be an additional cost. By the way, continue to explore potential users, and you will get multiple results!
“Difficulty of migration” Code farmers who are already familiar with Jupyter should be no strangers to the interface of Colab. The difficulty of migration is almost 0. The explanation line of Colab’s configuration can switch between Py2/Py3 and TF1.x/2.x with one line of code, which is a very comfortable user experience.
“Common scenarios” Just talk about my environment: use a host equipped with GPU at a fixed worksite, the TPU and GPU supported by TFRC on the cloud are available, the data part is in the remote NAS part in the GCS, and the data that is not frequently used is placed in the cold-line. In summary, when you leave your workplace and need to collaborate or show your needs or try a code snippet you are not familiar with, use it as a cloud sharing Jupyter.
Colab cannot correctly display Chinese labels/Chinese garbled characters when drawing Matplotlib
Calling Matplotlib
on Colab to display Chinese and displaying garbled characters, Chinese fonts cannot be found, you need to manually install Chinese fonts to Colab.
- First check the local fonts in the virtual machine:
By executing the !fc-list :lang=zh
command, the result is found to be empty, indicating that the Colab virtual machine Ubuntu
operating system does not support Chinese fonts.
- Find and download and install the fonts you need to use:
The font file ends with .otf
or .ttf
, SimHei
download link
Ubuntu’s font directory is located at /usr/share/fonts/truetype
.
Colab calls and executes system commands with commands starting with !
.
1 | # Download--Unzip--Move the font file |
- Test Matplotlib to correctly output and display Chinese characters
1 | import matplotlib.pyplot as plt |
Use the form to interact with Colab variable input
Colab interactive form is a great function, simple and clear, the data in the form is read in the str format, and the actual variables are obtained after further string processing. The effect is as follows:
1 | #@title Visualization of bivariate correlation confusion matrix |
Colab Link Google Drive
In the past experiments, the acquisition, storage and loading of a large amount of training and test data has always been a headache. In Colab, we can mount the Google Driver to the current working path:
1 | from google.colab import drive |
Then create and operate through normal Linux Shell commands:
1 | # Working with files |
Reference
- Welcome to Colaboratory
- Cloud Storage Docs
- Practice deep learning quickly in Google Colab
- External data: local files, Google Drive, Google Sheets, Cloud Storage