Skip to content

Instantly share code, notes, and snippets.

@milani
Created January 26, 2018 19:34
Show Gist options
  • Save milani/f90e448388440a3897d9aee1c3023c30 to your computer and use it in GitHub Desktop.
Save milani/f90e448388440a3897d9aee1c3023c30 to your computer and use it in GitHub Desktop.
============================= test session starts ==============================
platform linux -- Python 3.5.3, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
rootdir: /fast/keras-rcnn, inifile: setup.cfg
collected 25 items
tests/backend/test_common.py .FFFFFF..FFF [ 48%]
tests/backend/test_tensorflow_backend.py .....F.....F. [100%]
=================================== FAILURES ===================================
__________________________________ test_clip ___________________________________
def test_clip():
boxes = numpy.array(
[[0, 0, 0, 0], [1, 2, 3, 4], [-4, 2, 1000, 6000], [3, -10, 223, 224]])
shape = [224, 224]
boxes = keras.backend.variable(boxes)
results = keras_rcnn.backend.clip(boxes, shape)
results = keras.backend.eval(results)
expected = numpy.array(
[[0, 0, 0, 0], [1, 2, 3, 4], [0, 2, 223, 223], [3, 0, 223, 223]])
> numpy.testing.assert_array_almost_equal(results, expected)
E AssertionError:
E Arrays are not almost equal to 6 decimals
E
E (mismatch 100.0%)
E x: array([[-168., -80., 198., 110.],
E [-352., -176., 382., 206.],
E [-720., -368., 750., 398.],
E [-112., -112., 142., 142.]], dtype=float32)
E y: array([[ 0, 0, 0, 0],
E [ 1, 2, 3, 4],
E [ 0, 2, 223, 223],
E [ 3, 0, 223, 223]])
tests/backend/test_common.py:39: AssertionError
_____________________________ test_bbox_transform ______________________________
def test_bbox_transform():
gt_rois = numpy.array([[-84., -40., 99., 55.], [-176., -88., 191., 103.],
[-360., -184., 375., 199.], [-56., -56., 71., 71.],
[-120., -120., 135., 135.],
[-248., -248., 263., 263.], [-36., -80., 51., 95.],
[-80., -168., 95., 183.],
[-168., -344., 183., 359.]])
ex_rois = 2 * gt_rois
gt_rois = keras.backend.variable(gt_rois)
ex_rois = keras.backend.variable(ex_rois)
results = keras_rcnn.backend.bbox_transform(ex_rois, gt_rois)
results = keras.backend.eval(results)
expected = numpy.array(
[[-0.02043597, -0.03926702, -0.69042609, -0.68792524],
[-0.01020408, -0.01958225, -0.69178756, -0.69053962],
[-0.00509857, -0.00977836, -0.6924676, -0.69184425],
[-0.02941176, -0.02941176, -0.68923328, -0.68923328],
[-0.0146771, -0.0146771, -0.69119215, -0.69119215],
[-0.00733138, -0.00733138, -0.69217014, -0.69217014],
[-0.04285714, -0.02136752, -0.68744916, -0.69030223],
[-0.02136752, -0.01066856, -0.69030223, -0.69172572],
[-0.01066856, -0.00533049, -0.69172572, -0.6924367]])
> numpy.testing.assert_array_almost_equal(results, expected)
E AssertionError:
E Arrays are not almost equal to 6 decimals
E
E (mismatch 100.0%)
E x: array([[ 2.000000e+00, 2.924387e-39, 8.490193e-38, 4.324830e+17],
E [ 3.583381e-39, 1.626925e+17, 5.061360e-39, 4.324687e+17],
E [-7.976657e+36, 4.807772e-34, 5.053109e-39, 1.621648e+17],...
E y: array([[-0.020436, -0.039267, -0.690426, -0.687925],
E [-0.010204, -0.019582, -0.691788, -0.69054 ],
E [-0.005099, -0.009778, -0.692468, -0.691844],...
tests/backend/test_common.py:77: AssertionError
________________________________ test_mkanchors ________________________________
def test_mkanchors():
ws = numpy.array([1, 2, 3])
hs = numpy.array([4, 5, 6])
x_ctr = keras.backend.variable([1], 'float32')
y_ctr = keras.backend.variable([2], 'float32')
ws = keras.backend.variable(ws, 'float32')
hs = keras.backend.variable(hs, 'float32')
results = keras_rcnn.backend.common._mkanchors(ws, hs, x_ctr, y_ctr)
results = keras.backend.eval(results)
expected = numpy.array(
[[1, 0.5, 1, 3.5], [0.5, 0, 1.5, 4], [0, -0.5, 2, 4.5]])
> numpy.testing.assert_array_equal(results, expected)
E AssertionError:
E Arrays are not equal
E
E (mismatch 100.0%)
E x: array([[ 0.000000e+00, 2.647445e-39, 1.169760e-36, 3.783156e+17],
E [ 2.128777e-39, 7.393741e-06, 1.263800e-36, 3.783156e+17],
E [-1.221202e+26, 8.867906e-15, 2.540330e-35, 1.009275e+08]],
E dtype=float32)
E y: array([[ 1. , 0.5, 1. , 3.5],
E [ 0.5, 0. , 1.5, 4. ],
E [ 0. , -0.5, 2. , 4.5]])
tests/backend/test_common.py:91: AssertionError
_________________________________ test_overlap _________________________________
x_id = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
y_id = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
hasval = 'nan'
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
> assert_array_equal(x_id, y_id)
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:700:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
y = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
err_msg = '', verbose = True
def assert_array_equal(x, y, err_msg='', verbose=True):
"""
Raises an AssertionError if two array_like objects are not equal.
Given two array_like objects, check that the shape is equal and all
elements of these objects are equal. An exception is raised at
shape mismatch or conflicting values. In contrast to the standard usage
in numpy, NaNs are compared like numbers, no assertion is raised if
both objects have NaNs in the same positions.
The usual caution for verifying equality with floating point numbers is
advised.
Parameters
----------
x : array_like
The actual object to check.
y : array_like
The desired, expected object.
err_msg : str, optional
The error message to be printed in case of failure.
verbose : bool, optional
If True, the conflicting values are appended to the error message.
Raises
------
AssertionError
If actual and desired objects are not equal.
See Also
--------
assert_allclose: Compare two array_like objects for equality with desired
relative and/or absolute precision.
assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
Examples
--------
The first assert does not raise an exception:
>>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
... [np.exp(0),2.33333, np.nan])
Assert fails with numerical inprecision with floats:
>>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
... [1, np.sqrt(np.pi)**2, np.nan])
...
<type 'exceptions.ValueError'>:
AssertionError:
Arrays are not equal
<BLANKLINE>
(mismatch 50.0%)
x: array([ 1. , 3.14159265, NaN])
y: array([ 1. , 3.14159265, NaN])
Use `assert_allclose` or one of the nulp (number of floating point values)
functions for these cases instead:
>>> np.testing.assert_allclose([1.0,np.pi,np.nan],
... [1, np.sqrt(np.pi)**2, np.nan],
... rtol=1e-10, atol=0)
"""
__tracebackhide__ = True # Hide traceback for py.test
assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
> verbose=verbose, header='Arrays are not equal')
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:855:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
comparison = <built-in function eq>
x = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
y = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
err_msg = '', verbose = True, header = 'Arrays are not equal', precision = 6
equal_nan = True, equal_inf = True
def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
header='', precision=6, equal_nan=True,
equal_inf=True):
__tracebackhide__ = True # Hide traceback for py.test
from numpy.core import array, isnan, isinf, any, inf
x = array(x, copy=False, subok=True)
y = array(y, copy=False, subok=True)
def isnumber(x):
return x.dtype.char in '?bhilqpBHILQPefdgFDG'
def istime(x):
return x.dtype.char in "Mm"
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
assert_array_equal(x_id, y_id)
except AssertionError:
msg = build_err_msg([x, y],
err_msg + '\nx and y %s location mismatch:'
% (hasval), verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
raise AssertionError(msg)
try:
cond = (x.shape == () or y.shape == ()) or x.shape == y.shape
if not cond:
msg = build_err_msg([x, y],
err_msg
+ '\n(shapes %s, %s mismatch)' % (x.shape,
y.shape),
verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
raise AssertionError(msg)
if isnumber(x) and isnumber(y):
has_nan = has_inf = False
if equal_nan:
x_isnan, y_isnan = isnan(x), isnan(y)
# Validate that NaNs are in the same place
has_nan = any(x_isnan) or any(y_isnan)
if has_nan:
chk_same_position(x_isnan, y_isnan, hasval='nan')
if equal_inf:
x_isinf, y_isinf = isinf(x), isinf(y)
# Validate that infinite values are in the same place
has_inf = any(x_isinf) or any(y_isinf)
if has_inf:
# Check +inf and -inf separately, since they are different
chk_same_position(x == +inf, y == +inf, hasval='+inf')
chk_same_position(x == -inf, y == -inf, hasval='-inf')
if has_nan and has_inf:
x = x[~(x_isnan | x_isinf)]
y = y[~(y_isnan | y_isinf)]
elif has_nan:
x = x[~x_isnan]
y = y[~y_isnan]
elif has_inf:
x = x[~x_isinf]
y = y[~y_isinf]
# Only do the comparison if actual values are left
if x.size == 0:
return
elif istime(x) and istime(y):
# If one is datetime64 and the other timedelta64 there is no point
if equal_nan and x.dtype.type == y.dtype.type:
x_isnat, y_isnat = isnat(x), isnat(y)
if any(x_isnat) or any(y_isnat):
chk_same_position(x_isnat, y_isnat, hasval="NaT")
if any(x_isnat) or any(y_isnat):
x = x[~x_isnat]
y = y[~y_isnat]
val = comparison(x, y)
if isinstance(val, bool):
cond = val
reduced = [0]
else:
reduced = val.ravel()
cond = reduced.all()
reduced = reduced.tolist()
if not cond:
match = 100-100.0*reduced.count(1)/len(reduced)
msg = build_err_msg([x, y],
err_msg
+ '\n(mismatch %s%%)' % (match,),
verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
> raise AssertionError(msg)
E AssertionError:
E Arrays are not equal
E
E (mismatch 2.7777777777777715%)
E x: array([[False, False, False, False],
E [False, False, False, False],
E [False, False, False, False],...
E y: array([[False, False, False, False],
E [False, False, False, False],
E [False, False, False, False],...
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:779: AssertionError
During handling of the above exception, another exception occurred:
def test_overlap():
x = numpy.asarray([
[0, 10, 0, 10],
[0, 20, 0, 20],
[0, 30, 0, 30],
[0, 40, 0, 40],
[0, 50, 0, 50],
[0, 60, 0, 60],
[0, 70, 0, 70],
[0, 80, 0, 80],
[0, 90, 0, 90]
])
x = keras.backend.variable(x)
y = numpy.asarray([
[0, 20, 0, 20],
[0, 40, 0, 40],
[0, 60, 0, 60],
[0, 80, 0, 80]
])
y = keras.backend.variable(y)
overlapping = keras_rcnn.backend.common.overlap(x, y)
overlapping = keras.backend.eval(overlapping)
expected = numpy.array([
[0.0, 0.0, 0.0, 0.0],
[1.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
[0.0, 0.0, 0.0, 0.0]
])
> numpy.testing.assert_array_equal(overlapping, expected)
tests/backend/test_common.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x_id = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
y_id = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False],
...False],
[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
hasval = 'nan'
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
assert_array_equal(x_id, y_id)
except AssertionError:
msg = build_err_msg([x, y],
err_msg + '\nx and y %s location mismatch:'
% (hasval), verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
> raise AssertionError(msg)
E AssertionError:
E Arrays are not equal
E
E x and y nan location mismatch:
E x: array([[ 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00],
E [ 1.390281e-33, 7.970714e+07, 1.354217e-33, 3.801088e+07],
E [-5.317945e+37, 2.910037e-39, 2.435727e-29, 6.418014e+16],...
E y: array([[0., 0., 0., 0.],
E [1., 0., 0., 0.],
E [0., 0., 0., 0.],...
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:706: AssertionError
_______________________________ test_ratio_enum ________________________________
def test_ratio_enum():
anchor = numpy.expand_dims(numpy.array([0, 0, 0, 0]), 0)
ratios = numpy.array([1, 2, 3])
anchor = keras.backend.variable(anchor)
ratios = keras.backend.variable(ratios)
results = keras_rcnn.backend.common._ratio_enum(anchor, ratios)
results = keras.backend.eval(results)
expected = numpy.array(
[[0., 0., 0., 0.], [0., -0.5, 0., 0.5], [0., -1., 0., 1.]])
> numpy.testing.assert_array_equal(results, expected)
E AssertionError:
E Arrays are not equal
E
E (mismatch 100.0%)
E x: array([[ 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.324654e+17],
E [ 2.435685e-29, 1.643814e+17, 1.390328e-33, 5.371331e+08],
E [-8.059736e+36, 2.917212e-39, 1.390330e-33, 2.424275e+09]],
E dtype=float32)
E y: array([[ 0. , 0. , 0. , 0. ],
E [ 0. , -0.5, 0. , 0.5],
E [ 0. , -1. , 0. , 1. ]])
tests/backend/test_common.py:144: AssertionError
_______________________________ test_scale_enum ________________________________
x_id = array([[False, False, False, False],
[False, False, False, False],
[ True, False, False, False]])
y_id = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
hasval = 'nan'
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
> assert_array_equal(x_id, y_id)
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:700:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x = array([[False, False, False, False],
[False, False, False, False],
[ True, False, False, False]])
y = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
err_msg = '', verbose = True
def assert_array_equal(x, y, err_msg='', verbose=True):
"""
Raises an AssertionError if two array_like objects are not equal.
Given two array_like objects, check that the shape is equal and all
elements of these objects are equal. An exception is raised at
shape mismatch or conflicting values. In contrast to the standard usage
in numpy, NaNs are compared like numbers, no assertion is raised if
both objects have NaNs in the same positions.
The usual caution for verifying equality with floating point numbers is
advised.
Parameters
----------
x : array_like
The actual object to check.
y : array_like
The desired, expected object.
err_msg : str, optional
The error message to be printed in case of failure.
verbose : bool, optional
If True, the conflicting values are appended to the error message.
Raises
------
AssertionError
If actual and desired objects are not equal.
See Also
--------
assert_allclose: Compare two array_like objects for equality with desired
relative and/or absolute precision.
assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
Examples
--------
The first assert does not raise an exception:
>>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
... [np.exp(0),2.33333, np.nan])
Assert fails with numerical inprecision with floats:
>>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
... [1, np.sqrt(np.pi)**2, np.nan])
...
<type 'exceptions.ValueError'>:
AssertionError:
Arrays are not equal
<BLANKLINE>
(mismatch 50.0%)
x: array([ 1. , 3.14159265, NaN])
y: array([ 1. , 3.14159265, NaN])
Use `assert_allclose` or one of the nulp (number of floating point values)
functions for these cases instead:
>>> np.testing.assert_allclose([1.0,np.pi,np.nan],
... [1, np.sqrt(np.pi)**2, np.nan],
... rtol=1e-10, atol=0)
"""
__tracebackhide__ = True # Hide traceback for py.test
assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
> verbose=verbose, header='Arrays are not equal')
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:855:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
comparison = <built-in function eq>
x = array([[False, False, False, False],
[False, False, False, False],
[ True, False, False, False]])
y = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
err_msg = '', verbose = True, header = 'Arrays are not equal', precision = 6
equal_nan = True, equal_inf = True
def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
header='', precision=6, equal_nan=True,
equal_inf=True):
__tracebackhide__ = True # Hide traceback for py.test
from numpy.core import array, isnan, isinf, any, inf
x = array(x, copy=False, subok=True)
y = array(y, copy=False, subok=True)
def isnumber(x):
return x.dtype.char in '?bhilqpBHILQPefdgFDG'
def istime(x):
return x.dtype.char in "Mm"
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
assert_array_equal(x_id, y_id)
except AssertionError:
msg = build_err_msg([x, y],
err_msg + '\nx and y %s location mismatch:'
% (hasval), verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
raise AssertionError(msg)
try:
cond = (x.shape == () or y.shape == ()) or x.shape == y.shape
if not cond:
msg = build_err_msg([x, y],
err_msg
+ '\n(shapes %s, %s mismatch)' % (x.shape,
y.shape),
verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
raise AssertionError(msg)
if isnumber(x) and isnumber(y):
has_nan = has_inf = False
if equal_nan:
x_isnan, y_isnan = isnan(x), isnan(y)
# Validate that NaNs are in the same place
has_nan = any(x_isnan) or any(y_isnan)
if has_nan:
chk_same_position(x_isnan, y_isnan, hasval='nan')
if equal_inf:
x_isinf, y_isinf = isinf(x), isinf(y)
# Validate that infinite values are in the same place
has_inf = any(x_isinf) or any(y_isinf)
if has_inf:
# Check +inf and -inf separately, since they are different
chk_same_position(x == +inf, y == +inf, hasval='+inf')
chk_same_position(x == -inf, y == -inf, hasval='-inf')
if has_nan and has_inf:
x = x[~(x_isnan | x_isinf)]
y = y[~(y_isnan | y_isinf)]
elif has_nan:
x = x[~x_isnan]
y = y[~y_isnan]
elif has_inf:
x = x[~x_isinf]
y = y[~y_isinf]
# Only do the comparison if actual values are left
if x.size == 0:
return
elif istime(x) and istime(y):
# If one is datetime64 and the other timedelta64 there is no point
if equal_nan and x.dtype.type == y.dtype.type:
x_isnat, y_isnat = isnat(x), isnat(y)
if any(x_isnat) or any(y_isnat):
chk_same_position(x_isnat, y_isnat, hasval="NaT")
if any(x_isnat) or any(y_isnat):
x = x[~x_isnat]
y = y[~y_isnat]
val = comparison(x, y)
if isinstance(val, bool):
cond = val
reduced = [0]
else:
reduced = val.ravel()
cond = reduced.all()
reduced = reduced.tolist()
if not cond:
match = 100-100.0*reduced.count(1)/len(reduced)
msg = build_err_msg([x, y],
err_msg
+ '\n(mismatch %s%%)' % (match,),
verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
> raise AssertionError(msg)
E AssertionError:
E Arrays are not equal
E
E (mismatch 8.333333333333329%)
E x: array([[False, False, False, False],
E [False, False, False, False],
E [ True, False, False, False]])
E y: array([[False, False, False, False],
E [False, False, False, False],
E [False, False, False, False]])
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:779: AssertionError
During handling of the above exception, another exception occurred:
def test_scale_enum():
anchor = numpy.expand_dims(numpy.array([0, 0, 0, 0]), 0)
scales = numpy.array([1, 2, 3])
anchor = keras.backend.variable(anchor)
scales = keras.backend.variable(scales)
results = keras_rcnn.backend.common._scale_enum(anchor, scales)
results = keras.backend.eval(results)
expected = numpy.array(
[[0, 0, 0, 0], [-0.5, -0.5, 0.5, 0.5], [-1., -1., 1., 1.]])
> numpy.testing.assert_array_equal(results, expected)
tests/backend/test_common.py:163:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x_id = array([[False, False, False, False],
[False, False, False, False],
[ True, False, False, False]])
y_id = array([[False, False, False, False],
[False, False, False, False],
[False, False, False, False]])
hasval = 'nan'
def chk_same_position(x_id, y_id, hasval='nan'):
"""Handling nan/inf: check that x and y have the nan/inf at the same
locations."""
try:
assert_array_equal(x_id, y_id)
except AssertionError:
msg = build_err_msg([x, y],
err_msg + '\nx and y %s location mismatch:'
% (hasval), verbose=verbose, header=header,
names=('x', 'y'), precision=precision)
> raise AssertionError(msg)
E AssertionError:
E Arrays are not equal
E
E x and y nan location mismatch:
E x: array([[ 1.000000e+00, 2.917212e-39, 2.435687e-29, 6.447041e+16],
E [ 1.516390e-36, -8.854437e+20, 1.390283e-33, 7.970714e+07],
E [ nan, 2.917257e-39, 1.486580e-33, 7.970714e+07]],
E dtype=float32)
E y: array([[ 0. , 0. , 0. , 0. ],
E [-0.5, -0.5, 0.5, 0.5],
E [-1. , -1. , 1. , 1. ]])
/home/morteza/.local/lib/python3.5/site-packages/numpy/testing/nose_tools/utils.py:706: AssertionError
___________________________ test_bbox_transform_inv ____________________________
def test_bbox_transform_inv():
anchors = 9
features = (14, 14)
shifted = keras_rcnn.backend.shift(features, 16)
deltas = numpy.zeros((features[0] * features[1] * anchors, 4))
deltas = keras.backend.variable(deltas)
pred_boxes = keras_rcnn.backend.bbox_transform_inv(shifted, deltas)
assert keras.backend.eval(pred_boxes).shape == (1764, 4)
shifted = numpy.zeros((5, 4))
deltas = numpy.reshape(numpy.arange(12 * 5), (5, -1))
deltas = keras.backend.variable(deltas)
pred_boxes = keras_rcnn.backend.bbox_transform_inv(shifted, deltas)
expected = numpy.array(
[[-3.19452805e+00, -8.54276846e+00, 4.19452805e+00,
1.15427685e+01, -1.97214397e+02, -5.42816579e+02,
2.06214397e+02, 5.53816579e+02, -1.10047329e+04,
-2.99275709e+04, 1.10217329e+04, 2.99465709e+04],
[-6.01289642e+05, -1.63449519e+06, 6.01314642e+05,
1.63452219e+06, -3.28299681e+07, -8.92411330e+07,
3.28300011e+07, 8.92411680e+07, -1.79245640e+09,
-4.87240170e+09, 1.79245644e+09, 4.87240174e+09],
[-9.78648047e+10, -2.66024120e+11, 9.78648047e+10,
2.66024120e+11, -5.34323729e+12, -1.45244248e+13,
5.34323729e+12, 1.45244248e+13, -2.91730871e+14,
-7.93006726e+14, 2.91730871e+14, 7.93006726e+14],
[-1.59279659e+16, -4.32967002e+16, 1.59279659e+16,
4.32967002e+16, -8.69637471e+17, -2.36391973e+18,
8.69637471e+17, 2.36391973e+18, -4.74805971e+19,
-1.29065644e+20, 4.74805971e+19, 1.29065644e+20],
[-2.59235276e+21, -7.04674541e+21, 2.59235276e+21,
7.04674541e+21, -1.41537665e+23, -3.84739263e+23,
1.41537665e+23, 3.84739263e+23, -7.72769468e+24,
-2.10060520e+25, 7.72769468e+24, 2.10060520e+25]],
dtype=numpy.float32)
numpy.testing.assert_array_almost_equal(keras.backend.eval(pred_boxes)[0],
> expected[0], 0, verbose=True)
E AssertionError:
E Arrays are not almost equal to 0 decimals
E
E (mismatch 100.0%)
E x: array([1.e+00, 0.e+00, 5.e-43, 0.e+00, 5.e-43, 0.e+00, 5.e-43, 0.e+00,
E 5.e-43, 0.e+00, 5.e-43, 0.e+00], dtype=float32)
E y: array([-3.e+00, -9.e+00, 4.e+00, 1.e+01, -2.e+02, -5.e+02, 2.e+02,
E 6.e+02, -1.e+04, -3.e+04, 1.e+04, 3.e+04], dtype=float32)
tests/backend/test_common.py:239: AssertionError
________________________________ test_smooth_l1 ________________________________
def test_smooth_l1():
output = keras.backend.variable(
[[[2.5, 0.0, 0.4, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 2.5, 0.0, 0.4]],
[[3.5, 0.0, 0.0, 0.0],
[0.0, 0.4, 0.0, 0.9],
[0.0, 0.0, 1.5, 0.0]]]
)
target = keras.backend.zeros_like(output)
x = keras_rcnn.backend.smooth_l1(output, target)
> numpy.testing.assert_approx_equal(keras.backend.eval(x), 8.645)
E AssertionError:
E Items are not equal to 7 significant digits:
E ACTUAL: 0.0
E DESIRED: 8.645
tests/backend/test_common.py:256: AssertionError
_________________________ test_softmax_classification __________________________
def test_softmax_classification():
output = [[[-100, 100, -100],
[100, -100, -100],
[0, 0, -100],
[-100, -100, 100]],
[[-100, 0, 0],
[-100, 100, -100],
[-100, 100, -100],
[100, -100, -100]]]
target = [[[0, 1, 0],
[1, 0, 0],
[1, 0, 0],
[0, 0, 1]],
[[0, 0, 1],
[0, 1, 0],
[0, 1, 0],
[1, 0, 0]]]
weights = [[1.0, 1.0, 0.5, 1.0],
[1.0, 1.0, 1.0, 0.0]]
x = keras_rcnn.backend.softmax_classification(
keras.backend.variable(target), keras.backend.variable(output),
weights=keras.backend.variable(weights))
output_y = numpy.reshape(output, [-1, 3])
target_y = numpy.reshape(target, [-1, 3])
output_y = output_y / numpy.sum(output_y, axis=1, keepdims=True)
# epsilon = keras.backend.epsilon()
# stop python for complaining weakref
epsilon = 1e-07
output_y = numpy.clip(output_y,
epsilon,
1. - epsilon)
_y = - numpy.sum(target_y * numpy.log(output_y), axis=1)
y = _y * numpy.reshape(weights, -1)
> numpy.testing.assert_array_almost_equal(keras.backend.eval(x), y)
E AssertionError:
E Arrays are not almost equal to 6 decimals
E
E (mismatch 87.5%)
E x: array([0.e+00, 0.e+00, 1.e-45, 0.e+00, 3.e-45, 0.e+00, 4.e-45, 0.e+00],
E dtype=float32)
E y: array([16.118096, 16.118096, 8.059048, 16.118096, 16.118096, 16.118096,
E 16.118096, 0. ])
tests/backend/test_common.py:308: AssertionError
___________________________ test_scatter_add_tensor ____________________________
def test_scatter_add_tensor():
ref = keras.backend.ones((4, 5))
ii = keras.backend.reshape(
keras.backend.cast(keras.backend.zeros((4,)), 'int32'), (-1, 1))
jj = keras.backend.reshape(keras.backend.arange(0, 4), (-1, 1))
indices = keras.backend.concatenate([ii, jj], 1)
updates = keras.backend.arange(4, dtype=keras.backend.floatx()) * 2
result = keras_rcnn.backend.scatter_add_tensor(ref, indices, updates)
result = keras.backend.eval(result)
expected = numpy.ones((4, 5))
expected[0, :4] += numpy.arange(4) * 2
> numpy.testing.assert_array_almost_equal(result, expected)
E AssertionError:
E Arrays are not almost equal to 6 decimals
E
E (mismatch 100.0%)
E x: array([[2.69e-43, 0.00e+00, 2.70e-43, 0.00e+00, 2.72e-43],
E [0.00e+00, 2.73e-43, 0.00e+00, 2.75e-43, 0.00e+00],
E [2.76e-43, 0.00e+00, 2.77e-43, 0.00e+00, 2.79e-43],
E [0.00e+00, 2.80e-43, 0.00e+00, 2.82e-43, 0.00e+00]], dtype=float32)
E y: array([[1., 3., 5., 7., 1.],
E [1., 1., 1., 1., 1.],
E [1., 1., 1., 1., 1.],
E [1., 1., 1., 1., 1.]])
tests/backend/test_tensorflow_backend.py:60: AssertionError
_____________________________ test_crop_and_resize _____________________________
self = <tensorflow.python.client.session.Session object at 0x7faa79bdee80>
fn = <function BaseSession._do_run.<locals>._run_fn at 0x7faa4878b1e0>
args = (<Swig Object of type 'TF_DeprecatedSession *' at 0x7faa79c264e0>, {}, [b'CropAndResize:0'], [], None, None)
message = 'Failed launch CropAndResizeKernel.\n\t [[Node: CropAndResize = CropAndResize[T=DT_FLOAT, extrapolation_value=0, metho...tensor_name="edge_14_CropAndResize", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]'
m = <_sre.SRE_Match object; span=(37, 60), match='[[Node: CropAndResize ='>
def _do_call(self, fn, *args):
try:
> return fn(*args)
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py:1323:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
session = <Swig Object of type 'TF_DeprecatedSession *' at 0x7faa79c264e0>
feed_dict = {}, fetch_list = [b'CropAndResize:0'], target_list = []
options = None, run_metadata = None
def _run_fn(session, feed_dict, fetch_list, target_list, options,
run_metadata):
# Ensure any changes to the graph are reflected in the runtime.
self._extend_graph()
with errors.raise_exception_on_not_ok_status() as status:
if self._created_with_new_api:
return tf_session.TF_SessionRun_wrapper(
session, options, feed_dict, fetch_list, target_list,
run_metadata, status)
else:
return tf_session.TF_Run(session, options,
feed_dict, fetch_list, target_list,
> status, run_metadata)
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py:1302:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <tensorflow.python.framework.errors_impl.raise_exception_on_not_ok_status object at 0x7faa4879cc18>
type_arg = None, value_arg = None, traceback_arg = None
def __exit__(self, type_arg, value_arg, traceback_arg):
try:
if c_api.TF_GetCode(self.status.status) != 0:
raise _make_specific_exception(
None, None,
compat.as_text(c_api.TF_Message(self.status.status)),
> c_api.TF_GetCode(self.status.status))
E tensorflow.python.framework.errors_impl.InternalError: Failed launch CropAndResizeKernel.
E [[Node: CropAndResize = CropAndResize[T=DT_FLOAT, extrapolation_value=0, method="bilinear", _device="/job:localhost/replica:0/task:0/device:GPU:0"](Variable_22/read, Reshape_55, Reshape_54/_147, CropAndResize/crop_size)]]
E [[Node: CropAndResize/_149 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_14_CropAndResize", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py:473: InternalError
During handling of the above exception, another exception occurred:
def test_crop_and_resize():
image = keras.backend.variable(numpy.ones((1, 28, 28, 3)))
boxes = keras.backend.variable(
numpy.array([[0.1, 0.1, 0.2, 0.2],
[0.5, 0.5, 0.8, 0.8]]))
size = [7, 7]
slices = keras_rcnn.backend.crop_and_resize(image, boxes, size)
> assert keras.backend.eval(slices).shape == (2, 7, 7, 3)
tests/backend/test_tensorflow_backend.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/morteza/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py:660: in eval
return to_dense(x).eval(session=get_session())
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py:570: in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py:4455: in _eval_using_default_session
return session.run(tensors, feed_dict)
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py:889: in run
run_metadata_ptr)
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py:1120: in _run
feed_dict_tensor, options, run_metadata)
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py:1317: in _do_run
options, run_metadata)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <tensorflow.python.client.session.Session object at 0x7faa79bdee80>
fn = <function BaseSession._do_run.<locals>._run_fn at 0x7faa4878b1e0>
args = (<Swig Object of type 'TF_DeprecatedSession *' at 0x7faa79c264e0>, {}, [b'CropAndResize:0'], [], None, None)
message = 'Failed launch CropAndResizeKernel.\n\t [[Node: CropAndResize = CropAndResize[T=DT_FLOAT, extrapolation_value=0, metho...tensor_name="edge_14_CropAndResize", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]'
m = <_sre.SRE_Match object; span=(37, 60), match='[[Node: CropAndResize ='>
def _do_call(self, fn, *args):
try:
return fn(*args)
except errors.OpError as e:
message = compat.as_text(e.message)
m = BaseSession._NODEDEF_NAME_RE.search(message)
node_def = None
op = None
if m is not None:
node_name = m.group(1)
try:
op = self._graph.get_operation_by_name(node_name)
node_def = op.node_def
except KeyError:
pass
> raise type(e)(node_def, op, message)
E tensorflow.python.framework.errors_impl.InternalError: Failed launch CropAndResizeKernel.
E [[Node: CropAndResize = CropAndResize[T=DT_FLOAT, extrapolation_value=0, method="bilinear", _device="/job:localhost/replica:0/task:0/device:GPU:0"](Variable_22/read, Reshape_55, Reshape_54/_147, CropAndResize/crop_size)]]
E [[Node: CropAndResize/_149 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_14_CropAndResize", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
E
E Caused by op 'CropAndResize', defined at:
E File "/home/morteza/.local/bin/pytest", line 11, in <module>
E sys.exit(main())
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/config.py", line 59, in main
E return config.hook.pytest_cmdline_main(config=config)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
E return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
E return self._inner_hookexec(hook, methods, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
E firstresult=hook.spec_opts.get('firstresult'),
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
E res = hook_impl.function(*args)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/main.py", line 136, in pytest_cmdline_main
E return wrap_session(config, _main)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/main.py", line 105, in wrap_session
E session.exitstatus = doit(config, session) or 0
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/main.py", line 143, in _main
E config.hook.pytest_runtestloop(session=session)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
E return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
E return self._inner_hookexec(hook, methods, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
E firstresult=hook.spec_opts.get('firstresult'),
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
E res = hook_impl.function(*args)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/main.py", line 166, in pytest_runtestloop
E item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
E return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
E return self._inner_hookexec(hook, methods, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
E firstresult=hook.spec_opts.get('firstresult'),
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
E res = hook_impl.function(*args)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 62, in pytest_runtest_protocol
E runtestprotocol(item, nextitem=nextitem)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 76, in runtestprotocol
E reports.append(call_and_report(item, "call", log))
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 155, in call_and_report
E call = call_runtest_hook(item, when, **kwds)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 175, in call_runtest_hook
E return CallInfo(lambda: ihook(item=item, **kwds), when=when)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 189, in __init__
E self.result = func()
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 175, in <lambda>
E return CallInfo(lambda: ihook(item=item, **kwds), when=when)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
E return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
E return self._inner_hookexec(hook, methods, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
E firstresult=hook.spec_opts.get('firstresult'),
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
E res = hook_impl.function(*args)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/runner.py", line 106, in pytest_runtest_call
E item.runtest()
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/python.py", line 1171, in runtest
E self.ihook.pytest_pyfunc_call(pyfuncitem=self)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
E return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
E return self._inner_hookexec(hook, methods, kwargs)
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
E firstresult=hook.spec_opts.get('firstresult'),
E File "/home/morteza/.local/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
E res = hook_impl.function(*args)
E File "/home/morteza/.local/lib/python3.5/site-packages/_pytest/python.py", line 147, in pytest_pyfunc_call
E testfunction(**testargs)
E File "/fast/keras-rcnn/tests/backend/test_tensorflow_backend.py", line 100, in test_crop_and_resize
E slices = keras_rcnn.backend.crop_and_resize(image, boxes, size)
E File "/fast/keras-rcnn/keras_rcnn/backend/tensorflow_backend.py", line 145, in crop_and_resize
E return tensorflow.image.crop_and_resize(image, boxes, box_ind, size)
E File "/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/ops/gen_image_ops.py", line 237, in crop_and_resize
E extrapolation_value=extrapolation_value, name=name)
E File "/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
E op_def=op_def)
E File "/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
E op_def=op_def)
E File "/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
E self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
E
E InternalError (see above for traceback): Failed launch CropAndResizeKernel.
E [[Node: CropAndResize = CropAndResize[T=DT_FLOAT, extrapolation_value=0, method="bilinear", _device="/job:localhost/replica:0/task:0/device:GPU:0"](Variable_22/read, Reshape_55, Reshape_54/_147, CropAndResize/crop_size)]]
E [[Node: CropAndResize/_149 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_14_CropAndResize", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
/home/morteza/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py:1336: InternalError
===================== 11 failed, 14 passed in 2.37 seconds =====================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment