共计 464 个字符,预计需要花费 2 分钟才能阅读完成。
测试图片
图片的大小为 94KB,分辨率为 959×959
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)
正文完