Caffe 可变批量大小
Caffe variable batch size
我知道如果我有如下输入层,我的网络将接收维度 (1,1,100,100)
.
的 blob
layer {
name: "data"
type: "Input"
top: "data"
input_param {
shape {
dim: 1
dim: 1
dim: 100
dim: 100
}
}
}
我应该怎么做才能使第一个维度(输入批量大小)可变?这样我就可以将不同大小的网络批量输入?
您可以在调用 forward()
方法之前重塑网络。所以如果你想要一个变量 batch_size,你应该每次都重塑。这可以在您使用的任何界面(C、python、MATLAB)中完成。
在python中是这样的:
net.blobs['data'].reshape(BATCH_SIZE, CHANNELS, HEIGHT, WIDTH)
net.reshape()
net.forward()
提示:我相信 net.reshape()
是可选的,网络会在执行转发操作之前调用它。
除了 AHA 的答案,在 c++ 中它就像
Blob<float>* input_layer = net_->input_blobs()[0];
input_layer->Reshape(batch_size, input_layer->shape(1), input_layer->shape(2), input_layer->shape(3));
net_->Reshape();
我知道如果我有如下输入层,我的网络将接收维度 (1,1,100,100)
.
layer {
name: "data"
type: "Input"
top: "data"
input_param {
shape {
dim: 1
dim: 1
dim: 100
dim: 100
}
}
}
我应该怎么做才能使第一个维度(输入批量大小)可变?这样我就可以将不同大小的网络批量输入?
您可以在调用 forward()
方法之前重塑网络。所以如果你想要一个变量 batch_size,你应该每次都重塑。这可以在您使用的任何界面(C、python、MATLAB)中完成。
在python中是这样的:
net.blobs['data'].reshape(BATCH_SIZE, CHANNELS, HEIGHT, WIDTH)
net.reshape()
net.forward()
提示:我相信 net.reshape()
是可选的,网络会在执行转发操作之前调用它。
除了 AHA 的答案,在 c++ 中它就像
Blob<float>* input_layer = net_->input_blobs()[0];
input_layer->Reshape(batch_size, input_layer->shape(1), input_layer->shape(2), input_layer->shape(3));
net_->Reshape();