rhendz commited on
Commit
91af153
·
1 Parent(s): 0c12714

Upload processor

Browse files
Files changed (1) hide show
  1. image_processing_spice_cnn.py +1 -59
image_processing_spice_cnn.py CHANGED
@@ -143,65 +143,7 @@ class SpiceCNNImageProcessor(BaseImageProcessor):
143
  `np.ndarray`: The padded image.
144
 
145
  """
146
- if input_data_format is None:
147
- input_data_format = infer_channel_dimension_format(image)
148
-
149
- def _expand_for_data_format(values):
150
- """
151
- Convert values to be in the format expected by np.pad based on the data format.
152
- """
153
- if isinstance(values, (int, float)):
154
- values = ((values, values), (values, values))
155
- elif isinstance(values, tuple) and len(values) == 1:
156
- values = ((values[0], values[0]), (values[0], values[0]))
157
- elif (
158
- isinstance(values, tuple)
159
- and len(values) == 2
160
- and isinstance(values[0], int)
161
- ):
162
- values = (values, values)
163
- elif (
164
- isinstance(values, tuple)
165
- and len(values) == 2
166
- and isinstance(values[0], tuple)
167
- ):
168
- values = values
169
- else:
170
- raise ValueError(f"Unsupported format: {values}")
171
-
172
- # add 0 for channel dimension
173
- values = (
174
- ((0, 0), *values)
175
- if input_data_format == ChannelDimension.FIRST
176
- else (*values, (0, 0))
177
- )
178
-
179
- # Add additional padding if there's a batch dimension
180
- values = (0, *values) if image.ndim == 4 else values
181
- return values
182
-
183
- padding = _expand_for_data_format(padding)
184
-
185
- if mode == PaddingMode.CONSTANT:
186
- constant_values = _expand_for_data_format(constant_values)
187
- image = np.pad(
188
- image, padding, mode="constant", constant_values=constant_values
189
- )
190
- elif mode == PaddingMode.REFLECT:
191
- image = np.pad(image, padding, mode="reflect")
192
- elif mode == PaddingMode.REPLICATE:
193
- image = np.pad(image, padding, mode="edge")
194
- elif mode == PaddingMode.SYMMETRIC:
195
- image = np.pad(image, padding, mode="symmetric")
196
- else:
197
- raise ValueError(f"Invalid padding mode: {mode}")
198
-
199
- image = (
200
- to_channel_dimension_format(image, data_format)
201
- if data_format is not None
202
- else image
203
- )
204
- return image
205
 
206
  def resize(
207
  self,
 
143
  `np.ndarray`: The padded image.
144
 
145
  """
146
+ return pad(image, padding=padding)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  def resize(
149
  self,