MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / _setup_normalization

Method _setup_normalization

generation/tokenizer/vtp_tokenizer.py:56–72  ·  view source on GitHub ↗

Setup normalization and inverse normalization transforms.

(self, normalize_type)

Source from the content-addressed store, hash-verified

54 f"normalize={self.normalize_type}")
55
56 def _setup_normalization(self, normalize_type):
57 """Setup normalization and inverse normalization transforms."""
58 if normalize_type == "half":
59 norm_cfg = NORMALIZE_HALF
60 elif normalize_type == "imagenet":
61 norm_cfg = NORMALIZE_IMAGENET
62 else:
63 raise ValueError(f"Unknown normalize_type: {normalize_type}. Use 'half' or 'imagenet'.")
64
65 self.norm_mean = norm_cfg["mean"]
66 self.norm_std = norm_cfg["std"]
67
68 # Inverse normalization: x_orig = x_norm * std + mean
69 # Which is: Normalize with mean=-mean/std, std=1/std
70 inv_mean = [-m / s for m, s in zip(self.norm_mean, self.norm_std)]
71 inv_std = [1.0 / s for s in self.norm_std]
72 self.transform_inv = Normalize(inv_mean, inv_std)
73
74 def img_transform(self, p_hflip=0, img_size=None):
75 img_size = img_size if img_size is not None else self.img_size

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected