How to obtain convolutional kernel array of conv? What is the difference between nn.conv2d and layers.conv2d?

I’m trying to imitate a python project with Tensorflow, but the results have always been completely different, almost to a different extent. I suspect it is due to different convolution cores. I want to check the specific content of Tensorflow’s convolution cores. What method should I use? The method of torch viewing is conv.weight.data. What about tensorflow?

This a straightforward implementation of this kind of keras-like (?) convolution. It might be hard to understand for beginners because it uses a lot of broadcasting and stride tricks.

from numpy.lib.stride_tricks import as_strided
def conv2d(a, b):
    a = as_strided(a,(len(a),a.shape[1]-len(b)+1,a.shape[2]-b.shape[1]+1,len(b),b.shape[1],a.shape[3]),a.strides[:3]+a.strides[1:])
    return np.einsum('abcijk,ijkd', a, b[::-1,::-1])