Tensorflow 1.14: Eigen using failed(OpenCV冲突问题)

之前LZ在编译tf1.14接口的时候,其实就已经强调了Eigen 版本选择的重要性,但是我们经常使用不止一种三方库,在使用不同算法库的时候其实就会存在这样那样动态库冲突的情况,而且这种情况最为头疼。。。

下面是LZ的一段测试代码

#include <stdio.h>
#include <iostream>
...
tf的一些头文件
...

#include "opencv2/opencv.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudawarping.hpp"
#include "opencv2/gpu/gpu.hpp"

int main() {
    int num_devices = cv::cuda::getCudaEnabledDeviceCount();

    if (num_devices <= 0) {
        std::cerr << "There is no device." << std::endl;
        return -1;
    }
    int enable_device_id = -1;
    for (int i = 0; i < num_devices; i++) {
        cv::cuda::DeviceInfo dev_info(i);
        if (dev_info.isCompatible()) {
            enable_device_id = i;
        }
    }
    if (enable_device_id < 0) {
        std::cerr << "GPU module isn't built for GPU" << std::endl;
        return -1;
    }
    cv::cuda::setDevice(enable_device_id);

    std::cout << "GPU is ready, device ID is " << num_devices << "\n";

    // read one image
    cv::Mat src_image = cv::imread("../111.jpg");
    cv::Mat dst_image;
    cv::cuda::GpuMat g_src_img(src_image);
    cv::cuda::GpuMat g_dst_image;
    cv::cuda::resize(g_src_img, g_dst_image, cv::Size(WIDTH, HEIGHT));
    g_dst_image.download(dst_image);
    cv::imshow("test", dst_image);
    cv::waitKey(0);
    cv::imwrite("test.jpg", dst_image);


    return 0;
}

后来编译就出问题了,主要还是Eigen的问题

tensorflow-r1.14/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h: In static member function ‘static void Eigen::internal::TensorBlockIO<Scalar, StorageIndex, NumDims, Layout, BlockRead>::Copy(const Block&, StorageIndex, const Dimensions&, const Dimensions&, const Scalar*, Scalar*)’:
tensorflow-r1.14/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:393:63: error: the value of ‘j’ is not usable in a constant expression
         if (++block_iter_state[j].count < block_iter_state[j].size) {
                                                               ^
tensorflow-r1.14/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:392:16: note: ‘int j’ is not const
       for (int j = 0; j < num_squeezed_dims; ++j) {
                ^
tensorflow-r1.14/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h:393:35: error: parse error in template argument list
         if (++block_iter_state[j].count < block_iter_state[j].size) {
...

提取出主要问题

 error: the value of ‘j’ is not usable in a constant expression

发现在github上也有类似问题https://github.com/tensorflow/tensorflow/issues/33280

在这里插入图片描述但是并没有解决方案啊。。。

最后在LZ的仔细排查下最后发现了自己犯了一个很愚蠢的错误,在LZ的笔记本上有两个版本的OpenCV,

//这三行使用的是OpenCV4.2.0版本的
#include "opencv2/opencv.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudawarping.hpp"
//这个头文件使用的是OpenCV2.4.9版本的,这种肯定会出问题的,
#include "opencv2/gpu/gpu.hpp"

但是报的居然是tf中Eigen的问题,排查好久,差点以为要重新编译库了/(ㄒoㄒ)/~~

不知道github上那小哥解决问题了没有。。。

发布了300 篇原创文章 · 获赞 203 · 访问量 59万+

猜你喜欢

转载自blog.csdn.net/Felaim/article/details/103988856