MCPcopy Index your code
hub / github.com/OpenGVLab/DragGAN / prepare

Method prepare

draggan/deprecated/api.py:13–62  ·  view source on GitHub ↗
(
        self,
        styles,
        inject_index=None,
        truncation=1,
        truncation_latent=None,
        input_is_latent=False,
        noise=None,
        randomize_noise=True,
    )

Source from the content-addressed store, hash-verified

11
12class CustomGenerator(Generator):
13 def prepare(
14 self,
15 styles,
16 inject_index=None,
17 truncation=1,
18 truncation_latent=None,
19 input_is_latent=False,
20 noise=None,
21 randomize_noise=True,
22 ):
23 if not input_is_latent:
24 styles = [self.style(s) for s in styles]
25
26 if noise is None:
27 if randomize_noise:
28 noise = [None] * self.num_layers
29 else:
30 noise = [
31 getattr(self.noises, f"noise_{i}") for i in range(self.num_layers)
32 ]
33
34 if truncation < 1:
35 style_t = []
36
37 for style in styles:
38 style_t.append(
39 truncation_latent + truncation * (style - truncation_latent)
40 )
41
42 styles = style_t
43
44 if len(styles) < 2:
45 inject_index = self.n_latent
46
47 if styles[0].ndim < 3:
48 latent = styles[0].unsqueeze(1).repeat(1, inject_index, 1)
49
50 else:
51 latent = styles[0]
52
53 else:
54 if inject_index is None:
55 inject_index = random.randint(1, self.n_latent - 1)
56
57 latent = styles[0].unsqueeze(1).repeat(1, inject_index, 1)
58 latent2 = styles[1].unsqueeze(1).repeat(1, self.n_latent - inject_index, 1)
59
60 latent = torch.cat([latent, latent2], 1)
61
62 return latent, noise
63
64 def generate(
65 self,

Callers 4

on_change_modelFunction · 0.80
on_new_imageFunction · 0.80
mainFunction · 0.80
inverse_imageFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected