データ格納

DType クラス(Enum定義)

class binarybrain.dtype.DType(value)

ベースクラス: IntEnum

データ型定義

BINARY = 2
BIT = 1
FP16 = 272
FP32 = 288
FP64 = 320
INT16 = 528
INT32 = 544
INT64 = 576
INT8 = 520
UINT16 = 784
UINT32 = 800
UINT64 = 832
UINT8 = 776

Tensor クラス

class binarybrain.tensor.Tensor(shape: Optional[List[int]] = None, *, dtype=DType.FP32, host_only=False, core_tensor=None)

ベースクラス: Object

Tensor class

多次元データ構造。

パラメータ
  • shape (list[int]) -- Shape of created array

  • dtype (int) -- Data type

  • host_only (bool) -- flag of host only

static from_numpy(ndarray: ndarray, host_only=False)

NumPy から生成

パラメータ
  • ndarray (ndarray) -- array of NumPy

  • host_only (bool) -- flag of host only

get_shape() List[int]

データのシェイプ取得

戻り値

shape

get_type() int

データ型取得

戻り値

data type.

numpy() ndarray

NumPy の ndarray に変換

戻り値

ndarray (array)

FrameBuffer クラス

class binarybrain.frame_buffer.FrameBuffer(frame_size: int = 0, shape: List[int] = [], dtype=DType.FP32, host_only: bool = False, core_buf=None)

ベースクラス: Object

FrameBuffer class

BinaryBrainでの学習データを格納する特別な型である バッチと対応する 1次元のframe項と、各レイヤーの入出力ノードに対応する 多次元のnode項を有している numpy の ndarray に変換する際は axis=0 が frame 項となり、以降が node項となる

Tensor と異なり、frame 項に対して reshape を行うことはできず、 node 項に対しても transpose することはできない。

node に関しては 2次元以上の shape も持ちうるが、実際のレイヤー間接続に 際しては、畳み込みなどの次元に意味を持つノード以外では、ノード数さえ あっていれば接続できるものが殆どである(多くの処理系で必要とする flatten が省略できる)。

host_only フラグを指定すると device(GPU側) が利用可能であっても host(CPU側) のみにメモリを確保する

パラメータ
  • frame_size (int) -- frame サイズ

  • shape (list[int]) -- node シェイプ

  • dtype (int) -- Data type

  • host_only (bool) -- flag of host only

static from_numpy(ndarray: ndarray, host_only=False)

Create from NumPy

パラメータ
  • ndarray (np.ndarray) -- array of NumPy

  • host_only (bool) -- flag of host only

get_frame_size() int

get size of frame.

戻り値

frame size.

get_frame_stride() int

get stride of frame.

戻り値

frame stride.

get_node_shape() List[int]

get shape of node.

戻り値

shape

get_node_size() int

get size of node.

戻り値

node size.

get_type() int

データ型取得

戻り値

dtype (DType)

numpy() ndarray

Convert to NumPy

パラメータ
  • shape (list[int]) -- Shape of created array

  • dtype (int) -- Data type

  • host_only (bool) -- flag of host only

Variables クラス

class binarybrain.variables.Variables

ベースクラス: object

Variables class

学習の為の Optimizer と実際の学習ターゲットの変数の橋渡しに利用されるクラス。 内部的には各モデル内の重みや勾配を保有する Tensor をまとめて保持している。

append(variables)

変数を追加

パラメータ

variables (Variables) -- 追加する変数