Thank you very much. I finally get what I want!!
I avoid this problem by using  dict  as you told me to replace the outputs.
model_ft = models.resnet18(pretrained=True)

feature_out = {}
layers_name = list(model_ft._modules.keys())
layers = list(model_ft._modules.values())


def hook_fn_forward(module, input, output):
    layer = layers_name[np.argwhere([module == m for m in layers])[0, 0]]
    total_feat_out[layer] = output
    

modules = model_ft.named_children()
for name, module in modules:
    module.register_forward_hook(hook_fn_forward)

model_ft.eval() 
with torch.no_grad():
    pred = model_ft(dat)