BenWhetton / keras-surgeon

Pruning and other network surgery for trained Keras models.
Other
403 stars 107 forks source link

For People Who need > TF2.3 compatability #71

Open Woodyet opened 2 years ago

Woodyet commented 2 years ago

Hello I have been using this library for a bit and have a slightly edited library that works for at least tensorflow 2.5

https://github.com/Woodyet/Pix2Pix_Auto_Prune/tree/master/Pix2Pix_Auto_Prune/Tensorflow2.5.0/kerassurgeon

Most of the updates are lifted from the pull requests here

It's not fully tested but I think someone more capable than me should clone that repo and make a keras-surgeon-2 as I don't think Ben is coming back to this

King-Of-Knights commented 2 years ago

@Woodyet Thanks a a lot! I will test this on TF 2.7.0

Woodyet commented 2 years ago

The deleting of convtranspose is deffo broken, just notice the output_mask is set to None (which won't work if you have a model with subsequent layers)

callum-b commented 2 years ago

Thanks for working on this! Do you have a script example where you use this new library?

christian-steinmeyer commented 1 year ago

I'm not sure quite yet, whether I'll go all the way with releasing a pip package etc., but if you're fine with a pip install via git repo, check out my fork. I've put in a bit of effort in getting everything tidy including all functional PRs from this repo and adding depthwise convolutions. I also added the option to provide your own implementations for any additional layers, you might need. I might add more layers, if I need them for my work.

pip install keras-surgeon@git+https://github.com/christian-steinmeyer/keras-surgeon.git

Disclaimer: Although I am working with TF 2.12 and seem to have no issues, no guarantees, that everything works 100% correct.

Woodyet commented 1 year ago

I am sure people can test for themselves, but I am pretty sure tensorflow changed some fundamental code infrastructure when going from 2.2 to 2.3.

Which was what broke this library. But thanks for working on it.

christian-steinmeyer commented 1 year ago

@Woodyet Do you know anything more specific / do you have any pointers to what leads you to this conclusion? Although original testing worked out great for me, I do experience some unexplained behavior now that I do more in depth tests.

For example, I prune units from dense layers that have zero weights, which shouldn't really affect the model output, but unfortunately, it does, although the relevant subset of weights (those not pruned, because they were not zero) is exactly as expected after the pruning.

aidevmin commented 4 months ago

@christian-steinmeyer Do you meet this error "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 la mbda layer in the Functional Model. This error will also get raised if you try a sserting a symbolic input/output directly."

I used pre-trained MobileNetv1 model with changed number of classes. But I got this error. I used TF2.12.