Downloads pretrained Microsoft Vision models
Project description
Microsoft Vision
Installation
pip install microsoftvision
Usage
Input images should be in BGR format of shape (3 x H x W), where H and W are expected to be at least 224. The images have to be loaded in to a range of [0, 1] and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225].
Example script:
import microsoftvision
import torch
# This will load pretrained model
model = microsoftvision.models.resnext101_32x8d(pretrained=True)
# Load model to CPU memory, interface is the same as torchvision
model = microsoftvision.resnet50(map_location=torch.device('cpu'))
Example of creating image embeddings:
import microsoftvision
from torchvision import transforms
import torch
from PIL import Image
def get_image():
img = cv2.imread('example.jpg', cv2.IMREAD_COLOR)
img = cv2.resize(img, (256, 256))
img = img[16:256-16, 16:256-16]
preprocess = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
return preprocess(image).unsqueeze(0) # Unsqueeze only required when there's 1 image in images batch
model = microsoftvision.models.resnet50(pretrained=True)
features = model(get_image())
print(features.shape)
Should output
...
torch.Size([1, 2048])
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
microsoftvision-1.0.3.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for microsoftvision-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b75a6fda8bd18c39112d6adbcf1b45794f6c9f45cdeabd531f432b106beb73db |
|
MD5 | e4dd7f8056e7f04b2adf1558e6df0396 |
|
BLAKE2b-256 | dab068567ec4ec042ef3cf887d1fd41d34d7e1d59c5689c8396f71de911660b4 |