I used forward_hook this function, it seems only print input and output, if I want to call the input and output data with variables that should I do? I tried to return input in the printnorm function, but failed.
yes,I want to fetch the input and output of each layer, I try to use the global variable in the fun function to fetch, but the fetched variable can not be changed to numpy, suggesting that ‘tuple’ object has no attribute ‘numpy’ In the following code
def fun(self,input,output):
print('Inside '+ self.__class__.__name__ +'forward')
print('')
#print('input: ',input)
global xg
xg=input
model.conv2.register_forward_hook(fun)
out = model(input)
xi=xg
xi=xi.numpy()
so,If hook can not solve my problem, there are other ways to solve my problem?
forward can fetch the input and output of each layer? thank you very much
Thank you for your reply.I solved the above problem! I also have a question that I wish you can help me.
I have seen this Questions about ImageFolder about imagefolder. But I’m not really understand.
I have a picture datasets. Divided into trian and val two files Folder. Each folder has 0 and 1 subfolders.
I also create lables.txt about train and val. How do I load this dataset into pytorch?
dataset only return one sample at a time, you need loader to cat them into a batch. also dataloader can utilize multiprocessing to speed up the program.