caffe-tensorflow
caffe-tensorflow copied to clipboard
failed to convert official ResNet models
when converting models downloaded from https://github.com/KaimingHe/deep-residual-networks#models, ended up with error:
Traceback (most recent call last):
File "./convert.py", line 60, in <module>
main()
File "./convert.py", line 56, in main
args.phase)
File "./convert.py", line 27, in convert
transformer = TensorFlowTransformer(def_path, caffemodel_path, phase=phase)
File "/Users/shuang/github/caffe-tensorflow/kaffe/tensorflow/transformer.py", line 227, in __init__
self.load(def_path, data_path, phase)
File "/Users/shuang/github/caffe-tensorflow/kaffe/tensorflow/transformer.py", line 237, in load
graph = DataInjector(def_path, data_path)(graph)
File "/Users/shuang/github/caffe-tensorflow/kaffe/transformers.py", line 86, in __call__
node.data = self.adjust_parameters(node, data)
File "/Users/shuang/github/caffe-tensorflow/kaffe/transformers.py", line 79, in adjust_parameters
data[idx] = np.squeeze(data[idx])
IndexError: list index out of range
If saving only source code, ended up with error:
Traceback (most recent call last):
File "./convert.py", line 60, in <module>
main()
File "./convert.py", line 56, in main
args.phase)
File "./convert.py", line 37, in convert
src_out.write(transformer.transform_source())
File "/Users/shuang/github/caffe-tensorflow/kaffe/tensorflow/transformer.py", line 288, in transform_source
chains = mapper.map()
File "/Users/shuang/github/caffe-tensorflow/kaffe/graph.py", line 288, in map
mapped_chains.append(self.map_chain(chain))
File "/Users/shuang/github/caffe-tensorflow/kaffe/graph.py", line 292, in map_chain
return [self.map_node(node) for node in chain]
File "/Users/shuang/github/caffe-tensorflow/kaffe/graph.py", line 296, in map_node
mapped_node = map_func(node)
File "/Users/shuang/github/caffe-tensorflow/kaffe/tensorflow/transformer.py", line 155, in map_batch_norm
scale_offset = len(node.data) == 4
TypeError: object of type 'NoneType' has no len()
My fix is around line 155 of transformer.py:
if node.data:
scale_offset = len(node.data) == 4
else:
scale_offset = False
but the first error remains.
this may be related to #63
FYI, this is using protobuf backend, not caffe backend.
I have the same problem How to modify the code to solve it?
Same issues here. Anybody found a solution?
I got it to work by replacing scale_offset= len(node.data) == 4
with scale_offset = len(node.output_shape) == 4
in transformer.py
I don't know if this breaks something else, but it definitely makes the ResNet50 and ResNet101 work.
I solved this problem by installing pycaffe.
To address the first issue, try changing
squeeze_indices = [1] # Squeeze biases.
if node.kind == NodeKind.InnerProduct:
squeeze_indices.append(0) # Squeeze FC.
to
squeeze_indices = []
if node.kind == NodeKind.Convolution or node.kind == NodeKind.InnerProduct:
if node.parameters.bias_term:
squeeze_indices.append(1)
if node.kind == NodeKind.InnerProduct:
squeeze_indices.append(0) # Squeeze FC.
in transformers.py. This fixes the "index out of range" issue for convolutions without a bias term, as well as an issue where BatchNorm variance was getting squeezed incorrectly.
scale_offset = len(node.output_shape) == 4
this
I got it to work by replacing
scale_offset= len(node.data) == 4
withscale_offset = len(node.output_shape) == 4
intransformer.py
I don't know if this breaks something else, but it definitely makes the ResNet50 and ResNet101 work.
thanks, it fix the error.