Pretraining.py 文件源码

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

项目:Yelp_Restaurant_Photo_Classification 作者: prith189 项目源码 文件源码
def PreprocessImage(path, show_img=False,invert_img=False):
    img = io.imread(path)
    if(invert_img):
        img = np.fliplr(img)
    short_egde = min(img.shape[:2])
    yy = int((img.shape[0] - short_egde) / 2)
    xx = int((img.shape[1] - short_egde) / 2)
    crop_img = img[yy : yy + short_egde, xx : xx + short_egde]
    # resize to 224, 224
    resized_img = transform.resize(crop_img, (299, 299))
    if show_img:
        io.imshow(resized_img)
    # convert to numpy.ndarray
    sample = np.asarray(resized_img) * 256
    # swap axes to make image from (299, 299, 3) to (3, 299, 299)
    sample = np.swapaxes(sample, 0, 2)
    sample = np.swapaxes(sample, 1, 2)
    # sub mean 
    normed_img = sample - 128
    normed_img /= 128.
    return np.reshape(normed_img,(1,3,299,299))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号