PyTorch按类别绘制潜在变化图
我相信这已经被问了很多次了,但我正在试图找出我的代码有什么问题。我只是试着对一行类中潜在变化的列的图像进行采样PyTorch按类别绘制潜在变化图,pytorch,Pytorch,我相信这已经被问了很多次了,但我正在试图找出我的代码有什么问题。我只是试着对一行类中潜在变化的列的图像进行采样 def sample(self, n): l_dim = int(math.sqrt(n)) sample = [] labels = torch.randint(0, self.num_classes, (l_dim,)) for i in range(l_dim): label = labels
def sample(self, n):
l_dim = int(math.sqrt(n))
sample = []
labels = torch.randint(0, self.num_classes, (l_dim,))
for i in range(l_dim):
label = labels[i].repeat(l_dim)
one_hot = F.one_hot(label, num_classes=self.num_classes)
sample_z = torch.randn(l_dim, self.z_dim)
sample_i = torch.cat((sample_z, one_hot), dim=1)
sample.append(sample_i)
s = torch.cat(sample, 0).to(self.device)
return self.decode(s)
这样,我似乎在所有列中都得到了相同的图像——我确实得到了不同类的行。我错过了什么?(我完全承认和PyTorch在一起不是很舒服!)