rodrigomasini commited on
Commit
c1ecabd
·
verified ·
1 Parent(s): 36e5696

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -243,6 +243,27 @@ def get_caption_group(images_groups,captions = []):
243
  caption_groups[-1] = caption_groups[-1] + [""] * (len(images_groups[-1]) - len(caption_groups[-1]))
244
  return caption_groups
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  def get_comic_classical(images,captions = None,font = None,pad_image = None):
247
  if pad_image == None:
248
  raise ValueError("pad_image is None")
 
243
  caption_groups[-1] = caption_groups[-1] + [""] * (len(images_groups[-1]) - len(caption_groups[-1]))
244
  return caption_groups
245
 
246
+ class MLP(nn.Module):
247
+ def __init__(self, in_dim, out_dim, hidden_dim, use_residual=True):
248
+ super().__init__()
249
+ if use_residual:
250
+ assert in_dim == out_dim
251
+ self.layernorm = nn.LayerNorm(in_dim)
252
+ self.fc1 = nn.Linear(in_dim, hidden_dim)
253
+ self.fc2 = nn.Linear(hidden_dim, out_dim)
254
+ self.use_residual = use_residual
255
+ self.act_fn = nn.GELU()
256
+
257
+ def forward(self, x):
258
+ residual = x
259
+ x = self.layernorm(x)
260
+ x = self.fc1(x)
261
+ x = self.act_fn(x)
262
+ x = self.fc2(x)
263
+ if self.use_residual:
264
+ x = x + residual
265
+ return x
266
+
267
  def get_comic_classical(images,captions = None,font = None,pad_image = None):
268
  if pad_image == None:
269
  raise ValueError("pad_image is None")