void configure_split_layer(const string& layer_name, const string& blob_name,
const int blob_idx, const int split_count,
- LayerConnection* split_layer_connection);
+ LayerParameter* split_layer_param);
string get_split_layer_name(const string& layer_name, const string& blob_name,
const int blob_idx);
int M_;
int K_;
int N_;
- bool biasterm_;
+ bool bias_term_;
shared_ptr<SyncedMemory> bias_multiplier_;
};
int GROUP_;
Blob<Dtype> col_buffer_;
shared_ptr<SyncedMemory> bias_multiplier_;
- bool biasterm_;
+ bool bias_term_;
int M_;
int K_;
int N_;
"Concat Layer takes at least two blobs as input.";
CHECK_EQ(top->size(), 1) <<
"Concat Layer takes a single blob as output.";
- concat_dim_ = this->layer_param_.concat_dim();
+ concat_dim_ = this->layer_param_.concat_param().concat_dim();
CHECK_GE(concat_dim_, 0) << "concat_dim should be >= 0";
CHECK_LE(concat_dim_, 1) <<
"For now concat_dim <=1, it can only concat num and channels";
vector<Blob<Dtype>*>* top) {
CHECK_EQ(bottom.size(), 1) << "Conv Layer takes a single blob as input.";
CHECK_EQ(top->size(), 1) << "Conv Layer takes a single blob as output.";
- KSIZE_ = this->layer_param_.kernelsize();
- STRIDE_ = this->layer_param_.stride();
- GROUP_ = this->layer_param_.group();
- PAD_ = this->layer_param_.pad();
+ KSIZE_ = this->layer_param_.convolution_param().kernel_size();
+ STRIDE_ = this->layer_param_.convolution_param().stride();
+ GROUP_ = this->layer_param_.convolution_param().group();
+ PAD_ = this->layer_param_.convolution_param().pad();
NUM_ = bottom[0]->num();
CHANNELS_ = bottom[0]->channels();
HEIGHT_ = bottom[0]->height();
WIDTH_ = bottom[0]->width();
- NUM_OUTPUT_ = this->layer_param_.num_output();
+ NUM_OUTPUT_ = this->layer_param_.convolution_param().num_output();
CHECK_GT(NUM_OUTPUT_, 0);
CHECK_EQ(CHANNELS_ % GROUP_, 0);
// The im2col result buffer would only hold one image at a time to avoid
// Set the parameters
CHECK_EQ(NUM_OUTPUT_ % GROUP_, 0)
<< "Number of output should be multiples of group.";
- biasterm_ = this->layer_param_.biasterm();
+ bias_term_ = this->layer_param_.convolution_param().bias_term();
// Figure out the dimensions for individual gemms.
M_ = NUM_OUTPUT_ / GROUP_;
K_ = CHANNELS_ * KSIZE_ * KSIZE_ / GROUP_;
if (this->blobs_.size() > 0) {
LOG(INFO) << "Skipping parameter initialization";
} else {
- if (biasterm_) {
+ if (bias_term_) {
this->blobs_.resize(2);
} else {
this->blobs_.resize(1);
this->blobs_[0].reset(
new Blob<Dtype>(NUM_OUTPUT_, CHANNELS_ / GROUP_, KSIZE_, KSIZE_));
// fill the weights
- shared_ptr<Filler<Dtype> > weight_filler(
- GetFiller<Dtype>(this->layer_param_.weight_filler()));
+ shared_ptr<Filler<Dtype> > weight_filler(GetFiller<Dtype>(
+ this->layer_param_.convolution_param().weight_filler()));
weight_filler->Fill(this->blobs_[0].get());
// If necessary, intiialize and fill the bias term
- if (biasterm_) {
+ if (bias_term_) {
this->blobs_[1].reset(new Blob<Dtype>(1, 1, 1, NUM_OUTPUT_));
- shared_ptr<Filler<Dtype> > bias_filler(
- GetFiller<Dtype>(this->layer_param_.bias_filler()));
+ shared_ptr<Filler<Dtype> > bias_filler(GetFiller<Dtype>(
+ this->layer_param_.convolution_param().bias_filler()));
bias_filler->Fill(this->blobs_[1].get());
}
}
// Set up the bias filler
- if (biasterm_) {
+ if (bias_term_) {
bias_multiplier_.reset(new SyncedMemory(N_ * sizeof(Dtype)));
Dtype* bias_multiplier_data =
reinterpret_cast<Dtype*>(bias_multiplier_->mutable_cpu_data());
(Dtype)0., top_data + (*top)[0]->offset(n) + top_offset * g);
}
// third, add bias
- if (biasterm_) {
+ if (bias_term_) {
caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, NUM_OUTPUT_,
N_, 1, (Dtype)1., this->blobs_[1]->cpu_data(),
reinterpret_cast<const Dtype*>(bias_multiplier_->cpu_data()),
// bias gradient if necessary
Dtype* bias_diff = NULL;
- if (biasterm_) {
+ if (bias_term_) {
bias_diff = this->blobs_[1]->mutable_cpu_diff();
memset(bias_diff, 0, sizeof(Dtype) * this->blobs_[1]->count());
for (int n = 0; n < NUM_; ++n) {
(Dtype)0., top_data + (*top)[0]->offset(n) + top_offset * g);
}
// third, add bias
- if (biasterm_) {
+ if (bias_term_) {
caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, NUM_OUTPUT_,
N_, 1, (Dtype)1., this->blobs_[1]->gpu_data(),
reinterpret_cast<const Dtype*>(bias_multiplier_->gpu_data()),
// bias gradient if necessary
Dtype* bias_diff = NULL;
- if (biasterm_) {
+ if (bias_term_) {
bias_diff = this->blobs_[1]->mutable_gpu_diff();
CUDA_CHECK(cudaMemset(bias_diff, 0,
sizeof(Dtype) * this->blobs_[1]->count()));
CHECK(layer->prefetch_data_);
Dtype* top_data = layer->prefetch_data_->mutable_cpu_data();
Dtype* top_label = layer->prefetch_label_->mutable_cpu_data();
- const Dtype scale = layer->layer_param_.scale();
- const int batchsize = layer->layer_param_.batchsize();
- const int cropsize = layer->layer_param_.cropsize();
- const bool mirror = layer->layer_param_.mirror();
+ const Dtype scale = layer->layer_param_.data_param().scale();
+ const int batch_size = layer->layer_param_.data_param().batch_size();
+ const int crop_size = layer->layer_param_.data_param().crop_size();
+ const bool mirror = layer->layer_param_.data_param().mirror();
- if (mirror && cropsize == 0) {
- LOG(FATAL) << "Current implementation requires mirror and cropsize to be "
+ if (mirror && crop_size == 0) {
+ LOG(FATAL) << "Current implementation requires mirror and crop_size to be "
<< "set at the same time.";
}
// datum scales
const int width = layer->datum_width_;
const int size = layer->datum_size_;
const Dtype* mean = layer->data_mean_.cpu_data();
- for (int itemid = 0; itemid < batchsize; ++itemid) {
+ for (int item_id = 0; item_id < batch_size; ++item_id) {
// get a blob
CHECK(layer->iter_);
CHECK(layer->iter_->Valid());
datum.ParseFromString(layer->iter_->value().ToString());
const string& data = datum.data();
- if (cropsize) {
+ if (crop_size) {
CHECK(data.size()) << "Image cropping only support uint8 data";
int h_off, w_off;
// We only do random crop when we do training.
if (Caffe::phase() == Caffe::TRAIN) {
// NOLINT_NEXT_LINE(runtime/threadsafe_fn)
- h_off = rand() % (height - cropsize);
+ h_off = rand() % (height - crop_size);
// NOLINT_NEXT_LINE(runtime/threadsafe_fn)
- w_off = rand() % (width - cropsize);
+ w_off = rand() % (width - crop_size);
} else {
- h_off = (height - cropsize) / 2;
- w_off = (width - cropsize) / 2;
+ h_off = (height - crop_size) / 2;
+ w_off = (width - crop_size) / 2;
}
// NOLINT_NEXT_LINE(runtime/threadsafe_fn)
if (mirror && rand() % 2) {
// Copy mirrored version
for (int c = 0; c < channels; ++c) {
- for (int h = 0; h < cropsize; ++h) {
- for (int w = 0; w < cropsize; ++w) {
- top_data[((itemid * channels + c) * cropsize + h) * cropsize
- + cropsize - 1 - w] =
+ for (int h = 0; h < crop_size; ++h) {
+ for (int w = 0; w < crop_size; ++w) {
+ top_data[((item_id * channels + c) * crop_size + h) * crop_size
+ + crop_size - 1 - w] =
(static_cast<Dtype>(
(uint8_t)data[(c * height + h + h_off) * width
+ w + w_off])
} else {
// Normal copy
for (int c = 0; c < channels; ++c) {
- for (int h = 0; h < cropsize; ++h) {
- for (int w = 0; w < cropsize; ++w) {
- top_data[((itemid * channels + c) * cropsize + h) * cropsize + w]
+ for (int h = 0; h < crop_size; ++h) {
+ for (int w = 0; w < crop_size; ++w) {
+ top_data[((item_id * channels + c) * crop_size + h) * crop_size
+ + w]
= (static_cast<Dtype>(
(uint8_t)data[(c * height + h + h_off) * width
+ w + w_off])
// we will prefer to use data() first, and then try float_data()
if (data.size()) {
for (int j = 0; j < size; ++j) {
- top_data[itemid * size + j] =
+ top_data[item_id * size + j] =
(static_cast<Dtype>((uint8_t)data[j]) - mean[j]) * scale;
}
} else {
for (int j = 0; j < size; ++j) {
- top_data[itemid * size + j] =
+ top_data[item_id * size + j] =
(datum.float_data(j) - mean[j]) * scale;
}
}
}
- top_label[itemid] = datum.label();
+ top_label[item_id] = datum.label();
// go to the next iter
layer->iter_->Next();
if (!layer->iter_->Valid()) {
leveldb::Options options;
options.create_if_missing = false;
options.max_open_files = 100;
- LOG(INFO) << "Opening leveldb " << this->layer_param_.source();
+ LOG(INFO) << "Opening leveldb " << this->layer_param_.data_param().source();
leveldb::Status status = leveldb::DB::Open(
- options, this->layer_param_.source(), &db_temp);
+ options, this->layer_param_.data_param().source(), &db_temp);
CHECK(status.ok()) << "Failed to open leveldb "
- << this->layer_param_.source() << std::endl << status.ToString();
+ << this->layer_param_.data_param().source() << std::endl
+ << status.ToString();
db_.reset(db_temp);
iter_.reset(db_->NewIterator(leveldb::ReadOptions()));
iter_->SeekToFirst();
// Check if we would need to randomly skip a few data points
- if (this->layer_param_.rand_skip()) {
+ if (this->layer_param_.data_param().rand_skip()) {
// NOLINT_NEXT_LINE(runtime/threadsafe_fn)
- unsigned int skip = rand() % this->layer_param_.rand_skip();
+ unsigned int skip = rand() % this->layer_param_.data_param().rand_skip();
LOG(INFO) << "Skipping first " << skip << " data points.";
while (skip-- > 0) {
iter_->Next();
Datum datum;
datum.ParseFromString(iter_->value().ToString());
// image
- int cropsize = this->layer_param_.cropsize();
- if (cropsize > 0) {
- (*top)[0]->Reshape(
- this->layer_param_.batchsize(), datum.channels(), cropsize, cropsize);
+ int crop_size = this->layer_param_.data_param().crop_size();
+ if (crop_size > 0) {
+ (*top)[0]->Reshape(this->layer_param_.data_param().batch_size(),
+ datum.channels(), crop_size, crop_size);
prefetch_data_.reset(new Blob<Dtype>(
- this->layer_param_.batchsize(), datum.channels(), cropsize, cropsize));
+ this->layer_param_.data_param().batch_size(), datum.channels(),
+ crop_size, crop_size));
} else {
(*top)[0]->Reshape(
- this->layer_param_.batchsize(), datum.channels(), datum.height(),
- datum.width());
+ this->layer_param_.data_param().batch_size(), datum.channels(),
+ datum.height(), datum.width());
prefetch_data_.reset(new Blob<Dtype>(
- this->layer_param_.batchsize(), datum.channels(), datum.height(),
- datum.width()));
+ this->layer_param_.data_param().batch_size(), datum.channels(),
+ datum.height(), datum.width()));
}
LOG(INFO) << "output data size: " << (*top)[0]->num() << ","
<< (*top)[0]->channels() << "," << (*top)[0]->height() << ","
<< (*top)[0]->width();
// label
- (*top)[1]->Reshape(this->layer_param_.batchsize(), 1, 1, 1);
+ (*top)[1]->Reshape(this->layer_param_.data_param().batch_size(), 1, 1, 1);
prefetch_label_.reset(
- new Blob<Dtype>(this->layer_param_.batchsize(), 1, 1, 1));
+ new Blob<Dtype>(this->layer_param_.data_param().batch_size(), 1, 1, 1));
// datum size
datum_channels_ = datum.channels();
datum_height_ = datum.height();
datum_width_ = datum.width();
datum_size_ = datum.channels() * datum.height() * datum.width();
- CHECK_GT(datum_height_, cropsize);
- CHECK_GT(datum_width_, cropsize);
+ CHECK_GT(datum_height_, crop_size);
+ CHECK_GT(datum_width_, crop_size);
// check if we want to have mean
- if (this->layer_param_.has_meanfile()) {
+ if (this->layer_param_.data_param().has_meanfile()) {
BlobProto blob_proto;
- LOG(INFO) << "Loading mean file from" << this->layer_param_.meanfile();
- ReadProtoFromBinaryFile(this->layer_param_.meanfile().c_str(), &blob_proto);
+ LOG(INFO) << "Loading mean file from"
+ << this->layer_param_.data_param().meanfile();
+ ReadProtoFromBinaryFile(this->layer_param_.data_param().meanfile().c_str(),
+ &blob_proto);
data_mean_.FromProto(blob_proto);
CHECK_EQ(data_mean_.num(), 1);
CHECK_EQ(data_mean_.channels(), datum_channels_);
NeuronLayer<Dtype>::SetUp(bottom, top);
// Set up the cache for random number generation
rand_vec_.reset(new SyncedMemory(bottom[0]->count() * sizeof(int)));
- threshold_ = this->layer_param_.dropout_ratio();
+ threshold_ = this->layer_param_.dropout_param().dropout_ratio();
DCHECK(threshold_ > 0.);
DCHECK(threshold_ < 1.);
scale_ = 1. / (1. - threshold_);
CHECK_EQ(top->size(), 2) << "HDF5DataLayer takes two blobs as output.";
// Read the source to parse the filenames.
- LOG(INFO) << "Loading filename from " << this->layer_param_.source();
+ const string& source = this->layer_param_.hdf5_data_param().source();
+ LOG(INFO) << "Loading filename from " << source;
hdf_filenames_.clear();
- std::ifstream myfile(this->layer_param_.source().c_str());
- if (myfile.is_open()) {
+ std::ifstream source_file(source.c_str());
+ if (source_file.is_open()) {
std::string line;
- while (myfile >> line) {
+ while (source_file >> line) {
hdf_filenames_.push_back(line);
}
}
- myfile.close();
+ source_file.close();
num_files_ = hdf_filenames_.size();
current_file_ = 0;
LOG(INFO) << "Number of files: " << num_files_;
current_row_ = 0;
// Reshape blobs.
- (*top)[0]->Reshape(this->layer_param_.batchsize(), data_blob_.channels(),
+ const int batch_size = this->layer_param_.hdf5_data_param().batch_size();
+ (*top)[0]->Reshape(batch_size, data_blob_.channels(),
data_blob_.width(), data_blob_.height());
- (*top)[1]->Reshape(this->layer_param_.batchsize(), label_blob_.channels(),
+ (*top)[1]->Reshape(batch_size, label_blob_.channels(),
label_blob_.width(), label_blob_.height());
LOG(INFO) << "output data size: " << (*top)[0]->num() << ","
<< (*top)[0]->channels() << "," << (*top)[0]->height() << ","
template <typename Dtype>
Dtype HDF5DataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top) {
- const int batchsize = this->layer_param_.batchsize();
+ const int batch_size = this->layer_param_.hdf5_data_param().batch_size();
const int data_count = (*top)[0]->count() / (*top)[0]->num();
const int label_data_count = (*top)[1]->count() / (*top)[1]->num();
- for (int i = 0; i < batchsize; ++i, ++current_row_) {
+ for (int i = 0; i < batch_size; ++i, ++current_row_) {
if (current_row_ == data_blob_.num()) {
if (num_files_ > 1) {
current_file_ += 1;
template <typename Dtype>
Dtype HDF5DataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top) {
- const int batchsize = this->layer_param_.batchsize();
+ const int batch_size = this->layer_param_.hdf5_data_param().batch_size();
const int data_count = (*top)[0]->count() / (*top)[0]->num();
const int label_data_count = (*top)[1]->count() / (*top)[1]->num();
- for (int i = 0; i < batchsize; ++i, ++current_row_) {
+ for (int i = 0; i < batch_size; ++i, ++current_row_) {
if (current_row_ == data_blob_.num()) {
if (num_files_ > 1) {
current_file_ += 1;
vector<Blob<Dtype>*>* top) {
CHECK_EQ(bottom.size(), 1) << "Im2col Layer takes a single blob as input.";
CHECK_EQ(top->size(), 1) << "Im2col Layer takes a single blob as output.";
- KSIZE_ = this->layer_param_.kernelsize();
- STRIDE_ = this->layer_param_.stride();
- PAD_ = this->layer_param_.pad();
+ KSIZE_ = this->layer_param_.convolution_param().kernel_size();
+ STRIDE_ = this->layer_param_.convolution_param().stride();
+ PAD_ = this->layer_param_.convolution_param().pad();
CHANNELS_ = bottom[0]->channels();
HEIGHT_ = bottom[0]->height();
WIDTH_ = bottom[0]->width();
vector<Blob<Dtype>*>* top) {
CHECK_EQ(bottom.size(), 1) << "IP Layer takes a single blob as input.";
CHECK_EQ(top->size(), 1) << "IP Layer takes a single blob as output.";
- const int num_output = this->layer_param_.num_output();
- biasterm_ = this->layer_param_.biasterm();
+ const int num_output = this->layer_param_.inner_product_param().num_output();
+ bias_term_ = this->layer_param_.inner_product_param().bias_term();
// Figure out the dimensions
M_ = bottom[0]->num();
K_ = bottom[0]->count() / bottom[0]->num();
if (this->blobs_.size() > 0) {
LOG(INFO) << "Skipping parameter initialization";
} else {
- if (biasterm_) {
+ if (bias_term_) {
this->blobs_.resize(2);
} else {
this->blobs_.resize(1);
// Intialize the weight
this->blobs_[0].reset(new Blob<Dtype>(1, 1, N_, K_));
// fill the weights
- shared_ptr<Filler<Dtype> > weight_filler(
- GetFiller<Dtype>(this->layer_param_.weight_filler()));
+ shared_ptr<Filler<Dtype> > weight_filler(GetFiller<Dtype>(
+ this->layer_param_.inner_product_param().weight_filler()));
weight_filler->Fill(this->blobs_[0].get());
// If necessary, intiialize and fill the bias term
- if (biasterm_) {
+ if (bias_term_) {
this->blobs_[1].reset(new Blob<Dtype>(1, 1, 1, N_));
- shared_ptr<Filler<Dtype> > bias_filler(
- GetFiller<Dtype>(this->layer_param_.bias_filler()));
+ shared_ptr<Filler<Dtype> > bias_filler(GetFiller<Dtype>(
+ this->layer_param_.inner_product_param().bias_filler()));
bias_filler->Fill(this->blobs_[1].get());
}
} // parameter initialization
// Setting up the bias multiplier
- if (biasterm_) {
+ if (bias_term_) {
bias_multiplier_.reset(new SyncedMemory(M_ * sizeof(Dtype)));
Dtype* bias_multiplier_data =
reinterpret_cast<Dtype*>(bias_multiplier_->mutable_cpu_data());
const Dtype* weight = this->blobs_[0]->cpu_data();
caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasTrans, M_, N_, K_, (Dtype)1.,
bottom_data, weight, (Dtype)0., top_data);
- if (biasterm_) {
+ if (bias_term_) {
caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,
reinterpret_cast<const Dtype*>(bias_multiplier_->cpu_data()),
this->blobs_[1]->cpu_data(), (Dtype)1., top_data);
// Gradient with respect to weight
caffe_cpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,
top_diff, bottom_data, (Dtype)0., this->blobs_[0]->mutable_cpu_diff());
- if (biasterm_) {
+ if (bias_term_) {
// Gradient with respect to bias
caffe_cpu_gemv<Dtype>(CblasTrans, M_, N_, (Dtype)1., top_diff,
reinterpret_cast<const Dtype*>(bias_multiplier_->cpu_data()), (Dtype)0.,
const Dtype* weight = this->blobs_[0]->gpu_data();
caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasTrans, M_, N_, K_, (Dtype)1.,
bottom_data, weight, (Dtype)0., top_data);
- if (biasterm_) {
+ if (bias_term_) {
caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,
reinterpret_cast<const Dtype*>(bias_multiplier_->gpu_data()),
this->blobs_[1]->gpu_data(), (Dtype)1., top_data);
// Gradient with respect to weight
caffe_gpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,
top_diff, bottom_data, (Dtype)0., this->blobs_[0]->mutable_gpu_diff());
- if (biasterm_) {
+ if (bias_term_) {
// Gradient with respect to bias
caffe_gpu_gemv<Dtype>(CblasTrans, M_, N_, (Dtype)1., top_diff,
reinterpret_cast<const Dtype*>(bias_multiplier_->gpu_data()),
CHECK_EQ(bottom[1]->height(), 1);
CHECK_EQ(bottom[1]->width(), 1);
BlobProto blob_proto;
- ReadProtoFromBinaryFile(this->layer_param_.source(), &blob_proto);
+ ReadProtoFromBinaryFile(this->layer_param_.infogain_loss_param().source(),
+ &blob_proto);
infogain_.FromProto(blob_proto);
CHECK_EQ(infogain_.num(), 1);
CHECK_EQ(infogain_.channels(), 1);
width_ = bottom[0]->width();
(*top)[0]->Reshape(num_, channels_, height_, width_);
scale_.Reshape(num_, channels_, height_, width_);
- size_ = this->layer_param_.local_size();
+ size_ = this->layer_param_.lrn_param().local_size();
pre_pad_ = (size_ - 1) / 2;
- alpha_ = this->layer_param_.alpha();
- beta_ = this->layer_param_.beta();
+ alpha_ = this->layer_param_.lrn_param().alpha();
+ beta_ = this->layer_param_.lrn_param().beta();
}
template <typename Dtype>
vector<Blob<Dtype>*>* top) {
CHECK_EQ(bottom.size(), 1) << "PoolingLayer takes a single blob as input.";
CHECK_EQ(top->size(), 1) << "PoolingLayer takes a single blob as output.";
- KSIZE_ = this->layer_param_.kernelsize();
- STRIDE_ = this->layer_param_.stride();
+ KSIZE_ = this->layer_param_.pooling_param().kernel_size();
+ STRIDE_ = this->layer_param_.pooling_param().stride();
CHANNELS_ = bottom[0]->channels();
HEIGHT_ = bottom[0]->height();
WIDTH_ = bottom[0]->width();
(*top)[0]->Reshape(bottom[0]->num(), CHANNELS_, POOLED_HEIGHT_,
POOLED_WIDTH_);
// If stochastic pooling, we will initialize the random index part.
- if (this->layer_param_.pool() == LayerParameter_PoolMethod_STOCHASTIC) {
+ if (this->layer_param_.pooling_param().pool() ==
+ PoolingParameter_PoolMethod_STOCHASTIC) {
rand_idx_.Reshape(bottom[0]->num(), CHANNELS_, POOLED_HEIGHT_,
POOLED_WIDTH_);
}
// Different pooling methods. We explicitly do the switch outside the for
// loop to save time, although this results in more codes.
int top_count = (*top)[0]->count();
- switch (this->layer_param_.pool()) {
- case LayerParameter_PoolMethod_MAX:
+ switch (this->layer_param_.pooling_param().pool()) {
+ case PoolingParameter_PoolMethod_MAX:
// Initialize
for (int i = 0; i < top_count; ++i) {
top_data[i] = -FLT_MAX;
}
}
break;
- case LayerParameter_PoolMethod_AVE:
+ case PoolingParameter_PoolMethod_AVE:
for (int i = 0; i < top_count; ++i) {
top_data[i] = 0;
}
}
}
break;
- case LayerParameter_PoolMethod_STOCHASTIC:
+ case PoolingParameter_PoolMethod_STOCHASTIC:
NOT_IMPLEMENTED;
break;
default:
// Different pooling methods. We explicitly do the switch outside the for
// loop to save time, although this results in more codes.
memset(bottom_diff, 0, (*bottom)[0]->count() * sizeof(Dtype));
- switch (this->layer_param_.pool()) {
- case LayerParameter_PoolMethod_MAX:
+ switch (this->layer_param_.pooling_param().pool()) {
+ case PoolingParameter_PoolMethod_MAX:
// The main loop
for (int n = 0; n < top[0]->num(); ++n) {
for (int c = 0; c < CHANNELS_; ++c) {
}
}
break;
- case LayerParameter_PoolMethod_AVE:
+ case PoolingParameter_PoolMethod_AVE:
// The main loop
for (int n = 0; n < top[0]->num(); ++n) {
for (int c = 0; c < CHANNELS_; ++c) {
}
}
break;
- case LayerParameter_PoolMethod_STOCHASTIC:
+ case PoolingParameter_PoolMethod_STOCHASTIC:
NOT_IMPLEMENTED;
break;
default:
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = (*top)[0]->mutable_gpu_data();
int count = (*top)[0]->count();
- switch (this->layer_param_.pool()) {
- case LayerParameter_PoolMethod_MAX:
+ switch (this->layer_param_.pooling_param().pool()) {
+ case PoolingParameter_PoolMethod_MAX:
// NOLINT_NEXT_LINE(whitespace/operators)
MaxPoolForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, bottom_data, bottom[0]->num(), CHANNELS_,
HEIGHT_, WIDTH_, POOLED_HEIGHT_, POOLED_WIDTH_, KSIZE_, STRIDE_,
top_data);
break;
- case LayerParameter_PoolMethod_AVE:
+ case PoolingParameter_PoolMethod_AVE:
// NOLINT_NEXT_LINE(whitespace/operators)
AvePoolForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, bottom_data, bottom[0]->num(), CHANNELS_,
HEIGHT_, WIDTH_, POOLED_HEIGHT_, POOLED_WIDTH_, KSIZE_, STRIDE_,
top_data);
break;
- case LayerParameter_PoolMethod_STOCHASTIC:
+ case PoolingParameter_PoolMethod_STOCHASTIC:
if (Caffe::phase() == Caffe::TRAIN) {
// We need to create the random index as well.
CURAND_CHECK(curandGenerateUniform(Caffe::curand_generator(),
const Dtype* top_diff = top[0]->gpu_diff();
Dtype* bottom_diff = (*bottom)[0]->mutable_gpu_diff();
int count = (*bottom)[0]->count();
- switch (this->layer_param_.pool()) {
- case LayerParameter_PoolMethod_MAX:
+ switch (this->layer_param_.pooling_param().pool()) {
+ case PoolingParameter_PoolMethod_MAX:
// NOLINT_NEXT_LINE(whitespace/operators)
MaxPoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, (*bottom)[0]->gpu_data(), top[0]->gpu_data(), top_diff,
top[0]->num(), CHANNELS_, HEIGHT_, WIDTH_, POOLED_HEIGHT_,
POOLED_WIDTH_, KSIZE_, STRIDE_, bottom_diff);
break;
- case LayerParameter_PoolMethod_AVE:
+ case PoolingParameter_PoolMethod_AVE:
// NOLINT_NEXT_LINE(whitespace/operators)
AvePoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, top_diff, top[0]->num(), CHANNELS_,
HEIGHT_, WIDTH_, POOLED_HEIGHT_, POOLED_WIDTH_, KSIZE_, STRIDE_,
bottom_diff);
break;
- case LayerParameter_PoolMethod_STOCHASTIC:
+ case PoolingParameter_PoolMethod_STOCHASTIC:
// NOLINT_NEXT_LINE(whitespace/operators)
StoPoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
count, rand_idx_.gpu_data(), top_diff,
name_ = param.name();
map<string, int> blob_name_to_idx;
set<string> available_blobs;
- int num_layers = param.layers_size();
+ int num_layers = param.layer_size();
CHECK_EQ(param.input_size() * 4, param.input_dim_size())
<< "Incorrect bottom blob dimension specifications.";
size_t memory_used = 0;
}
DLOG(INFO) << "Memory required for Data" << memory_used*sizeof(Dtype);
// For each layer, set up their input and output
- bottom_vecs_.resize(param.layers_size());
- top_vecs_.resize(param.layers_size());
- bottom_id_vecs_.resize(param.layers_size());
- top_id_vecs_.resize(param.layers_size());
- for (int i = 0; i < param.layers_size(); ++i) {
+ bottom_vecs_.resize(param.layer_size());
+ top_vecs_.resize(param.layer_size());
+ bottom_id_vecs_.resize(param.layer_size());
+ top_id_vecs_.resize(param.layer_size());
+ for (int i = 0; i < param.layer_size(); ++i) {
bool in_place = false;
- const LayerConnection& layer_connection = param.layers(i);
- const LayerParameter& layer_param = layer_connection.layer();
+ const LayerParameter& layer_param = param.layer(i);
layers_.push_back(shared_ptr<Layer<Dtype> >(GetLayer<Dtype>(layer_param)));
layer_names_.push_back(layer_param.name());
LOG(INFO) << "Creating Layer " << layer_param.name();
bool need_backward = param.force_backward();
// Figure out this layer's input and output
- for (int j = 0; j < layer_connection.bottom_size(); ++j) {
- const string& blob_name = layer_connection.bottom(j);
+ for (int j = 0; j < layer_param.bottom_size(); ++j) {
+ const string& blob_name = layer_param.bottom(j);
const int blob_id = blob_name_to_idx[blob_name];
if (available_blobs.find(blob_name) == available_blobs.end()) {
LOG(FATAL) << "Unknown blob input " << blob_name <<
need_backward |= blob_need_backward_[blob_id];
available_blobs.erase(blob_name);
}
- for (int j = 0; j < layer_connection.top_size(); ++j) {
- const string& blob_name = layer_connection.top(j);
+ for (int j = 0; j < layer_param.top_size(); ++j) {
+ const string& blob_name = layer_param.top(j);
// Check if we are doing in-place computation
- if (layer_connection.bottom_size() > j &&
- blob_name == layer_connection.bottom(j)) {
+ if (layer_param.bottom_size() > j &&
+ blob_name == layer_param.bottom(j)) {
// In-place computation
LOG(INFO) << layer_param.name() << " -> " << blob_name << " (in-place)";
in_place = true;
template <typename Dtype>
void Net<Dtype>::CopyTrainedLayersFrom(const NetParameter& param) {
- int num_source_layers = param.layers_size();
+ int num_source_layers = param.layer_size();
for (int i = 0; i < num_source_layers; ++i) {
- const LayerParameter& source_layer = param.layers(i).layer();
+ const LayerParameter& source_layer = param.layer(i);
const string& source_layer_name = source_layer.name();
int target_layer_id = 0;
while (target_layer_id != layer_names_.size() &&
}
DLOG(INFO) << "Serializing " << layers_.size() << " layers";
for (int i = 0; i < layers_.size(); ++i) {
- LayerConnection* layer_connection = param->add_layers();
+ LayerParameter* layer_param = param->add_layer();
for (int j = 0; j < bottom_id_vecs_[i].size(); ++j) {
- layer_connection->add_bottom(blob_names_[bottom_id_vecs_[i][j]]);
+ layer_param->add_bottom(blob_names_[bottom_id_vecs_[i][j]]);
}
for (int j = 0; j < top_id_vecs_[i].size(); ++j) {
- layer_connection->add_top(blob_names_[top_id_vecs_[i][j]]);
+ layer_param->add_top(blob_names_[top_id_vecs_[i][j]]);
}
- LayerParameter* layer_parameter = layer_connection->mutable_layer();
- layers_[i]->ToProto(layer_parameter, write_diff);
+ layers_[i]->ToProto(layer_param, write_diff);
}
}
void insert_splits(const NetParameter& param, NetParameter* param_split) {
// Initialize by copying from the input NetParameter.
param_split->CopyFrom(param);
- param_split->clear_layers();
+ param_split->clear_layer();
map<string, pair<int, int> > blob_name_to_last_top_idx;
map<pair<int, int>, pair<int, int> > bottom_idx_to_source_top_idx;
map<pair<int, int>, int> top_idx_to_bottom_count;
const string& blob_name = param.input(i);
blob_name_to_last_top_idx[blob_name] = make_pair(-1, i);
}
- for (int i = 0; i < param.layers_size(); ++i) {
- const LayerConnection& layer_connection = param.layers(i);
- layer_idx_to_layer_name[i] = layer_connection.layer().name();
- for (int j = 0; j < layer_connection.bottom_size(); ++j) {
- const string& blob_name = layer_connection.bottom(j);
+ for (int i = 0; i < param.layer_size(); ++i) {
+ const LayerParameter& layer_param = param.layer(i);
+ layer_idx_to_layer_name[i] = layer_param.name();
+ for (int j = 0; j < layer_param.bottom_size(); ++j) {
+ const string& blob_name = layer_param.bottom(j);
if (blob_name_to_last_top_idx.find(blob_name) ==
blob_name_to_last_top_idx.end()) {
LOG(FATAL) << "Unknown blob input " << blob_name << " to layer " << j;
bottom_idx_to_source_top_idx[bottom_idx] = top_idx;
++top_idx_to_bottom_count[top_idx];
}
- for (int j = 0; j < layer_connection.top_size(); ++j) {
- const string& blob_name = layer_connection.top(j);
+ for (int j = 0; j < layer_param.top_size(); ++j) {
+ const string& blob_name = layer_param.top(j);
blob_name_to_last_top_idx[blob_name] = make_pair(i, j);
}
}
if (split_count > 1) {
const string& layer_name = layer_idx_to_layer_name[-1];
const string& blob_name = param.input(i);
- LayerConnection* split_layer_connection = param_split->add_layers();
+ LayerParameter* split_layer_param = param_split->add_layer();
configure_split_layer(layer_name, blob_name, i, split_count,
- split_layer_connection);
+ split_layer_param);
}
}
- for (int i = 0; i < param.layers_size(); ++i) {
- LayerConnection* layer_connection = param_split->add_layers();
- layer_connection->CopyFrom(param.layers(i));
+ for (int i = 0; i < param.layer_size(); ++i) {
+ LayerParameter* layer_param = param_split->add_layer();
+ layer_param->CopyFrom(param.layer(i));
// Replace any shared bottom blobs with split layer outputs.
- for (int j = 0; j < layer_connection->bottom_size(); ++j) {
+ for (int j = 0; j < layer_param->bottom_size(); ++j) {
const pair<int, int>& top_idx =
bottom_idx_to_source_top_idx[make_pair(i, j)];
const int split_count = top_idx_to_bottom_count[top_idx];
if (split_count > 1) {
const string& layer_name = layer_idx_to_layer_name[top_idx.first];
- const string& blob_name = layer_connection->bottom(j);
- layer_connection->set_bottom(j, get_split_blob_name(layer_name,
+ const string& blob_name = layer_param->bottom(j);
+ layer_param->set_bottom(j, get_split_blob_name(layer_name,
blob_name, top_idx.second, top_idx_to_bottom_split_idx[top_idx]++));
}
}
// Create split layer for any top blobs used by other layers as bottom
// blobs more than once.
- for (int j = 0; j < layer_connection->top_size(); ++j) {
+ for (int j = 0; j < layer_param->top_size(); ++j) {
const int split_count = top_idx_to_bottom_count[make_pair(i, j)];
if (split_count > 1) {
const string& layer_name = layer_idx_to_layer_name[i];
- const string& blob_name = layer_connection->top(j);
- LayerConnection* split_layer_connection = param_split->add_layers();
+ const string& blob_name = layer_param->top(j);
+ LayerParameter* split_layer_param = param_split->add_layer();
configure_split_layer(layer_name, blob_name, j, split_count,
- split_layer_connection);
+ split_layer_param);
}
}
}
void configure_split_layer(const string& layer_name, const string& blob_name,
const int blob_idx, const int split_count,
- LayerConnection* split_layer_connection) {
- split_layer_connection->Clear();
- split_layer_connection->add_bottom(blob_name);
- LayerParameter* split_layer_param = split_layer_connection->mutable_layer();
+ LayerParameter* split_layer_param) {
+ split_layer_param->Clear();
+ split_layer_param->add_bottom(blob_name);
split_layer_param->set_name(
get_split_layer_name(layer_name, blob_name, blob_idx));
split_layer_param->set_type("split");
for (int k = 0; k < split_count; ++k) {
- split_layer_connection->add_top(
+ split_layer_param->add_top(
get_split_blob_name(layer_name, blob_name, blob_idx, k));
}
}