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.

Source Distribution

microsoftvision-1.0.5.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

microsoftvision-1.0.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file microsoftvision-1.0.5.tar.gz.

File metadata

  • Download URL: microsoftvision-1.0.5.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for microsoftvision-1.0.5.tar.gz
Algorithm Hash digest
SHA256 f93e1a05f5133756409be01f20c7ee92f2e2600643546c5c774b7585113993f6
MD5 db0bb600ee99cbd7e5ae550efc83dd82
BLAKE2b-256 b433d315403c5b00020fd1669f4a4704549f0199048c5b7b3b5bf509fd3c95f1

See more details on using hashes here.

File details

Details for the file microsoftvision-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: microsoftvision-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for microsoftvision-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a2f4f425168fd144d6222c78ab527631ca62555f41fda7b517c0bf96c06d92b4
MD5 6c0dee026fffd475db57e8e7633b53f3
BLAKE2b-256 71db65a4aebd1eac4c5920ac5fcf7c964f9834675b129ef82871435ea902b393

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page