pmneila / PyMaxflow

Python library for creating flow networks and computing the maxflow/mincut (aka graph-cuts for Python)
http://pmneila.github.io/PyMaxflow/
242 stars 59 forks source link

layout_examples.py not working for me #37

Closed h4k1m0u closed 5 years ago

h4k1m0u commented 5 years ago

Hi,

First, thanks for this library. It's way better than having to decipher the C++ code published by Kolmogorov et al..

The plot function in this example isn't working for me though. Whether it's on the Windows terminal where I get shell returned -1073741819, or on jupyter notebook which completely fails when I run it.

I suspect get_nx_graph() of being responsible of the above error, which happens particularly when adding edges (add_edge() and add_grid_edges()), but not if with add nodes only (add_nodes(), add_grid_nodes()). However, I'm not comfortable enough with cython to debug it.

Finally, I think that plot_graph_2d() should be installed with the python package as well, to be able to plot graphs without copying the content of that function.

pmneila commented 5 years ago

Hi, @h4k1m0u

-1073741819 is the code for Memory Access Violation. This problem is very strange and doesn't seem to be directly related to PyMaxflow but to your current configuration of Python (or even Windows) libraries.

How did you install the library? Using pip?

Do you have several Python versions installed (for example, 3.6 and 3.5 or 2.7)? In that case, maybe PyMaxflow was compiled for one of those versions and you are loading it from a different version? Or maybe you installed PyMaxflow several times and you have multiple copies of it (for example, using pip first and then downloading and installing the library by hand)?

I am not aware of recent complaints about the library causing problems in Windows, but unfortunately I do not have an available Windows machine to test it myself.

Regarding the play_graph_2d, I am not sure if I understand the problem is. It is currently distributed with the package. The idea is that you run the examples inside the examples folder, so you do not have to copy the content of the function anywhere, but import it from examples_utils.py.

h4k1m0u commented 5 years ago

Hi @pmneila

PyMaxflow was installed using pip.

I have multiple versions of Python installed indeed (2.7 and 3.6), but only Python3 is activated. The error appears on the version I'm using (3.6), and the one PyMaxflow was installed on.

I encounter the same issue on my laptop also which has Python 3.7 and Windows8x64, instead of Windows10.

As for play_graph_2d, I cannot see any examples_util.py inside C:\Python36\Lib\site-packages\maxflow, and obviously in this case doing import examples_util.py fails.

Thanks.

pmneila commented 5 years ago

I encounter the same issue on my laptop also which has Python 3.7 and Windows8x64, instead of Windows10.

Ok, I'll try to find a windows machine to test this and I'll get back to you. It's really strange.

As for play_graph_2d, I cannot see any examples_util.py inside C:\Python36\Lib\site-packages\maxflow, and obviously in this case doing import examples_util.py fails.

I see what you mean. In principle, the examples (and related code) are not distributed with pip. The idea is that you should locally copy the examples folder, which contains not only auxiliary functions but also images required in some examples. plot_graph_2d() is a messy function meant for demonstration purposes and not ready for production. That's why I'd rather not have it as part of the main library.

I might consider copying the function inside each individual example so you don't need to deal with examples_utils.py (although this is not very elegant either).

pmneila commented 5 years ago

Hi again,

I tested the package in Windows 7 with Anaconda (Python 3.7) and I run examples_layouts.py with no errors or failures. I cannot reproduce your problem.

Just in case, I uploaded a wheel to PyPI with a precompiled version of PyMaxflow for Windows and Python 3.7. Try uninstalling and installing the package again in your Windows8x64 (the one with Python 3.7):

pip uninstall PyMaxflow
pip install PyMaxflow --no-cache-dir

Check that pip install... is downloading and installing the wheel file (PyMaxflow-1.2.11-cp37-cp37m-win_amd64.whl) and not compiling the code from the source. The precompiled version might fix your problem.

h4k1m0u commented 5 years ago

Thanks for the help.

But, it still didn't work for me. I get the usual window saying "Python has stopped working"

I made sure that pip is installing the correct version of PyMaxFlow. If it helps, I have Numpy-v1.15.4 installed no Python-v3.7.1, but I'm not using Anaconda.

It's not really a critical functionality that I need in my application. I think though that I should leave the issue open, in case somebody else comes across it.

alaa137 commented 5 years ago

I'm having the same problem. I try to run the examples (layout_examples.py / binary_restoration.py) in Windows 8.1 command line, and python stops working:

python binary_restoration.py

image

If i step in debug mode in PyCharm in binary_restoration.py, it gets to the line graph = g.get_nx_graph(), and then the program just exits with an error code -1073741819 (0xC0000005):

Process finished with exit code -1073741819 (0xC0000005)


Update: Same thing happens on Windows 10.

niranjantdesai commented 5 years ago

I tested get_nx_graph() on Python versions 3.7, 3.6 and 2.7 and got the same return code every time. I'm using a Windows 10 64-bit machine.

pmneila commented 5 years ago

Hi everyone,

I managed to reproduce the error in a Windows 10 and it is finally fixed. You can get the last working version with pip install PyMaxflow --upgrade.

Sorry for the inconveniences.