I am working on a Convolutional Neural Net built using Keras. And since the final model needs to be deployed on a processing unit with less processing capabilities, I started looking for ways to reduce the resources it'd consume. Luckily, I came across this library in Keras, Keras-surgeon, that helps in modifying trained Keras models.
I'm trying to delete channels in one of my Conv Net layers (and will proceed further on other layers). Although, documentation is very straightforward and simple, and people who have used this also praise it, when I tried to use it, it returns a weird type-error:
from kerassurgeon import Surgeon
surgeon = Surgeon(model_final)
layer_1 = model_final.layers[1] # selecting 2nd layer
surgeon.add_job('delete_channels', layer_1, channels=[4,7,3])
new_model = surgeon.operate()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-292-77c377538a52> in <module>
5
6 surgeon.add_job('delete_channels', layer_1, channels=[4,7,3])
----> 7 new_model = surgeon.operate()
~/anaconda3/envs/Learning/lib/python3.6/site-packages/kerassurgeon/surgeon.py in operate(self)
150 for node in sorted_nodes:
151 # Rebuild submodel up to this node
--> 152 sub_output_nodes = utils.get_node_inbound_nodes(node)
153 outputs, output_masks = self._rebuild_graph(self.model.inputs,
154 sub_output_nodes)
~/anaconda3/envs/Learning/lib/python3.6/site-packages/kerassurgeon/utils.py in get_node_inbound_nodes(node)
88 def get_node_inbound_nodes(node):
89 return [get_inbound_nodes(node.inbound_layers[i])[node_index]
---> 90 for i, node_index in enumerate(node.node_indices)]
91
92
TypeError: 'int' object is not iterable
What exactly am I doing wrong here?
Also, can anyone point out anything that I could use to run the keras model on, to see its resources consumption (memory and CPU etc.)? (It'll be a big help!)
- And what other approaches I can take to have a model that takes less resources without compromising accuracy?
Any help will be much appreciated..!