A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://huggingface.co/docs/transformers/v4.51.3/en/internal/image_processing_utils below:

Website Navigation


Utilities for Image Processors

Utilities for Image Processors

This page lists all the utility functions used by the image processors, mainly the functional transformations used to process the images.

Most of those are only useful if you are studying the code of the image processors in the library.

Image Transformations transformers.image_transforms.center_crop < source >

( image: ndarray size: tuple data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None input_data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None ) np.ndarray

Parameters

The cropped image.

Crops the image to the specified size using a center crop. Note that if the image is too small to be cropped to the size given, it will be padded (so the returned result will always be of size size).

transformers.image_transforms.center_to_corners_format < source >

( bboxes_center: TensorType )

Converts bounding boxes from center format to corners format.

center format: contains the coordinate for the center of the box and its width, height dimensions (center_x, center_y, width, height) corners format: contains the coordinates for the top-left and bottom-right corners of the box (top_left_x, top_left_y, bottom_right_x, bottom_right_y)

transformers.image_transforms.corners_to_center_format < source >

( bboxes_corners: TensorType )

Converts bounding boxes from corners format to center format.

corners format: contains the coordinates for the top-left and bottom-right corners of the box (top_left_x, top_left_y, bottom_right_x, bottom_right_y) center format: contains the coordinate for the center of the box and its the width, height dimensions (center_x, center_y, width, height)

transformers.image_transforms.id_to_rgb < source >

( id_map )

Converts unique ID to RGB color.

transformers.image_transforms.normalize < source >

( image: ndarray mean: typing.Union[float, collections.abc.Collection[float]] std: typing.Union[float, collections.abc.Collection[float]] data_format: typing.Optional[transformers.image_utils.ChannelDimension] = None input_data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None )

Parameters

Normalizes image using the mean and standard deviation specified by mean and std.

image = (image - mean) / std

transformers.image_transforms.pad < source >

( image: ndarray padding: typing.Union[int, tuple[int, int], collections.abc.Iterable[tuple[int, int]]] mode: PaddingMode = <PaddingMode.CONSTANT: 'constant'> constant_values: typing.Union[float, collections.abc.Iterable[float]] = 0.0 data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None input_data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None ) np.ndarray

Parameters

The padded image.

Pads the image with the specified (height, width) padding and mode.

transformers.image_transforms.rgb_to_id < source >

( color )

Converts RGB color to unique ID.

transformers.image_transforms.rescale < source >

( image: ndarray scale: float data_format: typing.Optional[transformers.image_utils.ChannelDimension] = None dtype: dtype = <class 'numpy.float32'> input_data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None ) np.ndarray

Parameters

The rescaled image.

Rescales image by scale.

transformers.image_transforms.resize < source >

( image: ndarray size: tuple resample: PILImageResampling = None reducing_gap: typing.Optional[int] = None data_format: typing.Optional[transformers.image_utils.ChannelDimension] = None return_numpy: bool = True input_data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None ) np.ndarray

Parameters

The resized image.

Resizes image to (height, width) specified by size using the PIL library.

transformers.image_transforms.to_pil_image < source >

( image: typing.Union[numpy.ndarray, ForwardRef('PIL.Image.Image'), ForwardRef('torch.Tensor'), ForwardRef('tf.Tensor'), ForwardRef('jnp.ndarray')] do_rescale: typing.Optional[bool] = None image_mode: typing.Optional[str] = None input_data_format: typing.Union[transformers.image_utils.ChannelDimension, str, NoneType] = None ) PIL.Image.Image

Parameters

The converted image.

Converts image to a PIL Image. Optionally rescales it and puts the channel dimension back as the last axis if needed.

ImageProcessingMixin class transformers.ImageProcessingMixin < source >

( **kwargs )

This is an image processor mixin used to provide saving/loading functionality for sequential and image feature extractors.

fetch_images < source >

( image_url_or_urls: typing.Union[str, list[str]] )

Convert a single or a list of urls into the corresponding PIL.Image objects.

