From 83f5482cb69d02aee9f7a2b9ff5859aff6282307 Mon Sep 17 00:00:00 2001 From: Geunsik Lim Date: Thu, 29 Jun 2017 13:12:53 +0900 Subject: [PATCH] Fix: mean shape in compatible with input shape This commit is to fix issue #5718. * reference: 1. https://groups.google.com/forum/#!topic/caffe-users/nBpWJCcJoCU 2. https://stackoverflow.com/questions/28692209/using-gpu-despite-setting-cpu-only-yielding-unexpected-keyword-argument Signed-off-by: Geunsik Lim --- python/caffe/io.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/caffe/io.py b/python/caffe/io.py index 966c164cffd..aace7c8c0f3 100644 --- a/python/caffe/io.py +++ b/python/caffe/io.py @@ -256,7 +256,13 @@ def set_mean(self, in_, mean): if len(ms) != 3: raise ValueError('Mean shape invalid') if ms != self.inputs[in_][1:]: - raise ValueError('Mean shape incompatible with input shape.') + print(self.inputs[in_]) + in_shape = self.inputs[in_][1:] + m_min, m_max = mean.min(), mean.max() + normal_mean = (mean - m_min) / (m_max - m_min) + mean = resize_image(normal_mean.transpose((1,2,0)), + in_shape[1:]).transpose((2,0,1)) * \ + (m_max - m_min) + m_min self.mean[in_] = mean def set_input_scale(self, in_, scale):