python - getting ValueError: operands could not be broadcast together with shapes (3,224,224) (3,) when trying to subtract from channel wise mean in Caffe -
this follow-up question this. want subtract each image mean. based on issue on github , this other similar question, , this classification example when feed cropped version of images network, need subtract mean pixel using sth :
mu = mean_file.mean(1).mean(1)
but irony when want this:
.. = (img[:,0:224,0:224] - mu)
i valueerror: operands not broadcast shapes (3,224,224) (3,)
i'm not well-versed @ python
, numpy
, can't figure out error message trying convey, appreciated.
currently, i'm cropping mean file! not ideal! better nothing!
.. = (img[:,0:224,0:224] - mean_image[:,0:224,0:224])
replace
mu = mean_file.mean(1).mean(1)
with
mu = mean_file.mean(1).mean(1)[:,none,none]
it seems trying subtract 1d vector (shape
of (3,)
) 3d array (shape
of (3,224,224)
). in order numpy needs broadcast 1d vector dimensions of 3d array (much matlab's bsxfun). numpy understand dimensions broadcast, 1 needs add singleton dimensions 1d vector:
mu[:,none,none]
is of shape (3,1,1)
, should enable numpy perform subtraction correctly.
Comments
Post a Comment