本文整理汇总了C++中DataTransformer::Transform方法的典型用法代码示例。如果您正苦于以下问题:C++ DataTransformer::Transform方法的具体用法?C++ DataTransformer::Transform怎么用?C++ DataTransformer::Transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTransformer
的用法示例。
在下文中一共展示了DataTransformer::Transform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FillDatum
TYPED_TEST(DataTransformTest, TestMeanValues) {
TransformationParameter transform_param;
const bool unique_pixels = false; // pixels are equal to label
const int_tp label = 0;
const int_tp channels = 3;
const int_tp height = 4;
const int_tp width = 5;
transform_param.add_mean_value(0);
transform_param.add_mean_value(1);
transform_param.add_mean_value(2);
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,
Caffe::GetDefaultDevice());
transformer->InitRand();
transformer->Transform(datum, blob);
for (int_tp c = 0; c < channels; ++c) {
for (int_tp j = 0; j < height * width; ++j) {
EXPECT_EQ(blob->cpu_data()[blob->offset(0, c) + j], label - c);
}
}
}
示例2: 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;
}
示例3: FillDatum
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);
}
}
示例4: string
TYPED_TEST(DataTransformTest, TestMeanFile) {
TransformationParameter transform_param;
const bool unique_pixels = true; // pixels are consecutive ints [0,size]
const int_tp label = 0;
const int_tp channels = 3;
const int_tp height = 4;
const int_tp width = 5;
const int_tp size = channels * height * width;
// Create a mean file
string* mean_file = new string();
MakeTempFilename(mean_file);
BlobProto blob_mean;
blob_mean.set_num(1);
blob_mean.set_channels(channels);
blob_mean.set_height(height);
blob_mean.set_width(width);
for (int_tp j = 0; j < size; ++j) {
blob_mean.add_data(j);
}
LOG(INFO) << "Using temporary mean_file " << *mean_file;
WriteProtoToBinaryFile(blob_mean, *mean_file);
transform_param.set_mean_file(*mean_file);
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,
Caffe::GetDefaultDevice());
transformer->InitRand();
transformer->Transform(datum, blob);
for (int_tp j = 0; j < blob->count(); ++j) {
EXPECT_EQ(blob->cpu_data()[j], 0);
}
}