MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / DetectionNormalize

Class DetectionNormalize

python/paddle_serving_app/reader/image_reader.py:741–783  ·  view source on GitHub ↗

Normalize a tensor image with mean and standard deviation. Given mean: ``(M1,...,Mn)`` and std: ``(S1,..,Sn)`` for ``n`` channels, this transform will normalize each channel of the input ``torch.*Tensor`` i.e. ``output[channel] = (input[channel] - mean[channel]) / std[channel]`` ..

Source from the content-addressed store, hash-verified

739
740
741class DetectionNormalize(object):
742 """Normalize a tensor image with mean and standard deviation.
743 Given mean: ``(M1,...,Mn)`` and std: ``(S1,..,Sn)`` for ``n`` channels, this transform
744 will normalize each channel of the input ``torch.*Tensor`` i.e.
745 ``output[channel] = (input[channel] - mean[channel]) / std[channel]``
746
747 .. note::
748 This transform acts out of place, i.e., it does not mutate the input tensor.
749
750 Args:
751 mean (sequence): Sequence of means for each channel.
752 std (sequence): Sequence of standard deviations for each channel.
753 is_scale (bool): whether need im / 255
754
755 """
756
757 def __init__(self, mean, std, is_scale=True):
758 self.mean = mean
759 self.std = std
760 self.is_scale = is_scale
761
762 def __call__(self, im, im_info=None):
763 """
764 Args:
765 im (np.ndarray): image (np.ndarray)
766 im_info (dict): info of image
767 Returns:
768 im (np.ndarray): processed image (np.ndarray)
769 im_info (dict): info of processed image
770 """
771 im = im.astype(np.float32, copy=False)
772 mean = np.array(self.mean)[np.newaxis, np.newaxis, :]
773 std = np.array(self.std)[np.newaxis, np.newaxis, :]
774
775 if self.is_scale:
776 im = im / 255.0
777 im -= mean
778 im /= std
779 return im, im_info
780
781 def __repr__(self):
782 return self.__class__.__name__ + '(mean={0}, std={1})'.format(self.mean,
783 self.std)
784
785
786class Lambda(object):

Callers 8

test_client.pyFile · 0.85
test_client.pyFile · 0.85
test_client.pyFile · 0.85
test_client.pyFile · 0.85
test_client.pyFile · 0.85
test_client.pyFile · 0.85
test_client.pyFile · 0.85
test_client.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected