Giter Club home page Giter Club logo

cnn_library's Introduction

CNNのC++実装

必要なパッケージ

C++

Python (重みやデータの生成用)

  • numpy
  • pickle
  • scikit-learn

ビルド方法

ALL

$ make -j4

MLP

$ make bin/mlp

$ ./bin/mlp test  # 推論の場合

$ ./bin/mlp train  # 学習の場合

CNN

$ make bin/cnn

$ ./bin/cnn test  # 推論の場合

$ ./bin/cnn train  # 学習の場合

テスト

$ make bin/utest

$ ./bin/utest

生成されたファイルの削除

$ make clean

※Stack Overflowした場合

$ ulimit -s 16384

コード構成

src/util

  • function.hpp : 活性化関数や畳込み、プーリングなど基本的な関数が実装されている
  • tensor.hpp : 多次元配列を扱うTensorクラスを定義している
  • read_data.cpp, read_data.hpp : MNISTのデータの読み込みをするクラス

src/cnn

  • cnn.hpp : CNNクラスを定義している

src/mlp

  • mlp.hpp : MLPクラスを定義している

src/python

  • make_cnn_weight.py : cnnの重みを定義するcnn_weight.hppを生成するファイル
  • make_mlp_weight.py : mlpの重みを定義するmlp_weight.hppを生成するファイル
  • make_mnist_data.py : mnistのデータを定義するmnist_data.hppを生成するファイル
  • make_test_array.py : テスト用の配列を定義するtest_array.hppを生成するファイル

test/

  • util_test.cpp : いろいろな関数のテストが実装されている

実装上のルール

For FPGA

  • std::vector, std::arrayはVivado HLSでサポートされていないので原則Tensorクラスか配列を使う
  • malloc, freeを使わず、メモリ確保はtemplateを使うなどして静的に行う
  • Vivado HLSでサポートされていないものを使うときはコメントを入れる
  • templateを多様することになるため基本的に実装はすべてヘッダファイルに書くことになるはず

For Maintainability

  • 関数を実装したらテストを書く
  • マージする前にテストが通っていることを確認する(CIとかと連携させてテストが通らないとマージできない設定にしたい...)
  • pull requestはできるだけ細かくする
  • branchも細かく切る
  • コードレビューしてもらってからマージ
  • スタイルはそんなに厳しく見ないけど、基本的にはhttps://ttsuki.github.io/styleguide/cppguide.ja.htmlに従う
  • 基本的にメンバ変数はprivateにする

For Performance

  • 関数内で値が変更される場合はポインタで渡す
  • 関数内で値が変更されない場合は参照渡しにする
  • 型にできるだけ依存しないような実装をする

Debug tips

通常のプリントデバッグやデバッガでのデバッグに加えてValgrindを使うと効果的だったりする。

Valgrind

メモリリークとかをチェックしてくれるツール

公式: http://valgrind.org/

日本語Wiki: https://ja.wikipedia.org/wiki/Valgrind

コマンド: 基本これだけ使っておけばなんとかなる

valgrind --leak-check=full ./a.out

cnn_library's People

Contributors

obake2ai avatar wakanapo avatar

Watchers

 avatar  avatar

cnn_library's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.