I am new to caffe and c++. I know that caffe has defined its EuclideanLossLayer. So can I use this layer to calculate the distance between blob_1 and blob_2?
File 1: main.cpp
#include "caffe/caffe.hpp"
#include "caffe/proto/caffe.pb.h"
// #include "caffe/utils/math_functions.hpp"
using std::string;
using std::cout;
using std::endl;
int main(int argc, char** argv) {
// set cpu or gpu
#ifdef CPU_ONLY
caffe::Caffe::set_mode(caffe::Caffe::CPU);
#else
caffe::Caffe::set_mode(caffe::Caffe::GPU);
#endif
// define two blobs
caffe::Blob<float>* blob_1 = new caffe::Blob<float>(1, 3, 2, 2);
caffe::Blob<float>* blob_2 = new caffe::Blob<float>(1, 3, 2, 2);
for (int b=0; b<blob_1->num(); ++b) {
for (int c=0; c<blob_1->channels(); ++c) {
for (int h=0; h<blob_1->height(); ++h) {
for (int w=0; w<blob_1->width(); ++w) {
blob_1->mutable_cpu_data()[((b*blob_1->channels()+c)*blob_1->height()+h)*blob_1->width()+w] = 1;
blob_2->mutable_cpu_data()[((b*blob_1->channels()+c)*blob_1->height()+h)*blob_1->width()+w] = 2;
}
}
}
}
// here is the problem: how do I calculate the distance between blob_1 and blob_2?
// caffe::EuclideanLossLayer<float> mseloss;
// float distance = mseloss(blob_1, blob_2);
cout << "done!" << endl;
}
You may need File 2: CMakeLists.txt
cmake_minimum_required(VERSION 2.8.8)
include("C:/Users/me/.caffe/dependencies/libraries_v140_x64_py27_1.1.0/libraries/caffe-builder-config.cmake")
find_package(Caffe)
project(mseErrorViaCaffe_proj)
link_directories("F:/libcaffe/caffe/build/lib/Release")
set(Caffe_INCLUDE_DIRS "F:/libcaffe/caffe/build/include" "F:/libcaffe/caffe/build")
include_directories(${Caffe_INCLUDE_DIRS})
add_executable(mseErrorViaCaffe main.cpp)
target_link_libraries(mseErrorViaCaffe ${Caffe_LIBRARIES})
set(Caffe_DLL_DIR "F:/libcaffe/caffe/build/install/bin/")
file(COPY ${Caffe_DLL_DIR} DESTINATION Release)