i have Conv2d as sequential model,i am passing the multidim tensor as an input from the txt file,how do i initialize the Conv2d weight from the text file which is also an multidimension tensor
here is my code:
import torch
import torch.nn as nn
import csv
import torch
import pandas as pd
import math
class PrintLayer(nn.Module):
def init(self):
super(PrintLayer, self).init()
self.conv = nn.Conv2d(1, 1, 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()
print(len(list_of_lists1))
b = torch.from_numpy(numpy.array(list_of_lists1,dtype= ‘float32’))
w = torch.tensor(b)
ten = w.reshape(256,96,5,5)
model[0].weight.data = ten
#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

model = nn.Sequential(
nn.Conv2d(96, 256, kernel_size=5, stride=1, padding=2),
PrintLayer(),
# Add Print layer for debug
)
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())
output = model(x.float())
print(model.state_dict())
#print(list(model.named_parameters()))