Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mischeiwiller
commited on
Commit
β’
0344d09
1
Parent(s):
d610df9
Update kornia_aug.py
Browse files- kornia_aug.py +11 -10
kornia_aug.py
CHANGED
@@ -6,6 +6,7 @@ from torchvision.transforms import functional as F
|
|
6 |
from torchvision.utils import make_grid
|
7 |
from streamlit_ace import st_ace
|
8 |
from PIL import Image
|
|
|
9 |
|
10 |
IS_LOCAL = False # Change this
|
11 |
|
@@ -34,25 +35,23 @@ else:
|
|
34 |
scaler = int(im.height / 2)
|
35 |
st.sidebar.image(im, caption="Input Image", width=256)
|
36 |
|
37 |
-
|
|
|
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=
|
43 |
if not gpu:
|
44 |
-
st.sidebar.markdown("
|
45 |
device = torch.device("cpu")
|
46 |
else:
|
47 |
-
if not IS_LOCAL:
|
48 |
-
st.sidebar.markdown("
|
49 |
-
# Credits
|
50 |
-
st.sidebar.caption("Demo made by [Ceyda Cinarel](https://linktr.ee/ceydai)")
|
51 |
-
st.sidebar.markdown("Clone [Code](https://github.com/cceyda/kornia-demo)")
|
52 |
device = torch.device("cpu")
|
53 |
else:
|
54 |
st.sidebar.markdown("Running on GPU~")
|
55 |
-
device = torch.device("cuda:0"
|
56 |
|
57 |
predefined_transforms = [
|
58 |
"""
|
@@ -119,7 +118,9 @@ cols = st.columns(4)
|
|
119 |
if transformeds is not None:
|
120 |
for i, x in enumerate(transformeds):
|
121 |
i = i % 4
|
122 |
-
|
|
|
|
|
123 |
|
124 |
st.markdown(
|
125 |
"There are a lot more transformations available: [Documentation](https://kornia.readthedocs.io/en/latest/augmentation.module.html)"
|
|
|
6 |
from torchvision.utils import make_grid
|
7 |
from streamlit_ace import st_ace
|
8 |
from PIL import Image
|
9 |
+
import numpy as np
|
10 |
|
11 |
IS_LOCAL = False # Change this
|
12 |
|
|
|
35 |
scaler = int(im.height / 2)
|
36 |
st.sidebar.image(im, caption="Input Image", width=256)
|
37 |
|
38 |
+
# Convert PIL Image to torch tensor
|
39 |
+
image = torch.from_numpy(np.array(im).transpose((2, 0, 1))).float() / 255.0
|
40 |
|
41 |
# batch size is just for show
|
42 |
batch_size = st.sidebar.slider("batch_size", min_value=4, max_value=16, value=8)
|
43 |
|
44 |
+
gpu = st.sidebar.checkbox("Use GPU!", value=False)
|
45 |
if not gpu:
|
46 |
+
st.sidebar.markdown("Using CPU for operations.")
|
47 |
device = torch.device("cpu")
|
48 |
else:
|
49 |
+
if not IS_LOCAL or not torch.cuda.is_available():
|
50 |
+
st.sidebar.markdown("GPU not available, using CPU.")
|
|
|
|
|
|
|
51 |
device = torch.device("cpu")
|
52 |
else:
|
53 |
st.sidebar.markdown("Running on GPU~")
|
54 |
+
device = torch.device("cuda:0")
|
55 |
|
56 |
predefined_transforms = [
|
57 |
"""
|
|
|
118 |
if transformeds is not None:
|
119 |
for i, x in enumerate(transformeds):
|
120 |
i = i % 4
|
121 |
+
img_np = x.cpu().numpy().transpose((1, 2, 0))
|
122 |
+
img_np = (img_np * 255).astype(np.uint8)
|
123 |
+
cols[i].image(img_np, use_column_width=True)
|
124 |
|
125 |
st.markdown(
|
126 |
"There are a lot more transformations available: [Documentation](https://kornia.readthedocs.io/en/latest/augmentation.module.html)"
|