I haven’t tested this, but this is the general idea.
import torch.nn as nn
import torchvision.models as model_zoo

class Net(nn.Module):
  def __init__(self):
    super(Net, self).__init__()
    self.dnet = model_zoo.densenet121(pretrained=True)
  def forward(self, input):
    dblock_outs = []
    x = input
    for name, module in self.dnet["features"].named_children():
      if "denseblock" in name:
        x = module(x)
        dblock_outs.append(x)
      else:
        x = module(x)
    x = self.dnet["classifier"](x)
    return x, dblock_outs

model = Net()
out, dblock_outs_for_classifiers = model(minibatch)