DeepLearnPhysics / larcv2

MIT License
13 stars 16 forks source link

Runtime error with segment violation while running larcv.as_ndarray() #25

Open nfoppiani opened 6 years ago

nfoppiani commented 6 years ago

I am try to run the tutorial02 and I got the following error while running this piece of code:

for index, image in enumerate(image2d_array):
    # Note here that std::vectors in pyroot are iterable
    # larcv has a helper function to convert std::vector to numpy array, so we can use that:
    image_numpy = larcv.as_ndarray(image)
    print("Image index", index)
    print("image_numpy has type {}".format(type(image_numpy)))
    print("Image dimensions are {}".format(image_numpy.shape))
    #Show the image with imshow:
    fig = plt.figure(figsize=(8,8))
    plt.imshow(image_numpy, interpolation='none',cmap='jet')
    plt.show()

Error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: _ARRAY_API is not PyCObject object

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-d1aaf3a5b8de> in <module>()
      2     # Note here that std::vectors in pyroot are iterable
      3     # larcv has a helper function to convert std::vector to numpy array, so we can use that:
----> 4     image_numpy = larcv.as_ndarray(image)
      5     print("Image index", index)
      6     print("image_numpy has type {}".format(type(image_numpy)))

TypeError: none of the 9 overloaded methods succeeded. Full details:
  _object* larcv::as_ndarray(const vector<short>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<unsigned short>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<int>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<unsigned int>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<Long64_t>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<ULong64_t>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<float>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const vector<double>& data) =>
    could not convert argument 1
  _object* larcv::as_ndarray(const larcv::Image2D& img) =>
    problem in C++; program state has been reset

 *** Break *** segmentation violation
 Generating stack trace...
 0x00007fc07b4e02db in FastCall(long, void*, void*, void*) at /home/nick/Downloads/root_v6.12.04.source/root-6.12.04/bindings/pyroot/src/Cppyy.cxx:435 from /home/nick/Software/root_python3/lib/libPyROOT.so
 0x00007fc07b4e0d70 in Cppyy::CallR(long, void*, void*) at /home/nick/Downloads/root_v6.12.04.source/root-6.12.04/bindings/pyroot/src/Cppyy.cxx:471 from /home/nick/Software/root_python3/lib/libPyROOT.so
 0x00007fc07b4e4068 in PyROOT::TPyObjectExecutor::Execute(long, void*, PyROOT::TCallContext*) at /home/nick/Downloads/root_v6.12.04.source/root-6.12.04/bindings/pyroot/src/Executors.cxx:633 from /home/nick/Software/root_python3/lib/libPyROOT.so
 0x00007fc07b504d42 in PyROOT::TMethodHolder::CallSafe(void*, long, PyROOT::TCallContext*) at /home/nick/Downloads/root_v6.12.04.source/root-6.12.04/bindings/pyroot/src/TMethodHolder.cxx:126 from /home/nick/Software/root_python3/lib/libPyROOT.so
 0x00007fc07b504909 in PyROOT::TMethodHolder::Execute(void*, long, PyROOT::TCallContext*) at /home/nick/Downloads/root_v6.12.04.source/root-6.12.04/bindings/pyroot/src/TMethodHolder.cxx:531 from /home/nick/Software/root_python3/lib/libPyROOT.so
 0x00007fc07b4e8e7a in <unknown> from /home/nick/Software/root_python3/lib/libPyROOT.so
 0x00007fc0a40940f4 in _PyObject_FastCallDict + 0x94 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d8d in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410bb38 in PyEval_EvalCodeEx + 0x328 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410c8bb in PyEval_EvalCode + 0x1b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a414098a in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40f518f in _PyCFunction_FastCallDict + 0x8f from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102c5a in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093073 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093073 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412dd9e in _PyEval_EvalFrameDefault + 0x124e from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40933cd in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093f7d in _PyFunction_FastCallDict + 0x40d from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40942ce in _PyObject_FastCallDict + 0x26e from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409e101 in _PyObject_Call_Prepend + 0x61 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409470b in PyObject_Call + 0x4b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412e976 in _PyEval_EvalFrameDefault + 0x1e26 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093245 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412dd9e in _PyEval_EvalFrameDefault + 0x124e from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093073 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c52ea in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c52ea in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410c185 in PyEval_EvalCodeEx + 0x975 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410c9e6 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409470b in PyObject_Call + 0x4b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412e976 in _PyEval_EvalFrameDefault + 0x1e26 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410c185 in PyEval_EvalCodeEx + 0x975 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410c9e6 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409470b in PyObject_Call + 0x4b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412e976 in _PyEval_EvalFrameDefault + 0x1e26 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093073 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c52ea in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093c8a in _PyFunction_FastCallDict + 0x11a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40942ce in _PyObject_FastCallDict + 0x26e from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409e101 in _PyObject_Call_Prepend + 0x61 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409470b in PyObject_Call + 0x4b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412e976 in _PyEval_EvalFrameDefault + 0x1e26 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40933cd in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c52ea in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c52ea in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093073 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410bb38 in PyEval_EvalCodeEx + 0x328 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410c8bb in PyEval_EvalCode + 0x1b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a414098a in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40f518f in _PyCFunction_FastCallDict + 0x8f from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102c5a in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4093073 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a40c5511 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a4102d1e in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a412ce9a in _PyEval_EvalFrameDefault + 0x34a from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410bb38 in PyEval_EvalCodeEx + 0x328 from /lib64/libpython3.6m.so.1.0
 0x00007fc0a410ca6c in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a409470b in PyObject_Call + 0x4b from /lib64/libpython3.6m.so.1.0
 0x00007fc0a419b6b1 in <unknown> from /lib64/libpython3.6m.so.1.0
 0x00007fc0a419bb7f in Py_Main + 0x35f from /lib64/libpython3.6m.so.1.0
 0x00005653a74f1d45 in main + 0x1f5 from /usr/bin/python3
 0x00007fc0a326ff2a in __libc_start_main + 0xea from /lib64/libc.so.6
 0x00005653a74f1eba in _start + 0x2a from /usr/bin/python3

I am using Python 3.6, ROOT 6.12 and I compiled larcv without opencv.

petersinemetu commented 6 years ago

Hi, I am currently facing the exact same issue. Any luck with this? Thanks

drinkingkazu commented 6 years ago

Thanks for bumping up this issue again! Should have looked at it earlier. I suspect this is an issue on us not running tests with Python 3. If you have a way around to use Python 2, would you mind to test and see if it works?

If Python 3 is needed, then I suggest we start from building a singularity container for python3 and compiling larcv on it (so that we share exactly what's going on): https://github.com/DeepLearnPhysics/larcv2-singularity/blob/master/Singularity.ubuntu16.04-gpu-py3

petersinemetu commented 6 years ago

Hi again and thanks for the quick response. I'm a total newbie but I think that somewhere in the code, the CObject API is called, which was deprecated as of Python 3.1 and substituted by the Capsules API (I built ROOT and ran larcv with Python3.5) Will try with Python2 and let you know. Thanks.

petersinemetu commented 6 years ago

So I rebuilt ROOT with Python 2.7 (and sudo apt-get install python-tk for matplotlib to work) and.....

image

I'm so happy :smile: Thank you!

nfoppiani commented 6 years ago

So if I understand correctly it is just a matter of using Python2 and ROOT compiled with Python2, correct? I will try to see if I can make it working with these settings then

petersinemetu commented 6 years ago

Yes, at least that did the trick for my system.