# Image Embedding with SWAG *author: [Jael Gu](https://github.com/jaelgu)*
## Description An image embedding operator generates a vector given an image. This operator extracts features for image with pretrained [SWAG](https://github.com/facebookresearch/SWAG) models from [Torch Hub](https://pytorch.org/docs/stable/hub.html). SWAG implements models from the paper [Revisiting Weakly Supervised Pre-Training of Visual Perception Models](https://arxiv.org/abs/2201.08371). To achieve higher accuracy in image classification, SWAG uses hashtags to perform weakly supervised learning instead of fully supervised pretraining with image class labels.
## Code Example Load an image from path './towhee.jpg' and use the pretrained SWAG model 'vit_b16_in1k' to generate an image embedding. *Write a pipeline with explicit inputs/outputs name specifications:* ```python from towhee import pipe, ops, DataCollection p = ( pipe.input('path') .map('path', 'img', ops.image_decode()) .map('img', 'vec', ops.image_embedding.swag(model_name='vit_b16_in1k')) .output('img', 'vec') ) DataCollection(p('towhee.jpeg')).show() ```
## Factory Constructor Create the operator via the following factory method ***image_embedding.swag(model_name='vit_b16_in1k', skip_preprocess=False)*** **Parameters:** ***model_name:*** *str* The model name in string. The default value is "vit_b16_in1k". Supported model names: - vit_b16_in1k - vit_l16_in1k - vit_h14_in1k - regnety_16gf_in1k - regnety_32gf_in1k - regnety_128gf_in1k ***skip_preprocess:*** *bool* The flag to control whether to skip image preprocess. The default value is False. If set to True, it will skip image preprocessing steps (transforms). In this case, input image data must be prepared in advance in order to properly fit the model.
## Interface An image embedding operator takes a towhee image as input. It uses the pre-trained model specified by model name to generate an image embedding in ndarray. **Parameters:** ***img:*** *towhee.types.Image (a sub-class of numpy.ndarray)* The decoded image data in numpy.ndarray. **Returns:** *numpy.ndarray* The image embedding extracted by model.