mischeiwiller commited on
Commit
aa91494
β€’
1 Parent(s): 4c55de5

Update kornia_aug.py

Browse files
Files changed (1) hide show
  1. kornia_aug.py +9 -3
kornia_aug.py CHANGED
@@ -18,21 +18,27 @@ def set_transform(content):
18
  transform = nn.Sequential()
19
  return transform
20
 
 
 
21
  st.markdown("# Kornia Augmentations Demo")
22
  st.sidebar.markdown(
23
  "[Kornia](https://github.com/kornia/kornia) is a *differentiable* computer vision library for PyTorch."
24
  )
25
- uploaded_file = st.sidebar.file_uploader("Choose a file")
 
26
  if uploaded_file is not None:
27
  im = Image.open(uploaded_file)
28
  else:
29
  im = Image.open("./images/pretty_bird.jpg")
 
30
  scaler = int(im.height / 2)
31
  st.sidebar.image(im, caption="Input Image", width=256)
 
32
  image = F.pil_to_tensor(im).float() / 255
33
 
34
  # batch size is just for show
35
  batch_size = st.sidebar.slider("batch_size", min_value=4, max_value=16, value=8)
 
36
  gpu = st.sidebar.checkbox("Use GPU!", value=True)
37
  if not gpu:
38
  st.sidebar.markdown("With Kornia you do ops on the GPU!")
@@ -93,6 +99,7 @@ content = st_ace(
93
  auto_update=False,
94
  readonly=readonly,
95
  )
 
96
  if content:
97
  transform = set_transform(content)
98
 
@@ -100,8 +107,8 @@ process = st.button("Next Batch")
100
 
101
  # Fake dataloader
102
  image_batch = torch.stack(batch_size * [image])
103
-
104
  image_batch = image_batch.to(device)
 
105
  transformeds = None
106
  try:
107
  transformeds = transform(image_batch)
@@ -109,7 +116,6 @@ except Exception as e:
109
  st.write(f"There was an error: {e}")
110
 
111
  cols = st.columns(4)
112
-
113
  if transformeds is not None:
114
  for i, x in enumerate(transformeds):
115
  i = i % 4
 
18
  transform = nn.Sequential()
19
  return transform
20
 
21
+ st.set_page_config(page_title="Kornia Augmentations Demo", layout="wide")
22
+
23
  st.markdown("# Kornia Augmentations Demo")
24
  st.sidebar.markdown(
25
  "[Kornia](https://github.com/kornia/kornia) is a *differentiable* computer vision library for PyTorch."
26
  )
27
+
28
+ uploaded_file = st.sidebar.file_uploader("Choose a file", type=['png', 'jpg', 'jpeg'])
29
  if uploaded_file is not None:
30
  im = Image.open(uploaded_file)
31
  else:
32
  im = Image.open("./images/pretty_bird.jpg")
33
+
34
  scaler = int(im.height / 2)
35
  st.sidebar.image(im, caption="Input Image", width=256)
36
+
37
  image = F.pil_to_tensor(im).float() / 255
38
 
39
  # batch size is just for show
40
  batch_size = st.sidebar.slider("batch_size", min_value=4, max_value=16, value=8)
41
+
42
  gpu = st.sidebar.checkbox("Use GPU!", value=True)
43
  if not gpu:
44
  st.sidebar.markdown("With Kornia you do ops on the GPU!")
 
99
  auto_update=False,
100
  readonly=readonly,
101
  )
102
+
103
  if content:
104
  transform = set_transform(content)
105
 
 
107
 
108
  # Fake dataloader
109
  image_batch = torch.stack(batch_size * [image])
 
110
  image_batch = image_batch.to(device)
111
+
112
  transformeds = None
113
  try:
114
  transformeds = transform(image_batch)
 
116
  st.write(f"There was an error: {e}")
117
 
118
  cols = st.columns(4)
 
119
  if transformeds is not None:
120
  for i, x in enumerate(transformeds):
121
  i = i % 4