首页 > 解决方案 > Torch Tensorboard 图不反映代码

问题描述

我构建了一个由 VGG + 线性层的简单组合组成的视频编码器

vgg16 = tv.models.vgg16(pretrained=True)
vgg16.classifier = torch.nn.Sequential(*[l for l in vgg16.classifier[:5]])

for l in vgg16.features:
  for p in l.parameters():
    p.requires_grad = False

for l in vgg16.classifier[:-2]:
  for p in l.parameters():
    p.requires_grad = False


class Encoder(torch.nn.Module):
  def __init__(self, emb_dimension):
    super(Encoder, self).__init__()

    self.vgg16 = vgg16
    self.encoder = torch.nn.Sequential(
        torch.nn.Linear(4096, emb_dimension),
        # torch.nn.ReLU()
    )

  def forward(self, x):

    batch_size, time_steps, *dims = x.shape
    x = x.view(batch_size * time_steps, *dims)
    x = vgg16(x)
    x = x.view(batch_size, time_steps, -1)
    x = self.encoder(x)

    return x

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

encoder = Encoder(30)
encoder.to(device)
writer.add_graph(encoder, torch.rand(1,5,3,100,100).to(device))

我不明白为什么 tensorBoard 图显示 20 个从顺序层返回到 VGG 的张量。恐怕它可能会影响梯度计算。 在此处输入图像描述 有人有什么想法吗?

标签: graphdeep-learningpytorchtensortensorboard

解决方案


推荐阅读