Esempio n. 1
0
void BaseShufflingDataLayer<Dtype>::Forward_cpu(
    const vector<Blob<Dtype>*>& bottom, vector<Blob<Dtype>*>* top) {
  int batch_size = this->layer_param_.shuffling_data_param().batch_size();
  int offset = 0;
  int N = prefetch_data_[current_buffer_].num();
  int dim = prefetch_data_[current_buffer_].count() / N;
  while (batch_size - offset) {
    if (current_row_ == N) {
      JoinPrefetchThread();
      current_row_ = 0;
      current_buffer_ = 1 - current_buffer_;
      CreatePrefetchThread();
    }
    int avail = std::min(batch_size-offset, N - current_row_);
    caffe_copy(avail * dim, prefetch_data_[current_buffer_].cpu_data() + 
               prefetch_data_[current_buffer_].offset(current_row_),
               (*top)[0]->mutable_cpu_data() + (*top)[0]->offset(offset));
    if (this->output_labels_) {
      dim = prefetch_label_[current_buffer_].count() / N;
      caffe_copy(avail * dim, prefetch_label_[current_buffer_].cpu_data() + 
                  prefetch_label_[current_buffer_].offset(current_row_),
                 (*top)[1]->mutable_cpu_data() + (*top)[1]->offset(offset));
    }
    current_row_ += avail;
    offset += avail;
  }
}
void BasePrefetchingDataLayer<Dtype>::Forward_gpu(
    const vector<Blob<Dtype>*>& bottom,
    const vector<Blob<Dtype>*>& top) {
  // First, join the thread
  JoinPrefetchThread();
  // Reshape to loaded data.
  top[0]->Reshape(
      this->prefetch_data_.num(),
      this->prefetch_data_.channels(),
      this->prefetch_data_.height(),
      this->prefetch_data_.width());
  // Copy the data
  caffe_copy(
      prefetch_data_.count(),
      prefetch_data_.cpu_data(),
      top[0]->mutable_gpu_data());
  if (this->output_labels_) {
    caffe_copy(
        prefetch_label_.count(),
        prefetch_label_.cpu_data(),
        top[1]->mutable_gpu_data());
  }
  // Start a new prefetch thread
  CreatePrefetchThread();
}
Esempio n. 3
0
void BasePrefetchingDataLayer<Dtype>::Forward_cpu(
    const vector<Blob<Dtype>*>& bottom, vector<Blob<Dtype>*>* top) {
  // First, join the thread
  JoinPrefetchThread();
  // Copy the data
  caffe_copy(prefetch_data_.count(), prefetch_data_.cpu_data(),
             (*top)[0]->mutable_cpu_data());
  if (this->output_labels_) {
    caffe_copy(prefetch_label_.count(), prefetch_label_.cpu_data(),
               (*top)[1]->mutable_cpu_data());
  }
  // Start a new prefetch thread
  CreatePrefetchThread();
}
Dtype VolumeDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  // First, join the thread
  JoinPrefetchThread();
  // Copy the data
  caffe_copy(prefetch_data_->count(), prefetch_data_->cpu_data(),
             (*top)[0]->mutable_cpu_data());
  if (output_labels_) {
    caffe_copy(prefetch_label_->count(), prefetch_label_->cpu_data(),
               (*top)[1]->mutable_cpu_data());
  }
  // Start a new prefetch thread
  CreatePrefetchThread();
  return Dtype(0.);
}
void BasePrefetchingDataLayer<Dtype>::Forward_cpu(
    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
  // First, join the thread
  JoinPrefetchThread();
  DLOG(INFO) << "Thread joined";
  // Copy the data
  caffe_copy(prefetch_data_.count(), prefetch_data_.cpu_data(),
             top[0]->mutable_cpu_data());
  DLOG(INFO) << "Prefetch copied";
  if (this->output_labels_) {
    caffe_copy(prefetch_label_.count(), prefetch_label_.cpu_data(),
               top[1]->mutable_cpu_data());
  }
  // Start a new prefetch thread
  DLOG(INFO) << "CreatePrefetchThread";
  CreatePrefetchThread();
}
VolumeDataLayer<Dtype>::~VolumeDataLayer<Dtype>() {
  JoinPrefetchThread();
}