ranjanZ / 2D-Morphological-Network

2D Morphological-Network
18 stars 7 forks source link

Issues running the code #2

Open ama542blake opened 4 years ago

ama542blake commented 4 years ago

Hello,

I have read your paper "Morphological Networks for Image De-raining”, and found it very interesting. I also have downloaded your code from the link to GitHub in your paper. Thank you very much for including that, it will be incredibly helpful. However I have set up the project and installed all of the requirements, but I am having trouble getting your code to run.

The first issue I have gives the following traceback: Traceback (most recent call last): File "run.py", line 3, in from models import File "/Users/Blake/Desktop/CV/Papers/Morphological Network/2D-Morphological-Network-master/src/models.py", line 8, in from morph_layers2D import File "/Users/Blake/Desktop/CV/Papers/Morphological Network/2D-Morphological-Network-master/src/morph_layers2D.py", line 5, in from keras.layers import initializers,constraints ImportError: cannot import name initializers

In doing some quick searches, I found I could get rid of the error by changing line 5 of morph_layers2D from from keras.layers import initializers, constraints to from keras import initializers, constraints

But after doing this, I get a new error

Traceback (most recent call last): File "run.py", line 163, in main(input_dir=sys.argv[1],output_dir=sys.argv[2]) File "run.py", line 128, in main D=get_all_models() File "run.py", line 56, in get_all_models path1=model_path1() File "/Users/Blake/Desktop/CV/Papers/Morphological Network/2D-Morphological-Network-master/src/models.py", line 86, in model_path1 z1=Dilation2D(4, (8,8),padding="same",strides=(1,1))(z1) File "/Users/Blake/anaconda3/envs/py2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper return func(*args, kwargs) File "/Users/Blake/anaconda3/envs/py2/lib/python2.7/site-packages/keras/engine/base_layer.py", line 489, in call output = self.call(inputs, kwargs) File "/Users/Blake/Desktop/CV/Papers/Morphological Network/2D-Morphological-Network-master/src/morph_layers2D.py", line 143, in call self.strides, self.padding), File "/Users/Blake/Desktop/CV/Papers/Morphological Network/2D-Morphological-Network-master/src/morph_layers2D.py", line 172, in __dilation2d rates, padding.upper()) TypeError: dilation2d_v2() takes at least 6 arguments (5 given)

Running on Python 2.7.16, Keras 2.3.1, tesorflow 2.0.0

Going through all of the locations mentioned in the traceback, I can not find anything with the name dilation2d_v2. How can I solve this issue?

ranjanZ commented 4 years ago

Hello @ama542blake , Thank you for your interest. I can see that the in the tensor-flow version the parameter settings has been updated. See this https://www.tensorflow.org/api_docs/python/tf/nn/dilation2d. tf.nn.dilation2d( input, filters, strides, padding, data_format, dilations, name=None )


Hence you may update accordingly. For example: At line number 172 Change x = tf.nn.dilation2d(x, st_element, (1, ) + strides + (1, ), rates, padding.upper())

to

x = tf.nn.dilation2d(x, st_element, (1, ) + strides + (1, ), padding.upper(),"NHWC",rates)

Please check and let me know if there is any further problem in running.

ama542blake commented 4 years ago

@ranjanZ thank you very much, that has solved that problem. However, now I am getting errors about indentation levels. For example, in run.py, the lines are like this:

Screen Shot 2019-11-06 at 7 26 13 PM

And also there is a statement with incorrect syntax in run.py:

Screen Shot 2019-11-06 at 7 27 04 PM

Other errors in run.py: Line 123: indentation error Line 130: indentation error, and the following lines (through 148) are also not indented, and it seems like they are intended to be part of the for loop on line 129, but I am not completely sure

Screen Shot 2019-11-06 at 7 32 13 PM

Line 142: indentation error

Errors in morph_layers2D.py line 36: indentation error, though it looks to me more like the error is in line 34:

Screen Shot 2019-11-06 at 7 34 00 PM

line 208: Another indentation error

Screen Shot 2019-11-06 at 10 59 10 PM

Also here, I'm getting all kinds of errors and it's really hard to tell how I should fix them (where is the end of the for loop supposed to be? are some of them nested?) since the indentation is off and line spacing is seemingly sporadic.

Screen Shot 2019-11-06 at 11 04 44 PM

In line of morh_layers2D, I get the error: "ImportError: cannot import name 'initializers' from 'keras.layers' ", which seems to be fixed by replacing from keras.layers import initializers, constraints with from keras import initializers, constraints

I am also getting a similar error to the first one here, which is expected, so I replaced it with something similar, but I'm not sure if this would be correct:

Screen Shot 2019-11-06 at 11 18 11 PM

In generator.py I am getting even more indentation errors. I will not type them all out, but there are quite a few, including these:

Screen Shot 2019-11-06 at 11 12 44 PM

Another error from generator: AttributeError: module 'scipy.misc' has no attribute 'imread'.

Errors just keep on coming and I don't have time to go through them all at the moment. Perhaps it would be helpful if you included the version numbers of all of the modules you used in the code? I suspect that may be the issue with most of the import statements.

I hope you don't mind me pointing all of the errors out, but I'm very confused on how to make this code run. I'm wondering how this happened, because I'm assuming you were able to run the code when you uploaded it. I'm not sure how the indentations would have changed when you uploaded it, but unfortunately indentation is meaningful in python.

Thank you, for your time.

ranjanZ commented 4 years ago

Thanks @ama542blake for pointing out the errors.

For all the indentation errors are because of tab and spacing. you can use autopep8 to correct that.

AttributeError: module 'scipy.misc' has no attribute 'imread scipy has been updated.

Anyways. I think I should update it to the latest version of the code.

ranjanZ commented 4 years ago

@ama542blake code has been updated. Please check once and let me know if there is any issue that I missed. Please install package imageio by pip. Also feel free to send pull request. Thanks

ama542blake commented 4 years ago

@ranjanZ thank you very much! It is working now. All I had to do this time was update the calls to dilation2d/eriosion2d to match the newer version of tensorflow.

ama542blake commented 4 years ago

I am wondering, is there documentation for this code anywhere? I am finding it kind of hard to understand.

ranjanZ commented 4 years ago

https://github.com/ranjanZ/2D-Morphological-Network/blob/master/Readme.md I would also suggest you read the paper. Also let me know the file that need more explanation ?

ama542blake commented 4 years ago

@ranjanZ I have read the paper. I understand what the system does. I just am having trouble understand what certain variables represent. For example in main() in run.py, what are t1 and t2?

ranjanZ commented 4 years ago

Thanks, could you please send patch mentioning the part that is not understandable.

t1, t2 = gen.get_test_data()

t1,t2 are coming from get_test data() t1 is the Input and t2 is the ground truth.

ranjanZ commented 4 years ago

Also, I am planning to upload a code with proper documentation for both 2D and dense morphological network soon after submitting a paper at journal.

ama542blake commented 4 years ago

Which versions of Keras and Tensorflow was the code implemented with? I'm having some compatibility issues when trying to train the model with new data.