If a single url is passed, the return value will be a single object. If a list is passed a list of objects is returned.

from_dict < source >

( image_processor_dict: dict **kwargs ) ImageProcessingMixin

Parameters

The image processor object instantiated from those parameters.

Instantiates a type of ImageProcessingMixin from a Python dictionary of parameters.

from_json_file < source >

( json_file: typing.Union[str, os.PathLike] ) A image processor of type ImageProcessingMixin

Parameters

Returns

A image processor of type ImageProcessingMixin

The image_processor object instantiated from that JSON file.

Instantiates a image processor of type ImageProcessingMixin from the path to a JSON file of parameters.

from_pretrained < source >

( pretrained_model_name_or_path: typing.Union[str, os.PathLike] cache_dir: typing.Union[str, os.PathLike, NoneType] = None force_download: bool = False local_files_only: bool = False token: typing.Union[str, bool, NoneType] = None revision: str = 'main' **kwargs )

Parameters

Instantiate a type of ImageProcessingMixin from an image processor.

Examples:

image_processor = CLIPImageProcessor.from_pretrained(
    "openai/clip-vit-base-patch32"
)  
image_processor = CLIPImageProcessor.from_pretrained(
    "./test/saved_model/"
)  
image_processor = CLIPImageProcessor.from_pretrained("./test/saved_model/preprocessor_config.json")
image_processor = CLIPImageProcessor.from_pretrained(
    "openai/clip-vit-base-patch32", do_normalize=False, foo=False
)
assert image_processor.do_normalize is False
image_processor, unused_kwargs = CLIPImageProcessor.from_pretrained(
    "openai/clip-vit-base-patch32", do_normalize=False, foo=False, return_unused_kwargs=True
)
assert image_processor.do_normalize is False
assert unused_kwargs == {"foo": False}
get_image_processor_dict < source >

( pretrained_model_name_or_path: typing.Union[str, os.PathLike] **kwargs ) Tuple[Dict, Dict]

Parameters

Returns

Tuple[Dict, Dict]

The dictionary(ies) that will be used to instantiate the image processor object.

From a pretrained_model_name_or_path, resolve to a dictionary of parameters, to be used for instantiating a image processor of type ~image_processor_utils.ImageProcessingMixin using from_dict.

push_to_hub < source >

( repo_id: str use_temp_dir: typing.Optional[bool] = None commit_message: typing.Optional[str] = None private: typing.Optional[bool] = None token: typing.Union[bool, str, NoneType] = None max_shard_size: typing.Union[int, str, NoneType] = '5GB' create_pr: bool = False safe_serialization: bool = True revision: typing.Optional[str] = None commit_description: typing.Optional[str] = None tags: typing.Optional[list[str]] = None **deprecated_kwargs )

Parameters

Upload the image processor file to the 🤗 Model Hub.

Examples:

from transformers import AutoImageProcessor

image processor = AutoImageProcessor.from_pretrained("google-bert/bert-base-cased")


image processor.push_to_hub("my-finetuned-bert")


image processor.push_to_hub("huggingface/my-finetuned-bert")
register_for_auto_class < source >

( auto_class = 'AutoImageProcessor' )

Parameters

Register this class with a given auto class. This should only be used for custom image processors as the ones in the library are already mapped with AutoImageProcessor .

This API is experimental and may have some slight breaking changes in the next releases.

save_pretrained < source >

( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )

Parameters

Save an image processor object to the directory save_directory, so that it can be re-loaded using the from_pretrained() class method.

to_dict < source >

( ) Dict[str, Any]

Dictionary of all the attributes that make up this image processor instance.

Serializes this instance to a Python dictionary.

to_json_file < source >

( json_file_path: typing.Union[str, os.PathLike] )

Parameters

Save this instance to a JSON file.

to_json_string < source >

( ) str

String containing all the attributes that make up this feature_extractor instance in JSON format.

Serializes this instance to a JSON string.

< > Update on GitHub

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3