MCPcopy
hub / github.com/microsoft/Cream / create_model_and_transforms

Function create_model_and_transforms

TinyCLIP/src/open_clip/factory.py:183–211  ·  view source on GitHub ↗
(
        model_name: str,
        pretrained: str = '',
        precision: str = 'fp32',
        device: torch.device = torch.device('cpu'),
        jit: bool = False,
        force_quick_gelu: bool = False,
        pretrained_image: bool = False,
        image_mean: Optional[Tuple[float, ...]] = None,
        image_std: Optional[Tuple[float, ...]] = None,
        cache_dir: Optional[str] = None,
        args=None,
)

Source from the content-addressed store, hash-verified

181
182
183def create_model_and_transforms(
184 model_name: str,
185 pretrained: str = '',
186 precision: str = 'fp32',
187 device: torch.device = torch.device('cpu'),
188 jit: bool = False,
189 force_quick_gelu: bool = False,
190 pretrained_image: bool = False,
191 image_mean: Optional[Tuple[float, ...]] = None,
192 image_std: Optional[Tuple[float, ...]] = None,
193 cache_dir: Optional[str] = None,
194 args=None,
195):
196 model = create_model(
197 model_name, pretrained, precision, device, jit,
198 force_quick_gelu=force_quick_gelu,
199 pretrained_image=pretrained_image,
200 cache_dir=cache_dir,
201 args=args)
202
203 image_mean = image_mean or getattr(model.visual, 'image_mean', None)
204 image_std = image_std or getattr(model.visual, 'image_std', None)
205 val_keep_ratio = 'davit' not in model_name.lower()
206 preprocess_train = image_transform(
207 model.visual.image_size, is_train=True, mean=image_mean, std=image_std)
208 preprocess_val = image_transform(model.visual.image_size, is_train=False,
209 mean=image_mean, std=image_std, val_keep_ratio=val_keep_ratio)
210
211 return model, preprocess_train, preprocess_val
212
213
214def list_models():

Callers 5

_load_checkpointFunction · 0.90
mainFunction · 0.90
_load_checkpointFunction · 0.90
mainFunction · 0.90
load_expFunction · 0.85

Calls 2

create_modelFunction · 0.85
image_transformFunction · 0.85

Tested by 2

_load_checkpointFunction · 0.72
mainFunction · 0.72