测试图片

图片的大小为 94KB,分辨率为 959x959

from PIL import Image
import numpy as np
import os
import time
from torchvision import transforms


preprocess = transforms.Compose([
    transforms.Resize(224),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406],
                         std=[0.229, 0.224, 0.225])
])

img_path = 'resources/images/std.jpg'  # 图片文件夹路径


_image = np.array(Image.open(img_path))


s = time.time()
for _ in range(10000):
    image = Image.fromarray(_image)
    preprocess(image)
e = time.time()

print(e-s)

耗时 62.5 秒

  • transforms.Resize(224),
  • transforms.CenterCrop(224),
  • transforms.ToTensor(),
  • transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])

其中 resize 耗时 48 秒

resize + CenterCrop 耗时 48 秒

resize + CenterCrop + ToTensor 耗时 58 秒



universe_king
3.4k 声望680 粉丝