Upload processor
Browse files- image_processor.py +3 -41
- 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))
|
|
@@ -172,11 +172,7 @@ class FaceNetImageProcessor(BaseImageProcessor):
|
|
| 172 |
images = [
|
| 173 |
self.resize(
|
| 174 |
image=image,
|
| 175 |
-
size={
|
| 176 |
-
"shortest_edge": min(
|
| 177 |
-
kwargs.get("image_size") or self.image_size
|
| 178 |
-
)
|
| 179 |
-
},
|
| 180 |
resample=kwargs.get("resample") or self.resample,
|
| 181 |
input_data_format=input_data_format,
|
| 182 |
)
|
|
@@ -204,7 +200,7 @@ class FaceNetImageProcessor(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 |
):
|
|
@@ -254,37 +250,3 @@ class FaceNetImageProcessor(BaseImageProcessor):
|
|
| 254 |
]
|
| 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
|
|
|
|
| 23 |
from transformers.utils import is_torch_tensor
|
| 24 |
|
| 25 |
|
| 26 |
+
class FaceSegformerImageProcessor(BaseImageProcessor):
|
| 27 |
def __init__(self, **kwargs):
|
| 28 |
super().__init__(**kwargs)
|
| 29 |
self.image_size = kwargs.get("image_size", (224, 224))
|
|
|
|
| 172 |
images = [
|
| 173 |
self.resize(
|
| 174 |
image=image,
|
| 175 |
+
size={"height": self.image_size[0], "width": self.image_size[1]},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
resample=kwargs.get("resample") or self.resample,
|
| 177 |
input_data_format=input_data_format,
|
| 178 |
)
|
|
|
|
| 200 |
data = {"pixel_values": images}
|
| 201 |
return BatchFeature(data=data, tensor_type="pt")
|
| 202 |
|
| 203 |
+
# Copied from transformers.models.segformer.image_processing_segformer.SegformerImageProcessor.post_process_semantic_segmentation
|
| 204 |
def post_process_semantic_segmentation(
|
| 205 |
self, outputs, target_sizes: List[Tuple] = None
|
| 206 |
):
|
|
|
|
| 250 |
]
|
| 251 |
|
| 252 |
return semantic_segmentation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.FaceSegformerImageProcessor"
|
| 4 |
},
|
| 5 |
"data_format": "channels_first",
|
| 6 |
+
"image_processor_type": "FaceSegformerImageProcessor",
|
| 7 |
"image_size": [
|
| 8 |
224,
|
| 9 |
224
|