Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
import kornia as K
|
4 |
from kornia.geometry.transform import resize
|
5 |
-
import cv2
|
6 |
import numpy as np
|
7 |
from torchvision import transforms
|
8 |
from torchvision.utils import make_grid
|
@@ -14,6 +13,8 @@ def read_image(img):
|
|
14 |
image_to_tensor = transforms.ToTensor()
|
15 |
if isinstance(img, np.ndarray):
|
16 |
img = Image.fromarray(img)
|
|
|
|
|
17 |
img_tensor = image_to_tensor(img)
|
18 |
resized_image = resize(img_tensor.unsqueeze(0), (50, 50)).squeeze(0)
|
19 |
return resized_image
|
@@ -31,14 +32,14 @@ def predict(images, eps):
|
|
31 |
title = 'ZCA Whitening with Kornia!'
|
32 |
description = '''[ZCA Whitening](https://paperswithcode.com/method/zca-whitening) is an image preprocessing method that leads to a transformation of data such that the covariance matrix is the identity matrix, leading to decorrelated features:
|
33 |
*Note that you can upload only image files, e.g. jpg, png etc and there should be at least 2 images!*
|
34 |
-
Learn more about [ZCA Whitening and Kornia](https://kornia.readthedocs.io/en/
|
35 |
|
36 |
with gr.Blocks(title=title) as demo:
|
37 |
gr.Markdown(f"# {title}")
|
38 |
gr.Markdown(description)
|
39 |
|
40 |
with gr.Row():
|
41 |
-
input_images = gr.
|
42 |
eps_slider = gr.Slider(minimum=0.01, maximum=1, value=0.01, label="Epsilon")
|
43 |
|
44 |
output_image = gr.Image(label="ZCA Whitened Images")
|
|
|
2 |
import torch
|
3 |
import kornia as K
|
4 |
from kornia.geometry.transform import resize
|
|
|
5 |
import numpy as np
|
6 |
from torchvision import transforms
|
7 |
from torchvision.utils import make_grid
|
|
|
13 |
image_to_tensor = transforms.ToTensor()
|
14 |
if isinstance(img, np.ndarray):
|
15 |
img = Image.fromarray(img)
|
16 |
+
elif isinstance(img, str):
|
17 |
+
img = Image.open(img).convert('RGB')
|
18 |
img_tensor = image_to_tensor(img)
|
19 |
resized_image = resize(img_tensor.unsqueeze(0), (50, 50)).squeeze(0)
|
20 |
return resized_image
|
|
|
32 |
title = 'ZCA Whitening with Kornia!'
|
33 |
description = '''[ZCA Whitening](https://paperswithcode.com/method/zca-whitening) is an image preprocessing method that leads to a transformation of data such that the covariance matrix is the identity matrix, leading to decorrelated features:
|
34 |
*Note that you can upload only image files, e.g. jpg, png etc and there should be at least 2 images!*
|
35 |
+
Learn more about [ZCA Whitening and Kornia](https://kornia.readthedocs.io/en/latest/enhance.zca.html)'''
|
36 |
|
37 |
with gr.Blocks(title=title) as demo:
|
38 |
gr.Markdown(f"# {title}")
|
39 |
gr.Markdown(description)
|
40 |
|
41 |
with gr.Row():
|
42 |
+
input_images = gr.Files(label="Input Images")
|
43 |
eps_slider = gr.Slider(minimum=0.01, maximum=1, value=0.01, label="Epsilon")
|
44 |
|
45 |
output_image = gr.Image(label="ZCA Whitened Images")
|