Roman commited on
Commit
d9d229c
1 Parent(s): b3b800b

chore: remove b&w filters post-processing step

Browse files
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, n_out_channels=1, groups=1)
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, n_out_channels=3, groups=3)
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, n_out_channels=3, groups=3)
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, n_out_channels=1, groups=1, threshold=900)
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:c7e1c5c599fcc4e07bd722acdb7714449806fca6b3ba3817bbf24f30b8eaeb88
3
- size 385
 
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:e17cf05929c3d85ccb22e328253482cd7df9801ce401887d0bf31fba9a388699
3
- size 5740
 
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:2916f7efa8bc228ec36546a2b7546d7a18748bf412369a6b156b40ef959a64b6
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:dbec6d836330771abc58d883ad0d412aaaa80890a95d326ff7e5b7d6a4c06dd6
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:f0645e87469aabe50f6b2026483c56823e0cba7869927f7b7625be5e8220b444
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:479fc7ced59e53aab5beed63d8f79824e936e3cc46fffcd7be235f7ccc365d25
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:f0645e87469aabe50f6b2026483c56823e0cba7869927f7b7625be5e8220b444
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:9e005c8bb973987b999eff041c3bd8026c91edeb38c5c3c881831edb843f6f31
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:db5a84074c5aaea704ac457be16762df2c5bfea22fe0a01d3667802bb7bbd956
3
- size 395
 
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:e82a31c2b3e7b0928a3a63865251be73eaced7904421ca4eb817d784ff4e3933
3
- size 6440
 
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:f0645e87469aabe50f6b2026483c56823e0cba7869927f7b7625be5e8220b444
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:f25b860acc97a759d8649bf9d5377cffc79fce725234d85e9d0c9b678c4c510b
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:b86b76dbb486d07be8890f0de14ee8a27a3b5b2fa2f82bed9ea1aa9ecbfa15b6
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:00c9f80281335d19b8aec5e8f6f43f5c889504094b973a16062c868a4fc0b373
3
  size 8735
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84da9ef7cebe7869be764ba5b5e3c959168722deb6e93bce4ad12c308bb4cad0
3
  size 8735