inference_patches.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:DeepNet 作者: hok205 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号