Work with Python on Windows10 (using Bash on Ubuntu on Windows)

[Updated] Comments for OpenCV installation

So far, I used pre-packaged Python environment, WinPython for developing Python program. That was my local optimal solution for working with Python on Windows.

Followings are my current solution (and some problem I faced). (Anaconda or pyenv are optional for managing several Python environments.)

Install Python3 and pip

$ sudo apt-get install python3
$ sudo apt-get install python3-pip

Install numpy

$ sudo pip3 install numpy

Install scipy

$ sudo apt-get install libblas-dev liblapack-dev
$ sudo apt-get install gfortran
$ sudo pip3 install scipy

Install Pyside and pyqtgraph

$ sudo apt-get install libqt4-dev
$ sudo apt-get install cmake
$ sudo pip3 install PySide
$ sudo pip3 install pyqtgraph

Install opencv (with Anaconda)

$ conda install -c menpo opencv3=3.1.0

ref: Opencv3 :: Anaconda Cloud

ImportError: libopencv_ccalib.so.3.1: cannot enable executable stack as shared object requires: Invalid argument

When importing opencv (import cv2), I faced this error. This is a dynamic linking trouble and can be resolved by execstack command.

ref: rhel - chcon fails to fix "cannot enable executable stack as shared object requires" err under RHEL6 - Unix & Linux Stack Exchange

$ sudo apt-get install execstack
$ sudo execstack -c $HOME/anaconda3/lib/libopencv_*
$ sudo apt-get install gtk2.0-0

[Update] This works well for

>>> import cv2

on Python interpreter however video related functions (such as cv2.VideoCapture) work unexpectedly. The comments on menpo's opencv3 github repository is below.

This functionality is disabled in order to attempt to increase the probability that the automated builds will be useful for as large a range of people as possible. I have made no effort to get the FFMPEG/Video builds working. If this is a requirement I can likely remedy it by adding an FFMPEG conda package.

I believe Python2.7 + OpenCV2 is much easier way to get started with video related functions.

However if you persist to use Python3+, you have to choose some more complicated installation process. So I will post some alternative setting up process for Python3+ + OpenCV3.

Cannon (Program in Python with PyQtGraph wrapper)

Previous post includes an animated graph, which is concatenation of png images, created by Giam software. The graphs are drawn by python program with a graphics library, PyQtGraph. Here is the source code. The package pyqtgraph_wrapper is my self-making wrapper of PyQtGraph.

# -*- coding: utf-8 -*-
"""
Sample code for pyqtgraph_wrapper

Created on Fri Jun  3 13:05:30 2016

@author: tatsuya-y
"""

import sys
import time
import numpy as np
import scipy as sp

sys.path.append('./pyqtgraph_wrapper')
import pyqtgraph_wrapper as pgw


## Cannon
win = pgw.figure()

i = 0
tsnap = 50
T = 5000

y = np.arange(0, 1, 0.001)

for t in np.arange(T):
    
    a = sp.tan(sp.pi/2 * t/T) 
    x = sp.sqrt(a**2 * (1 - y**2))

    win.clf()
    win.hold()
    win.plot(x, y, color="#ffffff")
    win.plot(x, -y, color="#ffffff")

    win.ylim(-2, 2)
    win.xlim(1, 100)
    
    #win.drawnow()
    
    print('t = {0:0>4}'.format(t))

    if t == 0 or t == T-1 or sp.mod(t,tsnap) == 0:   
        win.print('cannon_img\cannon_{0:0>4}.png'.format(i))
        i = i + 1
    
    time.sleep(0.1)

The wrapper pyqtgraph_wrapper is under development. I'm planning to open a github repository after making the rough list of TODOs or Tasks.

CUDA programming with NVidia GPU GeForce GTX 1080 on Linux (ubuntu)

The following is what I learned through CUDA programming environment setup.

Read official documents/supports first

In other words,

Do not google trouble shooting posts (at least) until some trouble comes up.

From NVidia developer website (https://developer.nvidia.com/), you can download CUDA toolkit.

To run the installing process, you have to stop the X server.

If the X server fails to start after reboot, (temporarily) edit boot option by adding 'nomodeset' option to the kernel parameter and re-install a suitable video driver.

This may happen after distribution upgrade (sudo apt-get dist-upgrade in Ubuntu).

Machine Learning and its surroundings

I bought 3 (japanese) books related with machine learning. Yesterday, I succeeded to execute some deep learning programs (such as GitHub - wojciechz/learning_to_execute: Learning to Execute) on my new PC. It is motivative for me to learn about machine learning more deeply.

  • 機械学習と深層学習 C言語によるシミュレーション(Machine Learning and Deep Learning)
  • 進化計算と深層学習 創発する知能(Neuro Evolution and Deep Learning)
  • 人工知能と人工生命の基礎(Artificial Intelligence and Artificial Life)

As a future post, I want to summarize 'how to' set up deep learning environment with NVidia GPU.