1. 程式人生 > >caffe.Net類

caffe.Net類

caffe.Net

__init__(prototxt, phase)

@param prototxt: 字串。指定prototxt路徑
@param phase: `caffe.TRAIN`或者`caffe.TEST`
@description: 根據prototxt初始化一個網路。相當於C++的:
      shared_ptr<Net<Dtype> > net(new Net<Dtype>(param_file,
      static_cast<Phase>(phase)));
@return `Net`類物件,網路例項
@example `net = caffe.Net('test.prototxt'
, caffe.TEST)
`

__init__(prototxt, caffemodel, phase)

@param prototxt: 字串。指定prototxt路徑
@param caffemodel: 字串,指定caffemodel路徑
@param phase: `caffe.TRAIN`或者`caffe.TEST`
@description: 根據prototxt初始化一個網路,並從caffemodel複製同名層的權值(作為網路中該層的權值)。相當於C++的:
      shared_ptr<Net<Dtype> > net(new Net<Dtype>(param_file,
          static_cast<Phase>(phase)));
      net->CopyTrainedLayersFrom(pretrained_param_file);
@return `Net
`類物件,網路例項 @example `net = caffe.Net('test.prototxt', 'resnet50.caffemodel', caffe.TEST)`

_forward(start, end)

@param start: int型別
@param end: int型別
@description: 執行前向傳播。呼叫的是C++的`Dtype Net<Dtype>::ForwardFromTo(int start, int end) `
@return: loss值
@example: 類的私有方法,所以不建議使用

_backward(start, end)

@param
start: int型別 @param end: int型別 @description: 執行前向傳播。呼叫的是C++的`void Net<Dtype>::BackwardFromTo(int start, int end) ` @return: 沒有返回值。 @example: 類的私有方法,所以不建議使用

reshape()

@param: 不需要引數
@description: 網路中的每一層,都執行reshape。呼叫的C++的`void Net<Dtype>::Reshape() `
@return: 沒有返回值型別

copy_from(caffemodel)

@param caffemodel: 字串型別。指定(pretrained的)caffemodel路徑
@description: 讀取指定的caffemodel(二進位制protobuf檔案),從中讀取和當前網路同名層的引數作為替代。呼叫的是C++`void Net<Dtype>::CopyTrainedLayersFrom(const string trained_filename)`
@return: 空
@example
    pretrained_caffemodel = 'abc.caffemodel'
    net = caffe.Net(prototxt, caffe.TEST)
    net.copy_from(pretrained_caffemodel)
    (來源:py-faster-rcnn)

copy_from(net)

@param net: (另一個)Net物件
@description: 從Net中讀取同名網路層引數作為替代。呼叫的其實是`void Net<Dtype>::CopyTrainedLayersFrom(const NetParameter& param)`
@return 空
@example
    net = caffe.Net(prototxt, caffe.TEST)
    resnet = caffe.Net(prototxt_resnet, caffemodel, caffe.TEST)
    net.copy_from(resnet)

share_with(net)

@param net: Net型別。打算從net上取同名層,和當前網路共享引數。
@description: 和copy_from非常像。區別在於,被share的兩個Net物件,同名層的資料是共享的!也就是記憶體中只有一份!改了一個,另一個也被修改!呼叫的是C++`void Net<Dtype>::ShareTrainedLayersWith(const Net* other) `
@return 空

_blob_loss_weights

私有屬性。
返回loss函式中的每個blob的權值。按照blob_id進行索引。

_bottom_ids(i)

@param i: 層(layer)序號
@returni層的bottom們的id列表,`bottom_id_vecs_[i]`

_top_ids(i)

@param i: 層(layer)序號
@returni層的top們的id列表,`top_id_vecs_[i]`

_blobs

私有屬性
返回blobs(不是很懂!)

layers

公共屬性
返回layers

_blob_names

私有屬性
返回blob們的名字

_layer_names

私有屬性
返回layer們的名字

_inputs

私有屬性。
返回`net_input_blob_indices_`,也就是網路輸入們的索引們

_outputs

私有屬性。
返回`net_output_blob_indices_`,也就是網路輸出們的索引們

_set_input_arrays(?)

私有函式。
設定網路輸入?(不懂)

save(pth)

@param pth: 字串型別。指定儲存的路徑。
@description: 儲存當前網路物件到檔案(磁碟)。呼叫的是C++`void Net_Save(const Net<Dtype>& net, string filename) `