MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / main

Function main

utils/create_strand_latent_weights.py:76–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74
75
76def main():
77
78 #argparse
79 parser = argparse.ArgumentParser(description='Get the weights of each dimensions after training a strand VAE')
80 parser.add_argument('--checkpoint_path', required=True, help='Path to the strandVAE checkpoint')
81 args = parser.parse_args()
82
83 path_strand_vae_model=args.checkpoint_path
84
85
86 hyperparams=HyperParamsStrandVAE()
87
88
89 normalization_dict=DiffLocksDataset.get_normalization_data()
90
91 model = StrandCodec(do_vae=False,
92 decode_type="dir",
93 scale_init=30.0,
94 nr_verts_per_strand=256, nr_values_to_decode=255,
95 dim_per_value_decoded=3).cuda()
96 model.load_state_dict(torch.load(path_strand_vae_model))
97 model = torch.compile(model)
98
99
100
101 #latent of dimension 64 and get GT which is the mean strand
102 latent=torch.zeros(1,64).cuda()
103 pred_dict = model.decoder(latent, None, normalization_dict)
104 pred_points=pred_dict["strand_positions"]
105 gt_strand=pred_points
106 print("gt_strand",gt_strand.shape)
107
108
109 #make loss function
110 loss_computer= StrandVAELoss()
111
112
113 #for each dimension change it by 0.5 and check the error towards the mean strand (GT)
114 loss_per_dim=[]
115 for i in range(64):
116 latent=torch.zeros(1,64).cuda()
117 latent[:,i]=0.8
118 pred_dict = model.decoder(latent, None, normalization_dict)
119 pred_points=pred_dict["strand_positions"]
120
121 #make dicts
122 gt_dict={"strand_positions": gt_strand}
123 pred_dict={"strand_positions": pred_points}
124 latent_dict={}
125
126 #loss
127 loss_dict = loss_computer(None, gt_dict, pred_dict, latent_dict, hyperparams)
128 loss=loss_dict["loss"]
129 loss_per_dim.append(loss)
130
131 # print("loss", loss)
132
133 #normalize losses

Callers 1

Calls 6

StrandCodecClass · 0.90
StrandVAELossClass · 0.90
load_state_dictMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected