def process_patches(images, net, transformer):
""" Process a patch through the neural network and extract the predictions
Args:
images (array list): list of images to process (length = batch_size)
net (obj): the Caffe Net
transformer (obj): the Caffe Transformer for preprocessing
"""
# caffe.io.load_image converts to [0,1], so our transformer sets it back to [0,255]
# but the skimage lib already works with [0, 255] so we convert it to float with img_as_float
data = np.zeros(net.blobs['data'].data.shape)
for i in range(len(images)):
data[i] = transformer.preprocess('data', img_as_float(images[i]))
net.forward(data=data)
output = net.blobs['conv1_1_D'].data[:len(images)]
output = np.swapaxes(np.swapaxes(output, 1, 3), 1, 2)
return output
评论列表
文章目录