worker.py 文件源码

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

项目:Cuppa 作者: flipkart-incubator 项目源码 文件源码
def __caffe_predict(self, net, height, width, url):
        # logger = logging.getLogger(__name__)
        #
        # logger.info("caffe_predict has been called")

        input_layer = net.inputs[0]
        output_layer = net.outputs[0]
        r = requests.get(url, allow_redirects=False)
        arr = numpy.asarray(bytearray(r.content), dtype=numpy.uint8)
        img = cv2.imdecode(arr, -1)
        resized_img = imresize(img, (height,width), 'bilinear')
        transposed_resized_img = numpy.transpose(resized_img, (2,0,1))
        reqd_shape = (1,) + transposed_resized_img.shape
        #net.blobs["data_q"].reshape(*reqd_shape)
        #net.blobs["data_q"].data[...] = transposed_resized_img
        net.blobs[input_layer].reshape(*reqd_shape)
        net.blobs[input_layer].data[...] = transposed_resized_img
        net.forward()
        #result = net.blobs['latent_q_encode'].data[0].tolist()
        result = net.blobs[output_layer].data[0].tolist()
        return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号