我正在使用Keras构建一个卷积神经网络。由于最终的模型需要部署在处理能力较低的处理单元上,所以我开始寻找减少它消耗的资源的方法。幸运的是,我在Keras中发现了这个库Keras-surgeon,它有助于修改经过训练的Keras模型。你知道吗
我正在尝试删除我的Conv-Net层之一中的频道(并将在其他层上继续)。尽管文档非常简单明了,使用过它的人也称赞它,但当我尝试使用它时,它会返回一个奇怪的类型错误:
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
我到底做错什么了?
另外,有没有人能指出我可以用来运行keras模型的东西,看看它的资源消耗(内存和CPU等等)?(这将是一个很大的帮助!)
任何帮助都将不胜感激。。!你知道吗
definition of ^{} 是:
函数参数中的
*
意味着强制您显式使用命名参数。 必须按如下方式调用add_job
:相关问题 更多 >
编程相关推荐