Skip to content

Commit 15b6e2a

Browse files
authored
Merge pull request #14795 from velconia/local_rel_1_2
Fix numpy bug on Ubuntu16 and Ubuntu18 which will cause segmentfault
2 parents 81b66db + b48b71d commit 15b6e2a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

python/paddle/dataset/image.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,28 @@
3232

3333
from __future__ import print_function
3434

35+
import six
3536
import numpy as np
36-
try:
37-
import cv2
38-
except ImportError:
39-
cv2 = None
37+
# FIXME(minqiyang): this is an ugly fix for the numpy bug reported here
38+
# https://github.com/numpy/numpy/issues/12497
39+
if six.PY3:
40+
import subprocess
41+
import sys
42+
import_cv2_proc = subprocess.Popen(
43+
[sys.executable, "-c", "import cv2"],
44+
stdout=subprocess.PIPE,
45+
stderr=subprocess.PIPE)
46+
out, err = import_cv2_proc.communicate()
47+
retcode = import_cv2_proc.poll()
48+
if retcode != 0:
49+
cv2 = None
50+
else:
51+
import cv2
52+
else:
53+
try:
54+
import cv2
55+
except ImportError:
56+
cv2 = None
4057
import os
4158
import tarfile
4259
import six.moves.cPickle as pickle

0 commit comments

Comments
 (0)