ncnn: 读取二维数据

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 的 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值