caffe的pycaffe.py文件中有这样一段代码:
if kwargs:
if set(kwargs.keys()) != set(self.outputs):
raise Exception('Top diff arguments do not match net outputs.')
# Set top diffs according to defined shapes and make arrays single and
# C-contiguous as Caffe expects.
for top, diff in six.iteritems(kwargs):
if diff.shape[0] != self.blobs[top].shape[0]:
raise Exception('Diff is not batch sized')
self.blobs[top].diff[...] = diff
self._backward(start_ind, end_ind)
其中有一个错误声明:'Top diff arguments do not match net outputs.'
当运行代码出现这一错误时,大多数情况是因为定义caffe中prototxt文件对某一层的命名,不同于代码中对某一层的命名。
可以在错误声明之前加入两行代码:
a = set(kwargs.keys())
b = set(self.outputs)
看看kwargs字典的键值和self.outputs的命名是否相同,如不同,则修改prototxt文件中或代码中对某一层的命名,使其相同即可。