ceyda commited on
Commit
6e3a15d
Β·
1 Parent(s): b7fbd81

allow uploading a batch of images

Browse files
Files changed (1) hide show
  1. kornia_aug.py +15 -6
kornia_aug.py CHANGED
@@ -23,14 +23,20 @@ st.markdown("# Kornia Augmentations Demo")
23
  st.sidebar.markdown(
24
  "[Kornia](https://github.com/kornia/kornia) is a *differentiable* computer vision library for PyTorch."
25
  )
26
- uploaded_file = st.sidebar.file_uploader("Choose a file")
27
- if uploaded_file is not None:
28
- im = Image.open(uploaded_file)
 
 
 
 
29
  else:
30
  im = Image.open("./images/pretty_bird.jpg")
31
- scaler = int(im.height / 2)
 
 
32
  st.sidebar.image(im, caption="Input Image", width=256)
33
- image = F.pil_to_tensor(im).float() / 255
34
 
35
 
36
  # batch size is just for show
@@ -110,7 +116,10 @@ if content:
110
  process = st.button("Next Batch")
111
 
112
  # Fake dataloader
113
- image_batch = torch.stack(batch_size * [image])
 
 
 
114
 
115
 
116
  image_batch.to(device)
 
23
  st.sidebar.markdown(
24
  "[Kornia](https://github.com/kornia/kornia) is a *differentiable* computer vision library for PyTorch."
25
  )
26
+ ims=[]
27
+ uploaded_files = st.sidebar.file_uploader("Choose a file")
28
+ if uploaded_files is not None:
29
+ for uploaded_file in uploaded_files:
30
+ im = Image.open(uploaded_file)
31
+ image = F.pil_to_tensor(im).float() / 255
32
+ ims.append(image)
33
  else:
34
  im = Image.open("./images/pretty_bird.jpg")
35
+ image = F.pil_to_tensor(im).float() / 255
36
+ ims.append(image)
37
+ scaler = int(ims[0].height / 2)
38
  st.sidebar.image(im, caption="Input Image", width=256)
39
+
40
 
41
 
42
  # batch size is just for show
 
116
  process = st.button("Next Batch")
117
 
118
  # Fake dataloader
119
+ if len(ims)>1:
120
+ image_batch = torch.stack(ims)
121
+ else:
122
+ image_batch = torch.stack(batch_size * ims)
123
 
124
 
125
  image_batch.to(device)