I am very afraid to rebuild the code, since installing caffe did not become easy for me. But to fix the resizing solution requires in_shape (user8264 response), which is installed inside caffe / classifier.py
Anyway, I debugged and found the value for in_shape = (3, 227, 227) for age_net.caffemodel
Thus, the model used to predict age and gender will have the following change:
age_net_pretrained='./age_net.caffemodel' age_net_model_file='./deploy_age.prototxt' age_net = caffe.Classifier(age_net_model_file, age_net_pretrained, mean=mean, channel_swap=(2,1,0), raw_scale=255, image_dims=(227, 227))
But first you need to change the value:
m_min, m_max = mean.min(), mean.max() normal_mean = (mean - m_min) / (m_max - m_min) in_shape=(227, 227) mean = caffe.io.resize_image(normal_mean.transpose((1,2,0)),in_shape) .transpose((2,0,1)) * (m_max - m_min) + m_min
This will get rid of "ValueError: middle form incompatible with the input form." But I'm not sure about the accuracy. Apparently, for me, skipping the middle parameter gave a better prediction of age :)