示例#1
0
static int download_keymap(USBKeyboard *kb, const KBHwinfo *info,
                           const char *outfilename, int mapindex)
{
  if(check_mapindex(info,0,mapindex) != 0) return -1;

  uint8_t keymap[KEYMAP_NAME_LENGTH+info->num_of_keys];
  if(get_keymap(kb,mapindex,keymap,sizeof(keymap)) != 0) return -1;

  if(keymap[0] == '\0' || keymap[0] == 0xff)
    fprintf(stderr,"Warning: downloaded key map data of deleted entry.\n");

  return write_blob_to_file(outfilename,keymap,sizeof(keymap));
}
示例#2
0
TYPED_TEST(ImageDataLayerTest, TestShuffle) {
  typedef typename TypeParam::Dtype Dtype;
  std::string file_name = std::string(EXAMPLES_SOURCE_DIR) +
          std::string("test_blobs/ImageDataLayerTest_TestShuffle_")+
          std::string(typeid(Dtype).name())+std::string(".blob");

  LayerParameter param;
  ImageDataParameter* image_data_param = param.mutable_image_data_param();
  image_data_param->set_batch_size(5);
  image_data_param->set_source(this->filename_.c_str());
  image_data_param->set_shuffle(true);
  ImageDataLayer<Dtype> layer(param);
  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
  EXPECT_EQ(this->blob_top_data_->num(), 5);
  EXPECT_EQ(this->blob_top_data_->channels(), 3);
  EXPECT_EQ(this->blob_top_data_->height(), 360);
  EXPECT_EQ(this->blob_top_data_->width(), 480);
  EXPECT_EQ(this->blob_top_label_->num(), 5);
  EXPECT_EQ(this->blob_top_label_->channels(), 1);
  EXPECT_EQ(this->blob_top_label_->height(), 1);
  EXPECT_EQ(this->blob_top_label_->width(), 1);
  // Go through the data twice
  for (int iter = 0; iter < 2; ++iter) {
    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
    map<Dtype, int> values_to_indices;
    int num_in_order = 0;
    for (int i = 0; i < 5; ++i) {
      Dtype value = this->blob_top_label_->cpu_data()[i];
      // Check that the value has not been seen already (no duplicates).
      EXPECT_EQ(values_to_indices.find(value), values_to_indices.end());
      values_to_indices[value] = i;
      num_in_order += (value == Dtype(i));
    }
    EXPECT_EQ(5, values_to_indices.size());
    EXPECT_GT(5, num_in_order);

#ifdef GENERATE_IDL_TEST_DATA
    write_blob_to_file(file_name, *this->blob_top_data_);
#endif
    Blob<Dtype> tmp_blob;
    read_blob_from_file(file_name, tmp_blob);
    EXPECT_EQ(0, memcmp(this->blob_top_data_->cpu_data(), tmp_blob.cpu_data(),
            sizeof(Dtype)*this->blob_top_data_->count()));
  }
}
示例#3
0
static int download_layout(USBKeyboard *kb, const KBHwinfo *info,
                           const char *outfilename)
{
  uint8_t vector[info->matrix_bvlen];
  int ret=receive_buffer(kb,KURQ_GET_LAYOUT,0,0,vector,info->matrix_bvlen);

  if(ret < 0)
  {
    fprintf(stderr,"Error while reading keyboard layout.\n");
    return -1;
  }

  if(ret != info->matrix_bvlen)
  {
    fprintf(stderr,"Received unexpected number of bytes (%d instead of %d)\n",
            ret,info->matrix_bvlen);
    return -1;
  }

  return write_blob_to_file(outfilename,vector,sizeof(vector));
}
示例#4
0
TYPED_TEST(ImageDataLayerTest, TestResize) {
  typedef typename TypeParam::Dtype Dtype;
  std::string file_name = std::string(EXAMPLES_SOURCE_DIR) +
          std::string("test_blobs/ImageDataLayerTest_TestResize_")
          +std::string(typeid(Dtype).name())+std::string(".blob");

  LayerParameter param;
  ImageDataParameter* image_data_param = param.mutable_image_data_param();
  image_data_param->set_batch_size(5);
  image_data_param->set_source(this->filename_.c_str());
  image_data_param->set_new_height(256);
  image_data_param->set_new_width(256);
  image_data_param->set_shuffle(false);
  ImageDataLayer<Dtype> layer(param);
  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
  EXPECT_EQ(this->blob_top_data_->num(), 5);
  EXPECT_EQ(this->blob_top_data_->channels(), 3);
  EXPECT_EQ(this->blob_top_data_->height(), 256);
  EXPECT_EQ(this->blob_top_data_->width(), 256);
  EXPECT_EQ(this->blob_top_label_->num(), 5);
  EXPECT_EQ(this->blob_top_label_->channels(), 1);
  EXPECT_EQ(this->blob_top_label_->height(), 1);
  EXPECT_EQ(this->blob_top_label_->width(), 1);
  // Go through the data twice
  for (int iter = 0; iter < 2; ++iter) {
    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
    for (int i = 0; i < 5; ++i) {
      EXPECT_EQ(i, this->blob_top_label_->cpu_data()[i]);
    }
#ifdef GENERATE_IDL_TEST_DATA
    write_blob_to_file(file_name, *this->blob_top_data_);
#endif
    Blob<Dtype> tmp_blob;
    read_blob_from_file(file_name, tmp_blob);
    EXPECT_EQ(0, memcmp(this->blob_top_data_->cpu_data(), tmp_blob.cpu_data(),
            sizeof(Dtype)*this->blob_top_data_->count()));
  }
}