NOT MAINTAINED. MOVE TO https://github.com/jina-ai/executors/tree/main/jinahub/crafters/ImageNormalizer
Image Normalizer is a class that resizes, crops and normalizes images. Since normalization is highly dependent on the model, it is recommended to have it as part of the encoders instead of using it in a dedicated executor. Therefore, misconfigurations resulting in a training-serving-gap are less likely.
The following parameters can be used:
resize_dim
(int): The size of the image after resizingtarget_size
(tuple or int): The dimensions to crop the image to (center cropping is used)img_mean
(tuple, default (0,0,0)): The mean for normalizationimg_std
(tuple, default (1,1,1)): The standard deviation for normalizationchannel_axis
(int): The channel axis in the images usedtarget_channel_axis
(int): The desired channel axis in the images. If this is not equal to the channel_axis, the axis is moved.target_dtype
(np.dtype, defaultnp.float32
): The desired type of the image array
Table of Contents
No prerequisites are required to run this executor.
Use the prebuilt images from JinaHub in your python codes,
from jina import Flow
f = Flow().add(uses='jinahub+docker://ImageNormalizer')
or in the .yml
config.
jtype: Flow
pods:
- name: encoder
uses: 'jinahub+docker://ImageNormalizer'
override_with:
target_size: 42
Use the source codes from JinaHub in your python codes,
from jina import Flow
f = Flow().add(uses='jinahub://ImageNormalizer')
or in the .yml
config.
jtype: Flow
pods:
- name: encoder
uses: 'jinahub://ImageNormalizer'
-
Install the
executor-image-normalizer
package.pip install git+https://github.com/jina-ai/executor-image-normalizer.git
-
Use
executor-image-normalizer
in your codefrom jina import Flow from jinahub.image.normalizer import ImageNormalizer f = Flow().add(uses=ImageNormalizer)
-
Clone the repo and build the docker image
git clone https://github.com/jina-ai/executor-image-normalizer.git cd executor-image-normalizer docker build -t image-normalizer .
-
Use
image-normalizer
in your codesfrom jina import Flow f = Flow().add(uses='docker://image-normalizer')
from jina import Flow, Document
f = Flow().add(uses='jinahub+docker://ImageNormalizer')
with f:
resp = f.post(on='foo', inputs=Document(), return_results=True)
print(f'{resp}')
Document
with image blob
.
Document
with overridden image blob
that is normalized, scaled, cropped and resized as instructed.