Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting channels with TF V2.4.0 and onwards breaks #11

Open
maartenvds opened this issue Jul 26, 2021 · 2 comments
Open

Deleting channels with TF V2.4.0 and onwards breaks #11

maartenvds opened this issue Jul 26, 2021 · 2 comments

Comments

@maartenvds
Copy link

Hi,

I tested your repo with the included lenet.py example and this works fine up until and including TF V2.3.0 (I use tf.keras). I also tried TF V2.4.0 and V2.5.0 which both gave me the following error:

Traceback (most recent call last):
  File "lenet.py", line 110, in <module>
    main()
  File "lenet.py", line 81, in main
    model = delete_channels(model, layer, high_apoz_channels)
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/kerassurgeon/operations.py", line 105, in delete_channels
    return surgeon.operate()
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/kerassurgeon/surgeon.py", line 155, in operate
    sub_output_nodes)
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/kerassurgeon/surgeon.py", line 278, in _rebuild_graph
    outputs, output_masks = zip(*[_rebuild_rec(n) for n in output_nodes])
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/kerassurgeon/surgeon.py", line 278, in <listcomp>
    outputs, output_masks = zip(*[_rebuild_rec(n) for n in output_nodes])
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/kerassurgeon/surgeon.py", line 215, in _rebuild_rec
    node_output = utils.single_element(node.output_tensors)
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/kerassurgeon/utils.py", line 144, in single_element
    if len(x) == 1:
  File "/home/maarten/.virtualenvs/easics_colonoscopy/lib/python3.7/site-packages/tensorflow/python/keras/engine/keras_tensor.py", line 221, in __len__
    raise TypeError('Keras symbolic inputs/outputs do not '
TypeError: Keras symbolic inputs/outputs do not implement `__len__`. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model. This error will also get raised if you try asserting a symbolic input/output directly.

What can be done to fix this?

@maartenvds maartenvds changed the title Deleting channels with TF V2.4.0 and onwards break Deleting channels with TF V2.4.0 and onwards breaks Jul 26, 2021
@Raukk
Copy link
Owner

Raukk commented Aug 4, 2021

Sorry for the delay in replying.

The original Keras Surgeon project has been updated to support tf.keras so, my reason for creating this repo is no longer valid.

Because of that, I've quit maintaining this repo.

Sorry for any inconvenience.

If the original Keras Surgeon project isn't able to cover your needs, then reply back and I'll try to look into it.

@MarvinKlemp
Copy link

@Raukk the original keras surgeon project does not seem to be maintained anymore.

I've tested every version of TF > 2.0.
Even including both Pull Requests from the original repo that fix different TF > 2.0 issues
(Also the __len__ issues described by this issue)

Once non Conv2D layers are used, kerassurgeon does not work anymore.

# is fine and can be pruned with kerassurgeon and TF > 2.0
model = tf.keras.Sequential([
    tf.keras.layers.Conv2D(5, (3,3)),
    tf.keras.layers.Conv2D(2, (3,3))
])
model = tf.keras.Sequential([
    tf.keras.layers.Conv2D(5, (3,3)),
    tf.keras.layers.UpSampling2D(), <- breaks kerassurgeon 
    tf.keras.layers.Conv2D(2, (3,3))
])

what I found out also breaks the lib is BatchNorm and UpSampling2D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants