PrakhAI commited on
Commit
0053124
·
1 Parent(s): c84c172

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -35
app.py CHANGED
@@ -8,46 +8,15 @@ from huggingface_hub import HfFileSystem
8
  from flax.serialization import msgpack_restore, from_state_dict
9
  import time
10
  from local_response_norm import LocalResponseNorm
 
11
 
12
  LATENT_DIM = 100
13
 
14
- class Generator(nn.Module):
15
- @nn.compact
16
- def __call__(self, latent, training=True):
17
- x = nn.Dense(features=32)(latent)
18
- # x = nn.BatchNorm(not training)(x)
19
- x = nn.relu(x)
20
- x = nn.Dense(features=2*2*256)(x)
21
- x = nn.BatchNorm(not training)(x)
22
- x = nn.relu(x)
23
- x = nn.Dropout(0.5, deterministic=not training)(x)
24
- x = x.reshape((x.shape[0], 2, 2, -1))
25
- x4o = nn.ConvTranspose(features=3, kernel_size=(2, 2), strides=(2, 2))(x)
26
- x4 = nn.ConvTranspose(features=128, kernel_size=(2, 2), strides=(2, 2))(x)
27
- x4 = LocalResponseNorm()(x4)
28
- # x4 = nn.BatchNorm(not training)(x4)
29
- x8 = nn.relu(x4)
30
- # x8 = nn.Dropout(0.5, deterministic=not training)(x8)
31
- x8o = nn.ConvTranspose(features=3, kernel_size=(2, 2), strides=(2, 2))(x8)
32
- x8 = nn.ConvTranspose(features=64, kernel_size=(2, 2), strides=(2, 2))(x8)
33
- x8 = LocalResponseNorm()(x8)
34
- # x8 = nn.BatchNorm(not training)(x8)
35
- x16 = nn.relu(x8)
36
- # x16 = nn.Dropout(0.5, deterministic=not training)(x16)
37
- x16o = nn.ConvTranspose(features=3, kernel_size=(2, 2), strides=(2, 2))(x16)
38
- x16 = nn.ConvTranspose(features=32, kernel_size=(2, 2), strides=(2, 2))(x16)
39
- x16 = LocalResponseNorm()(x16)
40
- # x16 = nn.BatchNorm(not training)(x16)
41
- x32 = nn.relu(x16)
42
- # x32 = nn.Dropout(0.5, deterministic=not training)(x32)
43
- x32o = nn.ConvTranspose(features=3, kernel_size=(2, 2), strides=(2, 2))(x32)
44
- return (nn.tanh(x32o), nn.tanh(x16o), nn.tanh(x8o), nn.tanh(x4o))
45
-
46
  generator = Generator()
47
  variables = generator.init(jax.random.PRNGKey(0), jnp.zeros([1, LATENT_DIM]), training=False)
48
 
49
  fs = HfFileSystem()
50
- with fs.open("PrakhAI/AIPlane/g_checkpoint.msgpack", "rb") as f:
51
  g_state = from_state_dict(variables, msgpack_restore(f.read()))
52
 
53
  def sample_latent(key):
@@ -55,7 +24,7 @@ def sample_latent(key):
55
 
56
  if st.button('Generate Plane'):
57
  latents = sample_latent(jax.random.PRNGKey(int(1_000_000 * time.time())))
58
- (g_out32, g_out16, g_out8, g_out4) = generator.apply({'params': g_state['params'], 'batch_stats': g_state['batch_stats']}, latents, training=False)
59
  img = ((np.array(g_out32[0])+1)*255./2.).astype(np.uint8)
60
  st.image(Image.fromarray(img))
61
- st.write("The model and its details are at https://huggingface.co/PrakhAI/AIPlane")
 
8
  from flax.serialization import msgpack_restore, from_state_dict
9
  import time
10
  from local_response_norm import LocalResponseNorm
11
+ from generator import Generator
12
 
13
  LATENT_DIM = 100
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  generator = Generator()
16
  variables = generator.init(jax.random.PRNGKey(0), jnp.zeros([1, LATENT_DIM]), training=False)
17
 
18
  fs = HfFileSystem()
19
+ with fs.open("PrakhAI/AIPlane2/g_checkpoint.msgpack", "rb") as f:
20
  g_state = from_state_dict(variables, msgpack_restore(f.read()))
21
 
22
  def sample_latent(key):
 
24
 
25
  if st.button('Generate Plane'):
26
  latents = sample_latent(jax.random.PRNGKey(int(1_000_000 * time.time())))
27
+ (g_out128, _, _, _, _, _) = generator.apply({'params': g_state['params'], 'batch_stats': g_state['batch_stats']}, latents, training=False)
28
  img = ((np.array(g_out32[0])+1)*255./2.).astype(np.uint8)
29
  st.image(Image.fromarray(img))
30
+ st.write("The model and its details are at https://huggingface.co/PrakhAI/AIPlane2")