SerdarHelli commited on
Commit
1f1b259
1 Parent(s): 188ff28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -11,11 +11,41 @@ os.system("git clone https://github.com/Zhengxinyang/SDF-StyleGAN.git")
11
  sys.path.append("SDF-StyleGAN")
12
 
13
  #Codes reference : https://github.com/Zhengxinyang/SDF-StyleGAN
14
-
15
- from utils.utils import noise, evaluate_in_chunks, scale_to_unit_sphere, volume_noise, process_sdf, linear_slerp
16
  from network.model import StyleGAN2_3D
17
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  cars=hf_hub_download("SerdarHelli/SDF-StyleGAN-3D", filename="cars.ckpt",revision="main")
20
 
21
 
@@ -25,7 +55,7 @@ device='cuda' if torch.cuda.is_available() else 'cpu'
25
  if device=="cuda":
26
  model = StyleGAN2_3D.load_from_checkpoint(cars).cuda(0)
27
  else:
28
- model = StyleGAN2_3D.load_from_checkpoint(cars)
29
  model.eval()
30
 
31
 
@@ -46,9 +76,9 @@ def seed_all(seed):
46
 
47
  def change_model(ckpt_path):
48
  if device=="cuda":
49
- model = StyleGAN2_3D.load_from_checkpoint(cars).cuda(0)
50
  else:
51
- model = StyleGAN2_3D.load_from_checkpoint(cars)
52
  model.eval()
53
 
54
 
 
11
  sys.path.append("SDF-StyleGAN")
12
 
13
  #Codes reference : https://github.com/Zhengxinyang/SDF-StyleGAN
14
+ from utils.utils import evaluate_in_chunks, scale_to_unit_sphere
 
15
  from network.model import StyleGAN2_3D
16
 
17
 
18
+ def noise(batch_size, latent_dim, device):
19
+
20
+ return torch.randn(batch_size, latent_dim,device=device)
21
+
22
+
23
+ def noise_list(batch_size, layers, latent_dim, device):
24
+ return [(noise(batch_size, latent_dim, device), layers)]
25
+
26
+
27
+ def volume_noise(n, vol_size, device):
28
+ if device=="cuda":
29
+ return torch.FloatTensor(n, vol_size, vol_size, vol_size, 1).uniform_(0., 1.).cuda(device)
30
+ return torch.FloatTensor(n, vol_size, vol_size, vol_size, 1).uniform_(0., 1.)
31
+
32
+ class StyleGAN2_3D_not_cuda(StyleGAN2_3D):
33
+
34
+ @torch.no_grad()
35
+ def generate_feature_volume(self, ema=False, trunc_psi=0.75):
36
+ latents = noise_list(
37
+ 1, self.num_layers, self.latent_dim, device=self.device)
38
+ n = volume_noise(1, self.G_vol_size, device=self.device)
39
+ if ema:
40
+ generate_voxels = self.generate_truncated(
41
+ self.SE, self.GE, latents, n, trunc_psi)
42
+ else:
43
+ generate_voxels = self.generate_truncated(
44
+ self.S, self.G, latents, n, trunc_psi)
45
+
46
+ return generate_voxels
47
+
48
+
49
  cars=hf_hub_download("SerdarHelli/SDF-StyleGAN-3D", filename="cars.ckpt",revision="main")
50
 
51
 
 
55
  if device=="cuda":
56
  model = StyleGAN2_3D.load_from_checkpoint(cars).cuda(0)
57
  else:
58
+ model = StyleGAN2_3D_not_cuda.load_from_checkpoint(cars)
59
  model.eval()
60
 
61
 
 
76
 
77
  def change_model(ckpt_path):
78
  if device=="cuda":
79
+ model = StyleGAN2_3D.load_from_checkpoint(ckpt_path).cuda(0)
80
  else:
81
+ model = StyleGAN2_3D_not_cuda.load_from_checkpoint(ckpt_path)
82
  model.eval()
83
 
84