Roman
commited on
chore: remove b&w filters post-processing step
Browse files- filters.py +5 -16
- filters/black and white/deployment/client.zip +2 -2
- filters/black and white/deployment/server.zip +2 -2
- filters/blur/deployment/client.zip +1 -1
- filters/blur/deployment/server.zip +1 -1
- filters/identity/deployment/client.zip +1 -1
- filters/identity/deployment/server.zip +1 -1
- filters/inverted/deployment/client.zip +1 -1
- filters/inverted/deployment/server.zip +1 -1
- filters/ridge detection/deployment/client.zip +2 -2
- filters/ridge detection/deployment/server.zip +2 -2
- filters/rotate/deployment/client.zip +1 -1
- filters/rotate/deployment/server.zip +1 -1
- filters/sharpen/deployment/client.zip +1 -1
- filters/sharpen/deployment/server.zip +1 -1
filters.py
CHANGED
|
@@ -87,6 +87,7 @@ class TorchConv(nn.Module):
|
|
| 87 |
# Ensure the kernel has a proper shape
|
| 88 |
# If the kernel has a 1D shape, a (1, 1) kernel is used for each in_channels
|
| 89 |
if len(kernel_shape) == 1:
|
|
|
|
| 90 |
kernel = self.kernel.reshape(
|
| 91 |
self.n_out_channels,
|
| 92 |
self.n_in_channels // self.groups,
|
|
@@ -151,7 +152,6 @@ class Filter:
|
|
| 151 |
self.onnx_model = None
|
| 152 |
self.fhe_circuit = None
|
| 153 |
self.divide = None
|
| 154 |
-
self.repeat_out_channels = False
|
| 155 |
|
| 156 |
# Instantiate the torch module associated to the given filter name
|
| 157 |
if filter_name == "identity":
|
|
@@ -174,19 +174,16 @@ class Filter:
|
|
| 174 |
# post-processing in order to retrieve the correct result
|
| 175 |
kernel = [299, 587, 114]
|
| 176 |
|
| 177 |
-
self.torch_model = TorchConv(kernel
|
| 178 |
|
| 179 |
# Define the value used when for dividing the output values in post-processing
|
| 180 |
self.divide = 1000
|
| 181 |
|
| 182 |
-
# Indicate that the out_channels will need to be repeated, as Gradio requires all
|
| 183 |
-
# images to have a RGB format, even for grayscaled ones
|
| 184 |
-
self.repeat_out_channels = True
|
| 185 |
|
| 186 |
elif filter_name == "blur":
|
| 187 |
kernel = np.ones((3, 3))
|
| 188 |
|
| 189 |
-
self.torch_model = TorchConv(kernel,
|
| 190 |
|
| 191 |
# Define the value used when for dividing the output values in post-processing
|
| 192 |
self.divide = 9
|
|
@@ -198,7 +195,7 @@ class Filter:
|
|
| 198 |
[0, -1, 0],
|
| 199 |
]
|
| 200 |
|
| 201 |
-
self.torch_model = TorchConv(kernel,
|
| 202 |
|
| 203 |
elif filter_name == "ridge detection":
|
| 204 |
kernel = [
|
|
@@ -209,12 +206,8 @@ class Filter:
|
|
| 209 |
|
| 210 |
# Additionally to the convolution operator, the filter will subtract a given threshold
|
| 211 |
# value to the result in order to better display the ridges
|
| 212 |
-
self.torch_model = TorchConv(kernel,
|
| 213 |
|
| 214 |
-
# Indicate that the out_channels will need to be repeated, as Gradio requires all
|
| 215 |
-
# images to have a RGB format, even for grayscaled ones. Ridge detection images are
|
| 216 |
-
# ususally displayed as such
|
| 217 |
-
self.repeat_out_channels = True
|
| 218 |
|
| 219 |
def compile(self):
|
| 220 |
"""Compile the filter on a representative inputset."""
|
|
@@ -266,8 +259,4 @@ class Filter:
|
|
| 266 |
# Clip the image's values to proper RGB standards as filters don't handle such constraints
|
| 267 |
output_image = output_image.clip(0, 255)
|
| 268 |
|
| 269 |
-
# Gradio requires all images to follow a RGB format
|
| 270 |
-
if self.repeat_out_channels:
|
| 271 |
-
output_image = output_image.repeat(3, axis=2)
|
| 272 |
-
|
| 273 |
return output_image
|
|
|
|
| 87 |
# Ensure the kernel has a proper shape
|
| 88 |
# If the kernel has a 1D shape, a (1, 1) kernel is used for each in_channels
|
| 89 |
if len(kernel_shape) == 1:
|
| 90 |
+
self.kernel = self.kernel.repeat(self.n_out_channels)
|
| 91 |
kernel = self.kernel.reshape(
|
| 92 |
self.n_out_channels,
|
| 93 |
self.n_in_channels // self.groups,
|
|
|
|
| 152 |
self.onnx_model = None
|
| 153 |
self.fhe_circuit = None
|
| 154 |
self.divide = None
|
|
|
|
| 155 |
|
| 156 |
# Instantiate the torch module associated to the given filter name
|
| 157 |
if filter_name == "identity":
|
|
|
|
| 174 |
# post-processing in order to retrieve the correct result
|
| 175 |
kernel = [299, 587, 114]
|
| 176 |
|
| 177 |
+
self.torch_model = TorchConv(kernel)
|
| 178 |
|
| 179 |
# Define the value used when for dividing the output values in post-processing
|
| 180 |
self.divide = 1000
|
| 181 |
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
elif filter_name == "blur":
|
| 184 |
kernel = np.ones((3, 3))
|
| 185 |
|
| 186 |
+
self.torch_model = TorchConv(kernel, groups=3)
|
| 187 |
|
| 188 |
# Define the value used when for dividing the output values in post-processing
|
| 189 |
self.divide = 9
|
|
|
|
| 195 |
[0, -1, 0],
|
| 196 |
]
|
| 197 |
|
| 198 |
+
self.torch_model = TorchConv(kernel, groups=3)
|
| 199 |
|
| 200 |
elif filter_name == "ridge detection":
|
| 201 |
kernel = [
|
|
|
|
| 206 |
|
| 207 |
# Additionally to the convolution operator, the filter will subtract a given threshold
|
| 208 |
# value to the result in order to better display the ridges
|
| 209 |
+
self.torch_model = TorchConv(kernel, threshold=900)
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
def compile(self):
|
| 213 |
"""Compile the filter on a representative inputset."""
|
|
|
|
| 259 |
# Clip the image's values to proper RGB standards as filters don't handle such constraints
|
| 260 |
output_image = output_image.clip(0, 255)
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
return output_image
|
filters/black and white/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d870611c586c24a8edde68e7974bc70b5bb7240a6bc6e28ba45bd50c11c8719
|
| 3 |
+
size 378
|
filters/black and white/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0113e57bf1016aa8089bfc95ce4eae847e6f69f8d921716718af19672aeffd9a
|
| 3 |
+
size 5871
|
filters/blur/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 391
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0181978730e5cdc7fc669916d949ce2f9a783d867362f731d36388917e3030ea
|
| 3 |
size 391
|
filters/blur/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 8716
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9334b5f3b113ddc97fe19a7fdadea7c6f1dbc97123aa1a94470c7b88174a0fb
|
| 3 |
size 8716
|
filters/identity/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 376
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8bd5dcf676ff27ea3e272f588fca78ff05db1ec922b5ee018182174d8f144e9
|
| 3 |
size 376
|
filters/identity/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 2537
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:62a76ee3f3688b0dab084bf415e2a83b3aafbd4b66f1aec43b3f867818c205e4
|
| 3 |
size 2537
|
filters/inverted/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 376
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8bd5dcf676ff27ea3e272f588fca78ff05db1ec922b5ee018182174d8f144e9
|
| 3 |
size 376
|
filters/inverted/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 4152
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ddfb48c9ceaeacec0a0ea13edbc3af545621deef9b66ae3a573e9c74295d23bb
|
| 3 |
size 4152
|
filters/ridge detection/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f31154f5c36f5974944129b513bddd33f74a2880d0d47503e0b6d202421d5d50
|
| 3 |
+
size 396
|
filters/ridge detection/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c5f75c8f54a669c5694c8aa5432c3ef1ff37cf375b7e17ab50e5fb33e50da93c
|
| 3 |
+
size 6697
|
filters/rotate/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 376
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8bd5dcf676ff27ea3e272f588fca78ff05db1ec922b5ee018182174d8f144e9
|
| 3 |
size 376
|
filters/rotate/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 4387
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:300962338ed0a7a4d47e1a679a36561e0888d1aafa2dc246630db946b9592313
|
| 3 |
size 4387
|
filters/sharpen/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 396
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74f5d14e6f5ccd47560c6a5194986005ba60251d1311a7ea9cf3ff7ee7b794f4
|
| 3 |
size 396
|
filters/sharpen/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 8735
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84da9ef7cebe7869be764ba5b5e3c959168722deb6e93bce4ad12c308bb4cad0
|
| 3 |
size 8735
|