def __init__(self, nn='v1', name='ssvae', gen_weight=1, class_weight=100): super().__init__() self.name = name self.z_dim = 64 self.y_dim = 10 self.gen_weight = gen_weight self.class_weight = class_weight nn = getattr(nns, nn) self.enc = nn.Encoder(self.z_dim, self.y_dim) self.dec = nn.Decoder(self.z_dim, self.y_dim) self.cls = nn.Classifier(self.y_dim) # Set prior as fixed parameter attached to Module self.z_prior_m = torch.nn.Parameter(torch.zeros(1), requires_grad=False) self.z_prior_v = torch.nn.Parameter(torch.ones(1), requires_grad=False) self.z_prior = (self.z_prior_m, self.z_prior_v)
def __init__(self, nn='v1', name='ssvae', rec_weight=1, kl_xy_x_weight=10, kl_xy_y_weight=10, gen_weight=1, class_weight=100, CNN=False): super().__init__() self.name = name self.CNN = CNN self.x_dim = 784 self.z_dim = 64 self.y_dim = 10 self.rec_weight = rec_weight self.kl_xy_x_weight = kl_xy_x_weight self.kl_xy_y_weight = kl_xy_y_weight self.gen_weight = gen_weight self.class_weight = class_weight nn = getattr(nns, nn) if CNN: self.enc_xy = nn.Encoder_XY(z_dim=self.z_dim, y_dim=self.y_dim) self.enc_x = nn.Encoder_X(z_dim=self.z_dim) self.enc_y = nn.Encoder_Y(z_dim=self.z_dim, y_dim=self.y_dim) else: self.enc_xy = nn.Encoder(z_dim=self.z_dim, y_dim=self.y_dim, x_dim=self.x_dim) self.enc_x = nn.Encoder(z_dim=self.z_dim, y_dim=0, x_dim=self.x_dim) self.enc_y = nn.Encoder(z_dim=self.z_dim, y_dim=self.y_dim, x_dim=0) self.dec = nn.Decoder(z_dim=self.z_dim, y_dim=0, x_dim=self.x_dim) self.cls = nn.Classifier(y_dim=self.y_dim, input_dim=self.z_dim * 2)