I am trying to return only the center crop with the oversample of Caffe using Python code the caffe.io.oversample function (not the classifier.py). II have tried to modify the code to return only the center crop however it still returns 10 instead of 1 crops. I have rebuilt the caffe and pycaffe however the situation is still the same. How can I get the python code to return only one crop?? I am confused. I have used matcaffe before but I don't know python, I am just figuring out as I go. Thanks!
Modified part:
def oversample(images, crop_dims, flow=False):
"""
Crop images into the four corners, center, and their mirrored versions.
Take
image: iterable of (H x W x K) ndarrays
crop_dims: (height, width) tuple for the crops.
Give
crops: (10*N x H x W x K) ndarray of crops for number of inputs N.
"""
# Dimensions and center.
im_shape = np.array(images[0].shape)
crop_dims = np.array(crop_dims)
center = im_shape[:2] / 2.0
# Make crop coordinates
# Take center crop.
crop = np.tile(center, (1, 2))[0] + np.concatenate([
-self.crop_dims / 2.0,
self.crop_dims / 2.0
])
crops = images[:, crop[0]:crop[2], crop[1]:crop[3], :]
return crops
Its original:
def oversample(images, crop_dims, flow=False):
"""
Crop images into the four corners, center, and their mirrored versions.
Take
image: iterable of (H x W x K) ndarrays
crop_dims: (height, width) tuple for the crops.
Give
crops: (10*N x H x W x K) ndarray of crops for number of inputs N.
"""
# Dimensions and center.
im_shape = np.array(images[0].shape)
crop_dims = np.array(crop_dims)
im_center = im_shape[:2] / 2.0
# Make crop coordinates
h_indices = (0, im_shape[0] - crop_dims[0])
w_indices = (0, im_shape[1] - crop_dims[1])
crops_ix = np.empty((5, 4), dtype=int)
curr = 0
for i in h_indices:
for j in w_indices:
crops_ix[curr] = (i, j, i + crop_dims[0], j + crop_dims[1])
curr += 1
crops_ix[4] = np.tile(im_center, (1, 2)) + np.concatenate([
-crop_dims / 2.0,
crop_dims / 2.0
])
crops_ix = np.tile(crops_ix, (2, 1))
# Extract crops
crops = np.empty((10 * len(images), crop_dims[0], crop_dims[1],
im_shape[-1]), dtype=np.float32)
ix = 0
for im in images:
for crop in crops_ix:
crops[ix] = im[crop[0]:crop[2], crop[1]:crop[3], :]
ix += 1
crops[ix-5:ix] = crops[ix-5:ix, :, ::-1, :] # flip for mirrors
if flow: #if using a flow input, should flip first channel which corresponds to x-flow
crops[ix-5:ix,:,:,0] = 1-crops[ix-5:ix,:,:,0]
return crops