Upload processor
Browse files- image_processor.py +35 -2
- preprocessor_config.json +2 -2
image_processor.py
CHANGED
@@ -23,7 +23,7 @@ from transformers.image_utils import (
|
|
23 |
from transformers.utils import is_torch_tensor
|
24 |
|
25 |
|
26 |
-
class
|
27 |
def __init__(self, **kwargs):
|
28 |
super().__init__(**kwargs)
|
29 |
self.image_size = kwargs.get("image_size", (224, 224))
|
@@ -204,7 +204,7 @@ class FaceSegformerImageProcessor(BaseImageProcessor):
|
|
204 |
data = {"pixel_values": images}
|
205 |
return BatchFeature(data=data, tensor_type="pt")
|
206 |
|
207 |
-
# Copied from transformers.models.
|
208 |
def post_process_semantic_segmentation(
|
209 |
self, outputs, target_sizes: List[Tuple] = None
|
210 |
):
|
@@ -255,3 +255,36 @@ class FaceSegformerImageProcessor(BaseImageProcessor):
|
|
255 |
|
256 |
return semantic_segmentation
|
257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
from transformers.utils import is_torch_tensor
|
24 |
|
25 |
|
26 |
+
class FaceNetImageProcessor(BaseImageProcessor):
|
27 |
def __init__(self, **kwargs):
|
28 |
super().__init__(**kwargs)
|
29 |
self.image_size = kwargs.get("image_size", (224, 224))
|
|
|
204 |
data = {"pixel_values": images}
|
205 |
return BatchFeature(data=data, tensor_type="pt")
|
206 |
|
207 |
+
# Copied from transformers.models.beit.image_processing_beit.BeitImageProcessor.post_process_semantic_segmentation with Beit->Segformer
|
208 |
def post_process_semantic_segmentation(
|
209 |
self, outputs, target_sizes: List[Tuple] = None
|
210 |
):
|
|
|
255 |
|
256 |
return semantic_segmentation
|
257 |
|
258 |
+
# def post_process_instance_segmentation(
|
259 |
+
# self,
|
260 |
+
# outputs,
|
261 |
+
# target_sizes: List[Tuple] = None,
|
262 |
+
# **kwargs
|
263 |
+
# ) -> np.ndarray:
|
264 |
+
# logits = outputs.logits
|
265 |
+
# if target_sizes is not None:
|
266 |
+
# if len(logits) != len(target_sizes):
|
267 |
+
# raise ValueError(
|
268 |
+
# "Make sure that you pass in as many target sizes as the batch dimension of the logits"
|
269 |
+
# )
|
270 |
+
# # use target sizes to resize logits
|
271 |
+
# resized_masks = []
|
272 |
+
# for idx in range(len(logits)):
|
273 |
+
# resized_mask = torch.nn.functional.interpolate(
|
274 |
+
# logits[idx].unsqueeze(dim=0),
|
275 |
+
# size=target_sizes[idx],
|
276 |
+
# mode="bilinear",
|
277 |
+
# align_corners=False,
|
278 |
+
# )
|
279 |
+
# resized_masks.append(
|
280 |
+
# resized_mask[0].softmax(dim=0).argmax(dim=0).to("cpu").numpy()
|
281 |
+
# )
|
282 |
+
|
283 |
+
# predicted_masks = np.array(resized_masks)
|
284 |
+
|
285 |
+
# else:
|
286 |
+
# predicted_masks = (
|
287 |
+
# torch.argmax(torch.softmax(logits, dim=1), axis=1).to("cpu").numpy()
|
288 |
+
# )
|
289 |
+
|
290 |
+
# return predicted_masks
|
preprocessor_config.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
{
|
2 |
"auto_map": {
|
3 |
-
"AutoImageProcessor": "image_processor.
|
4 |
},
|
5 |
"data_format": "channels_first",
|
6 |
-
"image_processor_type": "
|
7 |
"image_size": [
|
8 |
224,
|
9 |
224
|
|
|
1 |
{
|
2 |
"auto_map": {
|
3 |
+
"AutoImageProcessor": "image_processor.FaceNetImageProcessor"
|
4 |
},
|
5 |
"data_format": "channels_first",
|
6 |
+
"image_processor_type": "FaceNetImageProcessor",
|
7 |
"image_size": [
|
8 |
224,
|
9 |
224
|