i have reference model which is evaluated using pretrained model,i have weights,bias and input to the function…to check individually i took single conv2d has a sequential model. and i have initialized the input,weights and bias from the text file(values obtained from the refernce model)
but the problem is output from the Conv2d is not matching with the refernce model output (which is also a Conv2d with all same attributes)
here is my code…
“”"import torch
import torch.nn as nn
import csv
import torch
import pandas as pd
import math
import numpy
class PrintLayer(nn.Module):
def init(self):
super(PrintLayer, self).init()
selfconv = nn.Sequential(
nn.Conv2d(96, 256, kernel_size=5, stride=1, padding=2)
)
    a_file1 = open("2nd layer weight.txt","r")
    list_of_lists1 = []
    for line in a_file1:
      stripped_line1 = line.strip()
      line_list1 = stripped_line1.split()
      list_of_lists1.extend(line_list1)
    a_file1.close()

    b = torch.from_numpy(numpy.array(list_of_lists1,dtype= 'float32'))
    w = torch.tensor(b)
    ten = w.reshape(256,96,5,5)
    selfconv[0].weight.data = ten

    a_file12 = open("bias.txt","r")
    list_of_lists12 = []
    for line in a_file12:
      stripped_line12 = line.strip()
      line_list12 = stripped_line12.split()
      list_of_lists12.extend(line_list12)
    a_file12.close()

    c = torch.from_numpy(numpy.array(list_of_lists12,dtype= 'float32'))
    d = torch.tensor(c)
    ten1 = d.reshape(256)
    print(ten1.size())
    selfconv[0].bias.data = ten1
    

    #print(selfconv[0].weight)
    #print(selfconv[0].weight.data)
    #m.weight.data = m.weight.data.fill(m.weight.data)
    
    
    
def forward(self, x):
    # Do your print / debug stuff here
    #print("x is",x)
    return x

selfconv = nn.Sequential(
nn.Conv2d(96, 256, kernel_size=5, stride=1, padding=2),
PrintLayer()
)
a_file = open(“input_27_27_96.txt”,“r”)
list_of_lists = []
for line in a_file:
stripped_line = line.strip()
line_list = stripped_line.split()
list_of_lists.extend(line_list)
a_file.close()
#print(len(list_of_lists))
b = torch.from_numpy(numpy.array(list_of_lists,dtype= ‘float32’))
x = torch.tensor(b)
x = x.reshape(1,96,27,27)
x =x.double()
#print(x.size())
#print(x.size())
state_dict = selfconv.state_dict()
output = selfconv(x.float())
#print(output.size())
#print(output)
#print(selfconv.state_dict())
#print(list(selfconv.named_parameters()))
print((selfconv[0].weight == state_dict[‘0.weight’]).all())
print((selfconv[0].bias == state_dict[‘0.bias’]).all())
print(list(selfconv.named_parameters()))"""
@ptrblck can you please provide the solution for it…i am very new to python and pytorch