Skip to content

Commit 613e13b

Browse files
authored
Merge pull request #5719 from leemgs/upstream-issue5718
Fix: mean shape incompatible with input shape
2 parents be6a5c4 + bfc638d commit 613e13b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python/caffe/io.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ def set_mean(self, in_, mean):
256256
if len(ms) != 3:
257257
raise ValueError('Mean shape invalid')
258258
if ms != self.inputs[in_][1:]:
259-
raise ValueError('Mean shape incompatible with input shape.')
259+
in_shape = self.inputs[in_][1:]
260+
m_min, m_max = mean.min(), mean.max()
261+
normal_mean = (mean - m_min) / (m_max - m_min)
262+
mean = resize_image(normal_mean.transpose((1,2,0)),
263+
in_shape[1:]).transpose((2,0,1)) * \
264+
(m_max - m_min) + m_min
260265
self.mean[in_] = mean
261266

262267
def set_input_scale(self, in_, scale):

0 commit comments

Comments
 (0)