Skip to main content

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.resnet50(pretrained=True)

# Load model to CPU memory, interface is the same as torchvision
model = microsoftvision.models.resnet50(pretrained=True, 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.

Files for microsoftvision, version 1.0.5
Filename, size File type Python version Upload date Hashes
Filename, size microsoftvision-1.0.5-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size microsoftvision-1.0.5.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page