当前位置: 首页>>代码示例>>C++>>正文


C++ DataTransformer类代码示例

本文整理汇总了C++中DataTransformer的典型用法代码示例。如果您正苦于以下问题:C++ DataTransformer类的具体用法?C++ DataTransformer怎么用?C++ DataTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataTransformer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TYPED_TEST

TYPED_TEST(DataTransformTest, TestCropSize) {
  TransformationParameter transform_param;
  const bool unique_pixels = false;  // all pixels the same equal to label
  const int_tp label = 0;
  const int_tp channels = 3;
  const int_tp height = 4;
  const int_tp width = 5;
  const int_tp crop_size = 2;

  transform_param.set_crop_size(crop_size);
  Datum datum;
  FillDatum(label, channels, height, width, unique_pixels, &datum);
  DataTransformer<TypeParam>* transformer =
      new DataTransformer<TypeParam>(transform_param, TEST,
                                     Caffe::GetDefaultDevice());
  transformer->InitRand();
  Blob<TypeParam>* blob =
      new Blob<TypeParam>(1, channels, crop_size, crop_size);
  for (int_tp iter = 0; iter < this->num_iter_; ++iter) {
    transformer->Transform(datum, blob);
    EXPECT_EQ(blob->num(), 1);
    EXPECT_EQ(blob->channels(), datum.channels());
    EXPECT_EQ(blob->height(), crop_size);
    EXPECT_EQ(blob->width(), crop_size);
    for (int_tp j = 0; j < blob->count(); ++j) {
      EXPECT_EQ(blob->cpu_data()[j], label);
    }
  }
}
开发者ID:strin,项目名称:caffe-opencl,代码行数:29,代码来源:test_data_transformer.cpp

示例2: encodeForSaving

std::string encodeForSaving(const char* value, const char* user_token) 
{
    std::string res("");

    if ((user_token != NULL) && (strlen(user_token) > 0)) {
        if (value == NULL || strlen(value) == 0) {
            return res; 
        }
        
        DataTransformer* enc = DataTransformerFactory::getEncoder(DT_DES);
        TransformationInfo info;
        info.size = (long)strlen(value)*sizeof(char);
        info.password = user_token;
        char* v = strdup(value);
        char* desValue = enc->transform(v, info);
        
        DataTransformer* b64Enc = DataTransformerFactory::getEncoder(DT_B64);
        char* b64Value = b64Enc->transform(desValue, info); 
        
        free(v);
        
        if (desValue) {
            free(desValue);
        }
        
        res = b64Value;
        delete [] b64Value;
    } else {
        res = value;
    }

    return res;
}
开发者ID:fieldwind,项目名称:syncsdk,代码行数:33,代码来源:baseutils.cpp

示例3: testEncryption

USE_NAMESPACE

//
// IMPORTANT: this test case encodes/decodes a UNICODE string; make sure
// to update it to UTF8 strings when used with such content.
//
void testEncryption() {
    char* clearText = "This is clear text.\nLet's see if encryption/decryption works!";
    char* password = "dummypassword";

    DataTransformer* b64e = DataTransformerFactory::getEncoder("b64");
    DataTransformer* b64d = DataTransformerFactory::getDecoder("b64");
    DataTransformer* dese = DataTransformerFactory::getEncoder("des");
    DataTransformer* desd = DataTransformerFactory::getDecoder("des");

    TransformationInfo infoe, infod;

    infoe.size = strlen(clearText)*sizeof(char);
    infoe.password = password;

    LOG.info("Clear text");
    LOG.info("%s", clearText);

    char* desText = dese->transform(clearText, infoe);
    char* b64Text = b64e->transform(desText, infoe);

    LOG.info("Clear text");
    LOG.info("%s", b64Text);

    delete [] desText;

    infod.size = infoe.size;
    infod.password = infoe.password;
    desText = b64d->transform(b64Text, infod);
    clearText = desd->transform(desText, infod);

    char* clearString = new char[infod.size/sizeof(char)+1];
    strncpy(clearString, clearText, infod.size/sizeof(char));
    clearString[infod.size/sizeof(char)] = 0;

    LOG.info("Clear text");
    LOG.info("%s", clearString);

    delete [] clearString; delete [] clearText;
    delete [] b64Text; delete [] desText;
}
开发者ID:pohly,项目名称:funambol-cpp-client-api,代码行数:46,代码来源:testEncryption.cpp

