Git Product home page Git Product logo

extract_features.cpp's Introduction

extract_features.cpp

extract features for U-Net using C++, modified codes based on extract_features.cpp

  1. read a volume of 3d raw data

  2. put the data array into memory_data_layer add a new function AddRawData in memory_data_layer.cpp

template void MemoryDataLayer::AddRawData(float* mat_vector, const vector& labels, int num) { //size_t num = mat_vector.size(); //size_t num = batch_size_; std::cout << "nSlice:" << num << endl; std::cout << "nchannels:" << channels_ << endl; std::cout << "nheight:" << height_ << endl; std::cout << "nwidth:" << width_ << endl;

CHECK(!has_new_data_) <<
	"Can't add mat until current data has been consumed.";
CHECK_GT(num, 0) << "There is no mat to add";
CHECK_EQ(num % batch_size_, 0) <<
	"The added data must be a multiple of the batch size.";
added_data_.Reshape(num, channels_, height_, width_);
added_label_.Reshape(num, 1, 1, 1);
// Apply data transformations (mirror, scale, crop...)
//this->data_transformer_->Transform(mat_vector, &added_data_);// this layer doesn't need transform
//Dtype* transformed_data = transformed_blob->mutable_cpu_data(); 


Dtype* feature_blob_data = added_data_.mutable_cpu_data();

for (int i = 0; i < num*channels_*height_*width_; i++){
 feature_blob_data[i] = mat_vector[i];
}

//// save images for checking
//FILE * fpFeatures = NULL;
////fopen_s(&fpFeatures, "D:\\iyuzu\\UNet\\unet-master\\image.raw", "wb");
//fopen_s(&fpFeatures, "feature_blob.raw", "wb+");//93-A2-PDW-mag2_new
//if (fpFeatures)
//{
//	fwrite(feature_blob_data, sizeof(Dtype), 128 * 128 * 60, fpFeatures);
//	fclose(fpFeatures);
//}// save images for checking

Dtype* top_label = added_label_.mutable_cpu_data();
for (int item_id = 0; item_id < num; ++item_id) {
	//top_label[item_id] = labels[item_id];
	top_label[item_id] = labels[0];
}
// num_images == batch_size_
Dtype* top_data = added_data_.mutable_cpu_data();
Reset(top_data, top_label, num);
has_new_data_ = true;

} add declaration in memory_data_layer.hpp

virtual void AddRawData(float* mat_vector, const vector& labels, int num);

re-build caffe

3.re-construct the slices of output feature map into 3d raw data

4.compile the extract_features.cpp and invoke the exe

                    "This program takes in a trained network and an input data layer, and then"
		" extract features of the input data produced by the net.\n"
		"Usage: extract_features  input_image_names pretrained_net_param"
		"  feature_extraction_proto_file  extract_feature_blob_name1[,name2,...]"
		"  save_feature_dataset_name1[,name2,...]  num_mini_batches  input image path"
		"  [CPU/GPU] [DEVICE_ID=0]\n"
		"Note: you can extract multiple features in one pass by specifying"
		" multiple feature blob names and dataset names separated by ','."
		" The names cannot contain white space characters and the number of blobs"
		" and datasets must be equal.";

extract_features.cpp's People

Contributors

yanwenci avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.