Spaces:
Runtime error
Runtime error
SerdarHelli
commited on
Commit
•
cc96327
1
Parent(s):
e7df148
Update app.py
Browse files
app.py
CHANGED
@@ -21,9 +21,9 @@ sys.path.append("stylegan3")
|
|
21 |
|
22 |
|
23 |
|
24 |
-
DESCRIPTION = f''
|
25 |
![Example]("https://huggingface.co/spaces/SerdarHelli/Brain-MR-Image-Generation-GAN/blob/main/ex.png")
|
26 |
-
''
|
27 |
|
28 |
def make_transform(translate: Tuple[float,float], angle: float):
|
29 |
m = np.eye(3)
|
@@ -46,7 +46,7 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
46 |
G.eval()
|
47 |
G.to(device)
|
48 |
|
49 |
-
def predict(Seed,noise_mode,truncation_psi
|
50 |
|
51 |
# Generate images.
|
52 |
z = torch.from_numpy(np.random.RandomState(Seed).randn(1, G.z_dim)).to(device)
|
@@ -55,10 +55,7 @@ def predict(Seed,noise_mode,truncation_psi,trans_x,trans_y,angle):
|
|
55 |
# generator expects this matrix as an inverse to avoid potentially failing numerical
|
56 |
# operations in the network.
|
57 |
|
58 |
-
|
59 |
-
m = make_transform((trans_x,trans_y), angle)
|
60 |
-
m = np.linalg.inv(m)
|
61 |
-
G.synthesis.input.transform.copy_(torch.from_numpy(m))
|
62 |
|
63 |
img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
|
64 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
@@ -73,9 +70,6 @@ interface=gr.Interface(fn=predict, title="Brain MR Image Generation with StyleGA
|
|
73 |
article = "Author: S.Serdar Helli",
|
74 |
inputs=[gr.inputs.Slider( minimum=0, maximum=2**12,label='Seed'),gr.inputs.Radio( choices=noises, default='const',label='Noise Mods'),
|
75 |
gr.inputs.Slider(0, 2, step=0.05, default=1, label='Truncation psi'),
|
76 |
-
gr.inputs.Slider(-1, 1, step=0.05, default=0, label='Translate X'),
|
77 |
-
gr.inputs.Slider(-1, 1, step=0.05, default=0, label='Translate Y'),
|
78 |
-
gr.inputs.Slider(-180, 180, step=5, default=0, label='Angle'),],
|
79 |
outputs=gr.outputs.Image( type="numpy", label="Output"))
|
80 |
|
81 |
|
|
|
21 |
|
22 |
|
23 |
|
24 |
+
DESCRIPTION = f''This model generates healthy MR Brain Images.
|
25 |
![Example]("https://huggingface.co/spaces/SerdarHelli/Brain-MR-Image-Generation-GAN/blob/main/ex.png")
|
26 |
+
''
|
27 |
|
28 |
def make_transform(translate: Tuple[float,float], angle: float):
|
29 |
m = np.eye(3)
|
|
|
46 |
G.eval()
|
47 |
G.to(device)
|
48 |
|
49 |
+
def predict(Seed,noise_mode,truncation_psi):
|
50 |
|
51 |
# Generate images.
|
52 |
z = torch.from_numpy(np.random.RandomState(Seed).randn(1, G.z_dim)).to(device)
|
|
|
55 |
# generator expects this matrix as an inverse to avoid potentially failing numerical
|
56 |
# operations in the network.
|
57 |
|
58 |
+
|
|
|
|
|
|
|
59 |
|
60 |
img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
|
61 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
|
|
70 |
article = "Author: S.Serdar Helli",
|
71 |
inputs=[gr.inputs.Slider( minimum=0, maximum=2**12,label='Seed'),gr.inputs.Radio( choices=noises, default='const',label='Noise Mods'),
|
72 |
gr.inputs.Slider(0, 2, step=0.05, default=1, label='Truncation psi'),
|
|
|
|
|
|
|
73 |
outputs=gr.outputs.Image( type="numpy", label="Output"))
|
74 |
|
75 |
|