app.py 文件源码

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

项目:flask-app-for-mxnet-img-classifier 作者: XD-DENG 项目源码 文件源码
def get_image(file_location, local=False):
    # users can either 
    # [1] upload a picture (local = True)
    # or
    # [2] provide the image URL (local = False)
    if local == True:
        fname = file_location
    else:
        fname = mx.test_utils.download(file_location, dirname="static/img_pool")
    img = cv2.cvtColor(cv2.imread(fname), cv2.COLOR_BGR2RGB)

    if img is None:
         return None

    # convert into format (batch, RGB, width, height)
    img = cv2.resize(img, (224, 224))
    img = np.swapaxes(img, 0, 2)
    img = np.swapaxes(img, 1, 2)
    img = img[np.newaxis, :]

    return img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号