void KinectInterfacePrimesense::init(const char* device_uri) {
    initOpenNI(device_uri);

    // Create a thread pool for parallelizing the UVD to depth calculations
    uint32_t num_threads = KINECT_INTERFACE_NUM_WORKER_THREADS;
    tp_ = new jtil::threading::ThreadPool(num_threads);
    if (KINECT_INTERFACE_NUM_CONVERTER_THREADS > 1) {
      uint32_t n_pixels = depth_dim_[0] * depth_dim_[1];
      uint32_t n_pixels_per_thread = 1 + n_pixels / num_threads;  // round up
      for (uint32_t i = 0; i < num_threads; i++) {
        uint32_t start = i * n_pixels_per_thread;
        uint32_t end = std::min<uint32_t>(((i + 1) * n_pixels_per_thread) - 1,
          n_pixels - 1);
        pts_world_thread_cbs_.pushBack(MakeCallableMany(
          &KinectInterfacePrimesense::convertDepthToWorld, this, start, end));
        rgb_thread_cbs_.pushBack(MakeCallableMany(
          &KinectInterfacePrimesense::convertRGBToDepth, this, start, end));
      }
    }

    if (device_uri) {
      cout << "Finished initializing device " << device_uri << "..." << endl;
    } else {
      cout << "Finished initializing openNI device..." << endl;
    }
  }
Пример #2
0
void SpatialLPPooling::init(std::shared_ptr<TorchData> input) {
  RASSERT(input->type() == TorchDataType::TENSOR_DATA);
  Tensor<float>* in = TO_TENSOR_PTR(input.get());
  RASSERT(in->dim() == 2 || in->dim() == 3);

  if (output != nullptr && TO_TENSOR_PTR(output.get())->dim() != in->dim()) {
    // Input dimension has changed!
    cleanup();
  }

  if (output != nullptr) {
    // Check that the dimensions above the lowest 2 match
    for (uint32_t i = 2; i < in->dim() && output != nullptr; i++) {
      if (TO_TENSOR_PTR(output.get())->size()[i] != in->size()[i]) {
        cleanup();
      }
    }
  }

  if (output != nullptr) {
    // Check that the lowest 2 dimensions are the correct size
    if (TO_TENSOR_PTR(output.get())->size()[0] != in->size()[0] / poolsize_u_ ||
        TO_TENSOR_PTR(output.get())->size()[1] != in->size()[1] / poolsize_v_) {
      cleanup();
    }
  }

  if (output == nullptr) {
    // Check that the width and height is a multiple of the poolsize
    RASSERT(in->size()[0] % poolsize_u_ == 0 &&
           in->size()[1] % poolsize_v_ == 0);

    std::unique_ptr<uint32_t[]> out_size(new uint32_t[in->dim()]);
    out_size[0] = in->size()[0] / poolsize_u_;
    out_size[1] = in->size()[1] / poolsize_v_;
    for (uint32_t i = 2; i < in->dim(); i++) {
      out_size[i] = in->size()[i];
    }

    output.reset(new Tensor<float>(in->dim(), out_size.get()));
    input_cpu_.reset(new float[in->nelems()]);
    output_cpu_.reset(new float[TO_TENSOR_PTR(output.get())->nelems()]);
  }

  uint32_t n_threads = 1;
  if (in->dim() > 2) {
    n_threads = TO_TENSOR_PTR(output.get())->size()[2];
  }
  if (thread_cbs_.size() != n_threads) {
    thread_cbs_.empty();
    for (uint32_t f = 0; f < n_threads; f++) {
      thread_cbs_.push_back(std::unique_ptr<jcl::threading::Callback<void>>(
          MakeCallableMany(&SpatialLPPooling::forwardPropThread, this, f)));
    }
  }
}