测试代码参考自
共测试三个项目,numpy矩阵乘法,numpy矩阵resize和numpy跑图像滤波
测试代码如下,欢迎补充其他cpu成绩或指出测试不当的点
更多是为了满足自己好奇心hhh
import numpy as np
from time import time
d = 100 #矩阵尺寸
times = 5
a = np.random.rand(d,d,d)
b = np.random.rand(d,d,d)
start = time()
for i in range (times):
c = np.dot(a,b)
end = time()
print('running time is :%f'%(end/times-start/times))
print(np.__config__.show())
# 版权声明:本文为CSDN博主「weixin_39827506」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
# 原文链接:https://blog.csdn.net/weixin_39827506/article/details/111435520
import numpy as np
from time import time
times = 10
a = np.random.rand(100000000)
start = time()
for t in range(times):
for i in range(100):
b = np.resize(a,(1000,200,500))
end = time()
print('running time is :%f'%(end/times-start/times))
print(np.__config__.show())
# 版权声明:本文为CSDN博主「weixin_39827506」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
# 原文链接:https://blog.csdn.net/weixin_39827506/article/details/111435520
import numpy as np
import cv2
from time import time
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.2989, 0.5870, 0.1140])
def myImageFilter(img_in, h):
img_w = img_in.shape[0]
img_h = img_in.shape[1]
padding_width = int((h.shape[0] - 1) / 2)
padding_height = int((h.shape[1] - 1) / 2) #求padding步长
new_image = np.zeros([img_w + 2 * padding_width, img_h + 2 * padding_height])
new_image[padding_width : (img_w + padding_width), padding_height : (img_h + padding_height)] = img_in #创建一个新的temp图像,边框置0,中心为原图
res = np.zeros([img_w, img_h]) #结果图像
h = np.fliplr(np.flipud(h))
for i in range(padding_width, img_w + padding_width): #使用最普通的均值滤波
for j in range(padding_height, img_h + padding_height):
res[i - padding_width, j - padding_height] = np.sum(np.multiply(
new_image[i - padding_width:i + padding_width + 1, j - padding_height:j + padding_height + 1], h))/(len(h)**2)
return res
if __name__ == '__main__': # 主函数s
image_path = "test.jpg"
img = cv2.imread(image_path)
gray = rgb2gray(img)
h = np.ones((3, 3)) #卷积核
strat = time()
new_image = myImageFilter(gray, h)
end = time()
print("filter cost time:",(end - strat))
print(np.__config__.show())
附一个自己的b站视频 ,会有比较详细的测试过程图和视频AMD,Intel,Windows,openblas,mkl究竟谁会负优化numpy呢? (实测多款处理器多个环境但不好给结论)_哔哩哔哩_bilibili
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)