0
我一直在試圖實現facenet classifier,原本用Python編寫的,爲C++和它運作良好,大部分。我在OpenCV中被讀取的圖像,並轉換爲tensorflow張量,但是運行我的輸出張充滿NaN值的圖形之後。Tensorflow Facenet分類在C++
繼承人的代碼段:
string input_layer = "input:0";
string phase_train_layer = "phase_train:0";
string output_layer = "embeddings:0";
tensorflow::Tensor input_tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({input_Images.size(), height, width, channels}));
auto input_tensor_mapped = input_tensor.tensor<float, 4>();
for (int i = 0; i < input_Images.size(); i++) {
Mat image = input_Images[i];
const float * source_data = (float*) image.data;
for (int h = 0; h < image.rows; ++h) {
const float* source_row = source_data + (h * image.cols * image.channels());
for (int w = 0; w < image.cols; ++w) {
const float* source_pixel = source_row + (w * image.channels());
for (int c = 0; c < image.channels(); ++c) {
const float* source_value = source_pixel + c;
//std::cout << *source_value << std::endl;
input_tensor_mapped(i, h, w, c) = *source_value;
}
}
}
}
tensorflow::Tensor phase_tensor(tensorflow::DT_BOOL, tensorflow::TensorShape());
phase_tensor.scalar<bool>()() = false;
cout << phase_tensor.DebugString() << endl;
cout << input_tensor.DebugString() << endl;
std::vector<tensorflow::Tensor> outputs;
std::vector<std::pair<string, tensorflow::Tensor>> feed_dict = {
{input_layer, input_tensor},
{phase_train_layer, phase_tensor},
};
Status run_status = session->Run(feed_dict,
{output_layer}, {} , &outputs);
if (!run_status.ok()) {
LOG(ERROR) << "\tRunning model failed: " << run_status << "\n";
return -1;
}
cout << outputs[0].DebugString() << endl;
任何想法,爲什麼這可能是這樣?