tensorflow: Seg fault when using tf session with opencv 3

Hi,

We noticed that when we try to use tensorflow with opencv 3, it consistently seg faults and crashes. The commands are:

import cv2
import numpy as np
import tensorflow as tf

with tf.Session() as sess:
    img = cv2.imread('messi5.jpg', 0)
    rows, cols = img.shape
    M = np.float32([[1, 0, 100], [0, 1, 50]])
    dst = cv2.warpAffine(img, M, (cols, rows))
    cv2.imshow('img', dst)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

Assuming you have a messi5.jpg in the folder (https://raw.githubusercontent.com/abidrahmank/OpenCV2-Python-Tutorials/master/data/messi5.jpg)

We see this issue when we use tensorflow 0.12 GPU enabled, opencv 3.2.0 and python 2.7.6, CUDA 8.0 and CuDNN 5.1.5 . We did not observe this issue with opencv version 2.4.13 or 2.4.9.

We will also filed a bug report on opencv (https://github.com/opencv/opencv/issues/8155)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (16 by maintainers)

Most upvoted comments

That can happen with official OpenCV version too. I’ve hit similar crash, and looking at gdb backtrace it was in some OpenCV function checking if OpenCL was enabled. My guess is that TensorFlow GPU binary unintentionally includes some OpenCL symbols which confuses opencv

The solution was to set the following before running your script

export OPENCV_OPENCL_RUNTIME=