示例4: TYPED_TEST

TYPED_TEST(DataTransformTest, TestMeanValue) {
  TransformationParameter transform_param;
  const bool unique_pixels = false;  // pixels are equal to label
  const int label = 0;
  const int channels = 3;
  const int height = 4;
  const int width = 5;
  const int mean_value = 2;

  transform_param.add_mean_value(mean_value);
  Datum datum;
  FillDatum(label, channels, height, width, unique_pixels, &datum);
  Blob<TypeParam>* blob = new Blob<TypeParam>(1, channels, height, width);
  DataTransformer<TypeParam>* transformer =
      new DataTransformer<TypeParam>(transform_param, TEST);
  transformer->InitRand();
  transformer->Transform(datum, blob);
  for (int j = 0; j < blob->count(); ++j) {
    EXPECT_EQ(blob->cpu_data()[j], label - mean_value);
  }
}
开发者ID:bobbens,项目名称:caffe,代码行数:21,代码来源:test_data_transformer.cpp

示例5: NumSequenceMatches

  int NumSequenceMatches(const TransformationParameter transform_param,
      const Datum& datum, Phase phase) {
    // Get crop sequence with Caffe seed 1701.
    DataTransformer<Dtype>* transformer =
        new DataTransformer<Dtype>(transform_param, phase);
    const int crop_size = transform_param.crop_size();
    int crop_h = transform_param.crop_h();
    int crop_w = transform_param.crop_w();
    if (crop_size > 0) {
      crop_h = crop_w = crop_size;
    }
    Caffe::set_random_seed(seed_);
    transformer->InitRand();
    Blob<Dtype>* blob =
        new Blob<Dtype>(1, datum.channels(), datum.height(), datum.width());
    if (crop_h > 0 || crop_w > 0) {
      blob->Reshape(1, datum.channels(), crop_h, crop_w);
    }

    vector<vector<Dtype> > crop_sequence;
    for (int iter = 0; iter < this->num_iter_; ++iter) {
      vector<Dtype> iter_crop_sequence;
      transformer->Transform(datum, blob);
      for (int j = 0; j < blob->count(); ++j) {
        iter_crop_sequence.push_back(blob->cpu_data()[j]);
      }
      crop_sequence.push_back(iter_crop_sequence);
    }
    // Check if the sequence differs from the previous
    int num_sequence_matches = 0;
    for (int iter = 0; iter < this->num_iter_; ++iter) {
      vector<Dtype> iter_crop_sequence = crop_sequence[iter];
      transformer->Transform(datum, blob);
      for (int j = 0; j < blob->count(); ++j) {
        num_sequence_matches +=
            (crop_sequence[iter][j] == blob->cpu_data()[j]);
      }
    }
    return num_sequence_matches;
  }
开发者ID:bobbens,项目名称:caffe,代码行数:40,代码来源:test_data_transformer.cpp

示例6: decodeAfterReading

std::string decodeAfterReading(const char *value, const char* user_token) 
{
    std::string res(value);
    if ((user_token != NULL) && (strlen(user_token) > 0)) {
        if (value == NULL || strlen(value) == 0) {
            return "";
        }
        
        // Password is stored as b64(des(password))
        DataTransformer* b64Dec = DataTransformerFactory::getDecoder(DT_B64);
        TransformationInfo info;
        
        char* v = strdup(value);
        info.size = (long)strlen(v)*sizeof(char);
        char* b64DecValue = b64Dec->transform(v, info);
        
        DataTransformer* dec = DataTransformerFactory::getDecoder(DT_DES);
        info.password = user_token;
        
        char* desValue = dec->transform(b64DecValue, info);
        if (desValue != NULL && info.size > 0) {
            desValue[info.size] = 0;
        }
        
        free(v);
        
        if (desValue != NULL) {
            res = desValue;
        }
        delete [] b64DecValue;

        if (info.newReturnedData == true) {
            delete [] desValue;
        }               
    }         
    return res;          
}
开发者ID:fieldwind,项目名称:syncsdk,代码行数:37,代码来源:baseutils.cpp


注:本文中的DataTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。