我正在尝试使用this类来构建res网。
运行resnet.py时,main函数运行,我得到预期的结果。主要功能如下:
def main():
model = ResNetBuilder.build_resnet_18((3, 224, 224), 1000)
model.compile(loss="categorical_crossentropy", optimizer="sgd")
model.summary()
if __name__ == '__main__':
main()
导入函数时,我收到运行时错误。最小的例子:
from resnet import ResNetBuilder
from keras import backend as K
K.set_image_dim_ordering('th')
model = ResNetBuilder.build_resnet_18((3, 224, 224), 1000)
model.compile(loss="categorical_crossentropy", optimizer="sgd")
model.summary()
错误是关于图层大小或除以零的运行时错误 - 我觉得我必须做一些非常愚蠢的导入方式,但却看不到它。?
输出:
Using Theano backend.
Using gpu device 0: GeForce GTX 750 Ti (CNMeM is disabled, cuDNN 5105)
/......./site-packages/keras/backend/theano_backend.py:1500: UserWarning: DEPRECATION: the 'ds' parameter is not going to exist anymore as it is going to be replaced by the parameter 'ws'.
mode='max')
/......./site-packages/keras/backend/theano_backend.py:1500: UserWarning: DEPRECATION: the 'st' parameter is not going to exist anymore as it is going to be replaced by the parameter 'stride'.
mode='max')
/......./site-packages/keras/backend/theano_backend.py:1500: UserWarning: DEPRECATION: the 'padding' parameter is not going to exist anymore as it is going to be replaced by the parameter 'pad'.
mode='max')
Traceback (most recent call last):
File "testResnet.py", line 6, in <module>
model = ResNetBuilder.build_resnet_18((3, 224, 224), 1000)
File "........resnet.py", line 154, in build_resnet_18
return ResNetBuilder.build(input_shape, num_outputs, basic_block, [2, 2, 2, 2])
File "........resnet.py", line 139, in build
block = _residual_block(block_fn, nb_filters=nb_filters, repetitions=r, is_first_layer=i == 0)(block)
File "........resnet.py", line 77, in f
input = block_function(nb_filters=nb_filters, init_subsample=init_subsample)(input)
File "........resnet.py", line 90, in f
return _shortcut(input, residual)
File "........resnet.py", line 65, in _shortcut
init="he_normal", border_mode="valid")(input)
File "/......./site-packages/keras/engine/topology.py", line 514, in __call__
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/......./site-packages/keras/engine/topology.py", line 572, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/......./site-packages/keras/engine/topology.py", line 152, in create_node
output_shapes = to_list(outbound_layer.get_output_shape_for(input_shapes[0]))
File "/......./site-packages/keras/layers/convolutional.py", line 451, in get_output_shape_for
self.border_mode, self.subsample[0])
File "/......./site-packages/keras/utils/np_utils.py", line 131, in conv_output_length
return (output_length + stride - 1) // stride
ZeroDivisionError: integer division or modulo by zero