Skip to content

How to get the output of the middle layer in the process of model training #2368

Answered by xiaohoua
xiaohoua asked this question in Q&A
Discussion options

You must be logged in to vote

Here's how to use hook to solve my problem for future reference,In this case I don't need to modify the open_clip library source code。

for epoch in range(start_epoch, args.num_epochs):
        epoch_loss = 0.
        hook_handle, activations = get_activation('atten_layer_8')
        hook = teacher_model.visual.transformer.resblocks[8].register_forward_hook(hook_handle)
        for image, categories, embedding in tqdm.tqdm(iter(data_loader)):
            image = image.to(args.device, non_blocking=True)
            embedding = embedding.to(args.device, non_blocking=True)
            category = F.one_hot(categories, num_classes=397).float().to(args.device, non_blocking=True)
            ....…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rwightman
Comment options

@xiaohoua
Comment options

@xiaohoua
Comment options

Answer selected by xiaohoua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants