Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Handle OpenCV exceptions instead of aborting #13217

Closed
lgov opened this issue Nov 11, 2018 · 5 comments · Fixed by #14433
Closed

Handle OpenCV exceptions instead of aborting #13217

lgov opened this issue Nov 11, 2018 · 5 comments · Fixed by #14433
Labels
Exception Handling OpenCV OpenCV related issues

Comments

@lgov
Copy link
Contributor

lgov commented Nov 11, 2018

(This is intended as an umbrella issue to follow up my ongoing proposal on the dev mailing list & work on handling OpenCV exceptions)

Description

I am working on migrating a classification product currently using Caffe to
MXNet. Along the way I'm encountering some issues loading and augmenting
the images dataset.

Basically it seems my dataset contains some technically invalid images.
When loading them using mx.io.ImageRecordIter (from a Python script), they
get passed eventually to the OpenCV library which will throw a C++
exception. MXNet currently doesn't capture those, resulting in my script
aborting with a not very clear error message.

Error Message:

"
terminate called after throwing an instance of 'cv::Exception'

what(): OpenCV(3.4.3)
/home/lgo/dev/opencv-3.4.3/modules/imgproc/src/resize.cpp:4044: error:
(-215:Assertion failed) !ssize.empty() in function 'resize'

Aborted (core dumped)
"

Environment info (Required)

Linux (Ubuntu 18.04), OpenCV 3.4.3, mxmet master branch, Python 3.6.6

Build info (Required if built from source)

Compiler (gcc/clang/mingw/visual studio):
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

Steps to reproduce

It's not clear exactly which image causes this particular exception. As the process aborts due to the unhandled exception, there is no easy way to capture good information about the process status - in this case the image name.

@lgov
Copy link
Contributor Author

lgov commented Nov 11, 2018

Draft proposal on how to handle OpenCV exceptions on the dev mailing list:

http://mail-archives.apache.org/mod_mbox/mxnet-dev/201811.mbox/%3cCANvU9seUjFbVYCk49T93R0BfDxbFq-cenirRRuZdCHYekOFD6Q@mail.gmail.com%3e

@lgov
Copy link
Contributor Author

lgov commented Nov 11, 2018

Related issues:
#9913 - TODO list for Exception Handling Support

#11912 - failed to catch imdecode exception
#10389 - Report clear errors when opencv::imdecode fails.
#9475 - OpenCV Error: Assertion failed
#12999 - throw mxnet exceptions when decoding invalid images.
#10393 - ImageRecordIOParser2 Assertion failed
#12280 - Reading/ignoring corrupt images with Gluon data loader (imdecode error cannot be captured)

@leleamol
Copy link
Contributor

@mxnet-label-bot add [OpenCV, Exception Handling]

@marcoabreu marcoabreu added Exception Handling OpenCV OpenCV related issues labels Nov 13, 2018
@eric-haibin-lin
Copy link
Member

Do you know why this happens? @lgov

@lgov
Copy link
Contributor Author

lgov commented Dec 21, 2018

Do you know why this happens? @lgov

Late reply, I missed the notification. But what exactly do you mean?
An application using mxnet will abort whenever there is an Assert triggered in the 3rd party libraries it uses, or atleast in OpenCV. That can for instance happen when you pass it an incorrect image file (take a text file and load it as .jpg for instance).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Exception Handling OpenCV OpenCV related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants