Thank you for your advice! I try to use the mkldnn. But I don’t know if it’s the right way to use it.
import numpy as np
import torch
from torch import nn
import time
size_list = [3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51]
h = 6115
w = 5490
pic = np.random.randint(0,2,(h,w),dtype=(np.int16))
Max_iters = 5
for kernel_size in range(3,109,2):
kernel = torch.ones((1,1,kernel_size,kernel_size))
neighbor_func = nn.Conv2d(1, 1, kernel_size,padding=int((kernel_size-1)/2),bias = False)
with torch.no_grad():
for i,j in neighbor_func.named_parameters():
j.copy_(kernel)
tst = time.time()
for i in range(Max_iters):
N = np.where(pic == 1,1,0)
N = np.reshape(N,(1,1,h,w))
N = torch.from_numpy(N).type(torch.float32).to_mkldnn()
with torch.no_grad():
N = neighbor_func(N)
N = N.detach().to_dense().numpy()
N = np.squeeze(N)
print(kernel_size,time.time()-tst)
I modify the code and can not get performance improvements.