栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

不同框架下验证精度

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

不同框架下验证精度

0.两个txt对比精度
import numpy as np
name = "fc1x_a"
path_pytorch_txt = "/data_1/everyday/1123/img_acc/libtorch_img.txt"
path_caffe_txt = "/data_1/everyday/1123/img_acc/pytorch_img.txt"

pytorch_tensor = np.loadtxt(path_pytorch_txt)
caffe_tensor = np.loadtxt(path_caffe_txt)

diff = pytorch_tensor - caffe_tensor

max_ = np.max(np.abs(diff))
print("max=", max_)

print("none zero=",np.count_nonzero(diff))

print(np.argmax(np.abs(diff)))

1.c++与python的opencv 图像生成txt验证精度

c++

cv::Mat img = cv::imread(file);
        int rowNumber = img.rows;  //行数
        int colNumber = img.cols*img.channels();  //列数 x 通道数=每一行元素的个数
        std::ofstream out_file("/data_1/everyday/1123/img_acc/libtorch_img.txt");
        //双重循环,遍历所有的像素值
        for (int i = 0; i < rowNumber; i++)  //行循环
        {
            uchar *data = img.ptr(i);  //获取第i行的首地址
            for (int j = 0; j < colNumber; j++)   //列循环
            {
                // ---------【开始处理每个像素】-------------
                int pix = int(data[j]);
                out_file << pix << std::endl;
            }
        }
        out_file.close();

 这里有个问题需要注意, uchar *data = img.ptr(i);  //获取第i行的首地址

这句话当你图像

m_stand.convertTo(m_stand, CV_32FC3);

转为float的时候需要改类型

Python

img = cv2.imread(path_img)
        tmp_1 = img.reshape(-1)
        np.savetxt("/data_1/everyday/1123/img_acc/pytorch_img.txt",tmp_1)

2.pytorch tensor与libtorch tensor生成txt验证精度

libtorch

bool save_tensor_txt(torch::Tensor tensor_in_,string path_txt)
{
#include "fstream"
    ofstream outfile(path_txt);
    torch::Tensor tensor_in = tensor_in_.clone();
    tensor_in = tensor_in.view({-1,1});
    tensor_in = tensor_in.to(torch::kCPU);

    auto result_data = tensor_in.accessor();

    for(int i=0;i

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/588326.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号