0

Keras: plot_model returns pydot and graphviz related error on Windows

plot_model of Keras installed on Windows may return pydot and graphviz related error like “Graphviz’s executables are not found’. The error cause is that the computer does not know the path of Graphviz’s executable exactly mentioned as the error message. The solution is explained here.

  1. Install GraphViz software not python module
  2. add GraphViz’s bin directory to system path
  3. install graphviz like conda install graphviz
  4. install pydot like pip install git+https://github.com/nlhepler/pydot.git

 

Advertisements
0

pytorch

pytorchを使った方が良いかもしれないと思ったので,色々調査.

  1. Tensor
    1. 任意オーダーのtensorを定義する型
    2. Tutorialではオーダーが1,2のtensor(つまり,ベクトルと行列)のみを例として扱っている
    3. NumPyのArray型と互換性を持つ
  2. Autograd
    1. Tensorのあらゆる計算の勾配(微分)を自動で計算
    2. define-by-runのフレームワーク
      1. プログラムを走らせることで逆伝搬が定義される
      2. 毎回計算は異なる
    3. メインモジュールはautograd.Variable
  3. Neural Networks
    1. torch.nnモジュールによって定義
    2. 一般的な学習の流れ
      1. 学習可能なパラメータ(重み)を持つネットワークを定義
      2. 学習データセットに対して繰り返し計算
      3. ネットワークによって入力を処理
      4. 処理結果の誤差を評価
      5. ネットワークのパラメータに勾配を逆伝搬
      6. ネットワークの重みを更新
    3. Networkを表すclassを定義し,
      1. コンストラクタ(__init__)でネットワーク構成+活性化関数を定義
      2. 関数forwardで入力から出力までの処理を定義
      3. backwardはautogradにより自動で計算される
    4. 入力データはミニバッチのみをサポートしている
    5. 単一のデータを入力する時は,input.unsqueeze(0)によって次元数を増やす必要がある
0

Implementation: CycleGAN and Pix2pix

The implementation of CycleGAN and Pix2pix based on pytorch is published on github. Here’s a todo procedure with anaconda.

The CPU mode installation is under test right now…

  1. pytorch installation
    1. see the repository
    2. For a machine with GPU
      1. conda install -c conda-forge dominate
      2. conda install pytorch torchvision cuda80 -c soumith
    3. For a machine without GPU
      1. export enviroment variable NO_CUDA=1
      2. add anaconda root directory to CMAKE_PREFIX_PATH as
        export CMAKE_PREFIX_PATH=[anaconda root directory]
      3. conda install numpy pyyaml mkl setuptools cmake gcc cffi
      4. git clone https://github.com/pytorch/pytorch.git
      5. cd pytorch/
      6. python setup.py install
      7. cd ..
      8. git clone https://github.com/pytorch/vision.git
      9. cd vision
      10. python setup.py install
  2. CycleGAN and pix2pix installation
    1. conda install -c conda-forge dominate
    2. git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
    3. cd pytorch-CycleGAN-and-pix2pix

Note that running train.py and test.py without GPU requires to disable GPU via command line such as –gpu_id -1. For instance:
– With GPU: python train.py –dataroot ./datasets/facades –name facades_pix2pix –gpu_ids 0 –model pix2pix –align_data –which_direction BtoA
– Without GPU: python train.py –dataroot ./datasets/facades –name facades_pix2pix –gpu_ids -1 –model pix2pix –align_data –which_direction BtoA

0

install keras + tensorflow (GPU) to Windows using anaconda

  1. Install Tensorflow and Keras
    1. Run Anaconda Prompt
    2. Install Tensorflow
      # pip install tensorflow-gpu
    3. Install Keras
      # pip install keras
  2. (Optional) Change Keras’ backend from Theano to TensorFlow
    1. This step is optional if Keras uses Theano as its backend.
    2. Start python and import keras
      # python
      # import keras
    3. If Theano is set as the backend, the terminal says “Using Theano backend
    4. Find the setting file location
      1. Find the location of Keras’ setting file. Executing the following 2 lines, the terminal shows the location where the Keras’ setting file is stored.
        # import os
        # print(os.path.expanduser(‘~’))
        NAME_OF_DIRECTORY (in my case it’s C:\User\USERNAME)
    5. Change the backend
      1. Open NAME_OF_DIRECTORY.keras\keras.json
      2. Change  “th” to “tf
      3. Change “theano” to “tensorflow
  3. run any Keras example