sneedium commited on
Commit
ce8dba3
·
1 Parent(s): a9c31e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -7,10 +7,24 @@ import gradio as gr
7
  from torchvision import transforms as T
8
  from typing import Tuple
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def get_transform(img_size: Tuple[int], augment: bool = False, rotation: int = 0):
11
  transforms = []
12
  if augment:
13
- from .augment import rand_augment_transform
14
  transforms.append(rand_augment_transform())
15
  if rotation:
16
  transforms.append(lambda img: img.rotate(rotation, expand=True))
 
7
  from torchvision import transforms as T
8
  from typing import Tuple
9
 
10
+
11
+ def rand_augment_transform(magnitude=5, num_layers=3):
12
+ # These are tuned for magnitude=5, which means that effective magnitudes are half of these values.
13
+ hparams = {
14
+ 'rotate_deg': 30,
15
+ 'shear_x_pct': 0.9,
16
+ 'shear_y_pct': 0.2,
17
+ 'translate_x_pct': 0.10,
18
+ 'translate_y_pct': 0.30
19
+ }
20
+ ra_ops = auto_augment.rand_augment_ops(magnitude, hparams, transforms=_RAND_TRANSFORMS)
21
+ # Supply weights to disable replacement in random selection (i.e. avoid applying the same op twice)
22
+ choice_weights = [1. / len(ra_ops) for _ in range(len(ra_ops))]
23
+ return auto_augment.RandAugment(ra_ops, num_layers, choice_weights)
24
+
25
  def get_transform(img_size: Tuple[int], augment: bool = False, rotation: int = 0):
26
  transforms = []
27
  if augment:
 
28
  transforms.append(rand_augment_transform())
29
  if rotation:
30
  transforms.append(lambda img: img.rotate(rotation, expand=True))