fversaci/WaveTF

Mini CNN has a bug?

Closed this issue · 10 comments

Hi friend,

I ran the code of mini ccn, but python returns:

`ValueError: Exception encountered when calling layer "daub_wave_layer2d" (type DaubWaveLayer2D).

in user code:

File "C:\Users\marco\AppData\Local\Programs\Python\Python39\lib\site-packages\wavetf\_base_wavelets.py", line 109, in call  *
    return self.kernel_function(batch)
File "C:\Users\marco\AppData\Local\Programs\Python\Python39\lib\site-packages\wavetf\_daubachies_conv.py", line 216, in kernel_function  *
    s1 = tf.reshape(s1, [self.bs*self.cn*self.ox, -1, 1])

ValueError: Invalid value in tensor used for shape: -672

Call arguments received:
• batch=tf.Tensor(shape=(None, 224, 224, 3), dtype=float32)`

The images are RGB:

img_size= 224
channels = 3
input_shape = (img_size, img_size, channels)

Hi @SrMarkLau,
which version of Tensorflow are you using?

same for me tf 2.4.0

with 128x128x3 as input shape

ValueError: Invalid value in tensor used for shape: -384

same with tf2.2

i just run this command in Jupyter
wavelet_cnn(input_shape=(128,128,3))

Hi, can you produce a minimal, non-working example that I could run and test?

my error

ValueError Traceback (most recent call last)
in
----> 1 wavelet_cnn(input_shape=(128,128,3))

in wavelet_cnn(input_shape, ks, baselev, wavelet, wave_kern, hsv, convrep, num_classes)
22 wave0 = inputs
23 # compute 4 level of wavelet
---> 24 wave1 = WaveTFFactory.build(wave_kern)(wave0)
25 # compute new wavelet features from LL componenents
26 wave2 = WaveTFFactory.build(wave_kern)(wave1[:,:,:,:chans])

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
920 not base_layer_utils.is_in_eager_or_tf_function()):
921 with auto_control_deps.AutomaticControlDependencies() as acd:
--> 922 outputs = call_fn(cast_inputs, *args, **kwargs)
923 # Wrap Tensors in outputs in tf.identity to avoid
924 # circular dependencies.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
263 except Exception as e: # pylint:disable=broad-except
264 if hasattr(e, 'ag_error_metadata'):
--> 265 raise e.ag_error_metadata.to_exception(e)
266 else:
267 raise

ValueError: in user code:

/usr/local/lib/python3.6/dist-packages/wavetf/_base_wavelets.py:109 call  *
    return self.kernel_function(batch)
/usr/local/lib/python3.6/dist-packages/wavetf/_daubachies_conv.py:216 kernel_function  *
    s1 = tf.reshape(s1, [self.bs*self.cn*self.ox, -1, 1])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py:193 reshape  **
    result = gen_array_ops.reshape(tensor, shape, name)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py:8087 reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:744 _apply_op_helper
    attrs=attr_protos, op_def=op_def)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py:595 _create_op_internal
    compute_device)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:3327 _create_op_internal
    op_def=op_def)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:1817 __init__
    control_input_ops, op_def)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:1657 _create_c_op
    raise ValueError(str(e))

ValueError: Invalid value in tensor used for shape: -384

I clone your repository master branch and next pip install .

Hi, I just pushed a commit that seems to fix this issue.
Could you check if that works for you as well?

image
fix for me thanks a lot

All right then 👍 Thank you for pointing out the issue!

Welcome,
small question: do you know how to reproduce this code with your keras module ?
https://github.com/mxbastidasr/DAWN_WACV2020 (Wavelet CNN part)

Hi,
I don't have time to write the network in detail, but keep in mind that, being wave the output of a wavelet layer working on 3 channels (e.g., RGB), its LL component is given by wave[..., :3], while the LH, HL and HH components are wave[..., 3:].

All the other layers in your network look like standard keras ones. Try to have a look at mini_cnn.py code for an example of applying a wavelet layer on the LL component of the output of a previous wavelet layer.