Skip to main content

Loads GPU or CPU pytorch models

Project description

model_loads is an open-source Python package for pytorch load models easy.

PyTorch is a Python package that provides two high-level features:

  • Tensor computation (like NumPy) with strong GPU acceleration
  • Deep neural networks built on a tape-based autograd system

It's annoying to load cpu model to gpu devices or load multi-gpus trained model to single gpu devices sometimes, And this package try to simplify it.

Table of Contents

Installation

To install load_models, you can do as follow:

    pip install model-loads

Or from source

    git clone https://github.com/cwh94/model_loads.git
    cd load_models
    python setup.py bdist_egg
    python setup.py install

Getting Started

  1. load pth model to GPU device
import model_loads as lo
import torchvision.models as models

model = models.MobileNetV2()
model_path = "../examples/models/pth/mobilenet_v2-b0353104.pth"
lo.load_models(model_path, model, use_gpu=True)
print(model)
print(type(model))
  1. load tar model(which contains state_dict and optimization info or accuracy) to CPU device
from models.tar.mobilenet_v2 import MobileNetV2

model = MobileNetV2()
model_path = "models/tar/checkpoint.pth.tar"

lo.load_models(model_path, model)
print(model)
  1. load model to CPU device
import os

os.environ["CUDA_VISIBLE_DEVICES"] = ""

model = models.MobileNetV2()
model_path = "models/pth/mobilenet_v2-b0353104.pth"
lo.load_models(model_path, model, use_gpu=True)
print(model)
print(type(model))

Done:

load model which save model by

torch.save(model, "path/to/model")

Todo list

DATA PARALLELISM

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

model-loads-0.2.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

model_loads-0.2.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file model-loads-0.2.2.tar.gz.

File metadata

  • Download URL: model-loads-0.2.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.9

File hashes

Hashes for model-loads-0.2.2.tar.gz
Algorithm Hash digest
SHA256 75c510013161149e1de326beb0ad4a516c550aa6d19875822b7ef365ec9d98d1
MD5 6c080a27c9be0d00faeef909afc56b70
BLAKE2b-256 0ad830cc496e18802d4e459ba646567c03e46b123a41fd437d0e3e4fb4ba2eb6

See more details on using hashes here.

File details

Details for the file model_loads-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: model_loads-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.9

File hashes

Hashes for model_loads-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 34b7ef9a5a2f16c016e03e69278d8734492b214b3c2ee106e8b55c78fd0eb34c
MD5 a599b523612d0a5d9e183e18bd4b7d0c
BLAKE2b-256 023df387f05ad22be5f7e6351759e0b4cd1d5cb27ca511888d3b2ff609298f41

See more details on using hashes here.

Supported by

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