Run Tensorflow from Jupyter Notebook on Bash on Ubuntu on Windows

I read TensorFlow --MNIST For ML Beginners to learn by playing with Jupyter Notebook, and I wanted an environment where I can run Tensorflow using Jupyter Notebook even on windows. I tried to build it.

Install pyenv

Bash on Ubuntu on Windows includes python by default, but Anaconda I wanted to use it, so I installed pyenv.

$ sudo aptitude install git
$ git clone https://github.com/yyuu/pyenv ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ source ~/.bashrc

Installation of Anaconda

After installing pyenv,

$ pyenv install --list

And look for the latest version of Anaconda. 3-4.2.0 was the latest at the time of writing this article So I installed 3-4.2.0 and made it the default setting.

$ pyenv install anaconda3-4.2.0
$ pyenv global anaconda3-4.2.0
$ pyenv rehash

Maintenance of X11 GUI environment

Refer to Reference article [2] to prepare the environment for using the X11 GUI application.

Download and install the following application on windows.

After that, in Bash on Ubuntu on Windows, enter X11 with the following command and write the DISPLAY setting in .bashrc.

$ sudo aptitude install x11-apps
$ echo 'export DISPLAY=localhost:0.0' >> ~/.bashrc
$ source ~/.bashrc

Finally, display xclock to check the operation.

$ xclock

Install matplotlib

Matplotlib is required to display the graph with jupyter, so prepare for it.

sudo aptitude install libqtgui4
conda install matplotlib

Also, numpy used in the following code is mkl compatible and an error will occur, so Replace with nomkl's.

conda install nomkl
conda update --all

If you execute the following code in this state, confirm that an image of the sin curve is created.

sin_plot.py


import matplotlib
matplotlib.use('Agg')

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y  = np.sin(x)
plt.plot(x, y)
plt.savefig('sin_curve.png')

install jupyter

In Bash on Ubuntu on Windows, an error occurs around libzmq3, so install libzmq3 corresponding to it.

$ sudo add-apt-repository ppa:aseering/wsl
$ sudo aptitude update
$ sudo aptitude install libzmq3
$ conda install -c jzuhone zeromq=4.1.dev0
$ conda install jupyter

Finally, execute the following command to start Jupyter and http: // localhost: 8888 / You will be able to connect with and run python.

jupyter notebook --no-browser

I want to display the matplotlib graph inline in the jupyter notebook In that case, you can display it in jupyter's notebook by writing as follows.

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y  = np.sin(x)
plt.plot(x, y)

sin_curve.PNG

Install Tensorflow

Reference article [1] with reference to anaconda Put Tensorflow in the environment of.

conda install -c conda-forge tensorflow

Finally, on Jupyter's Notebook, https://www.tensorflow.org/get_started/ If you paste the code in and execute it, the result will be returned, so You can see that Tensorflow is installed.

tensor_flow_tutorial.PNG

Reference article

I referred to the following article. Thank you very much.

  1. Notes for using TensorFlow on Bash on Ubuntu on Windows
  2. GUI by Bash on Ubuntu on Windows + Xming
  3. Cygwin Absolute Killing Man-Until Physical Nerds Can Calculate Numerically with Windows Subsystem for Linux-
  4. Learn by playing with Jupyter Notebook TensorFlow --MNIST For ML Beginners

Recommended Posts

Run Tensorflow from Jupyter Notebook on Bash on Ubuntu on Windows
Run Jupyter Notebook on windows
Run XGBoost on Bash on Ubuntu on Windows
Notes for using TensorFlow on Bash on Ubuntu on Windows
Install Bash on Ubuntu on Windows, Ruby, Python, Jupyter, etc.
Run Tensorflow natively supported on windows
Run azure ML on jupyter notebook
Try using Bash on Windows 10 2 (TensorFlow installation)
Run Jupyter notebook on a remote server
Install TensorFlow on Ubuntu
Build TensorFlow on Windows
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
High charts on Jupyter notebook
View PDF on Jupyter Notebook
Operate ubuntu on VScode (windows10)
Run Tensorflow 2.x on Python 3.7
Introducing TensorFlow on Ubuntu + Python 2.7
[Tensorflow] Tensorflow environment construction on Windows 10
Run IPython Notebook on Docker
A note when I can't open Jupyter Notebook on Windows
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Formatting with autopep8 on Jupyter notebook
Remove ubuntu installed on Windows 10 machine
Install and run dropbox on Ubuntu 20.04
Building a Python development environment on Windows -From installing Anaconda to linking Atom and Jupyter Notebook-
Run Open Modelica from Jupyter Lab
Real-time display of video acquired from webcam on Jupyter notebook (Python3)
Run TensorFlow Docker Image on Python3
Run SwitchBot on Windows 10 with Bleak
Use Tensorflow 2.1.0 with Anaconda on Windows 10!
Run TensorFlow2 on a VPS server
Try running Jupyter Notebook on Mac
Run Yocto on Ubuntu using QEMU.
Use Jupyter Notebook with Visual Studio Code on Windows 10 + Python + Poetry + pyenv-win
Settings when reading S3 files with pandas from Jupyter Notebook on AWS
Run TensorFlow on a GPU instance on AWS
Make Jupyter Notebook a service on CentOS
Try SVM with scikit-learn on Jupyter Notebook
[Note] Procedures for installing Ubuntu on Windows 10
Start jupyter notebook on GPU server (remote server)
I installed TensorFlow (GPU version) on Ubuntu
Use BigQuery from your local Jupyter Notebook
Clone the github repository on jupyter notebook
GPU check of PC on jupyter notebook
Run bootgen on Debian GNU / Linux, Ubuntu
Display histogram / scatter plot on Jupyter Notebook
Install ubuntu on 32bit UEFI Ultra Notebook
Build jupyter notebook on remote server (CentOS)
Run py.test on Windows Anaconda and MinGW
Use vim keybindings on Docker-launched Jupyter Notebook
I built a TensorFlow environment on windows10
Run matplotlib on a Windows Docker container
How to install Fast.ai on Alibaba Cloud GPU and run it on Jupyter notebook
Install matplotlib and display graph on Jupyter Notebook
Use jupyter notebook by connecting from another host
Run PIFuHD in Windows + Anaconda + Git Bash environment
[Jupyter Notebook / Lab] 3 ways to debug on Jupyter [Pdb]
Run django applications on Windows + Apache + mod_wsgi + services.
Put MicroPython on Windows to run ESP32 on Python
Browser specification of Jupyter Notebook in Windows environment
Run yolov4 "for the time being" on windows