Mat类型变量读取二维数据:
#include "net.h"
#include <fstream>
#include <iostream>
#include <chrono>
#include <stdio.h>
#include <vector>
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#endif
using namespace std;
struct Object
{
int label;
float prob;
};
static int detect_age(std::vector<Object>& objects)
{
ncnn::Net age;
// age.opt.use_vulkan_compute = true;
if (age.load_param("Simple_sim_opt.param"))
exit(-1);
if (age.load_model("Simple_sim_opt.bin"))
exit(-1);
float data[61][37] = { 0 };
ifstream infile;
infile.open("/home/1.txt");
for (int i = 0; i < 61; i++){
for (int j = 0; j < 37; j++){
infile >> data[i][j];
}
}
infile.close();
// 存储数据:
ncnn::Mat m(37,61);
std::copy(data[0],data[61],(float *)m);
ncnn::Extractor ex = age.create_extractor();
ex.input("input", m);
ncnn::Mat out;
ex.extract("output", out);
for (int i = 0; i < out.total(); ++i){
std::cout<< out[i] << std::endl;
}
objects.clear();
return 0;
}
int main()
{
// test();
std::vector<Object> objects;
detect_age(objects);
return 0;
}
直接用 ncnn::Mat m(37, 61, data[0]) 就可以了,不需要 std::copy
确保 m 在使用的时候, data 还是 alive 的