Giter Club home page Giter Club logo

coreml_torch_utils's Introduction

PyTest codecov Linux macOS Maintenance

Small Coreml utils for deep learning models

* utils are tested for pytorch but should work for any deep learning framework

Install

pip install coreml-pytorch-utils

Example Usage

from coreml_torch_utils import InputEnumeratedShapeImage, OutputDynamicImage, RenameOutput, CoreExporter
from torch import nn
model = nn.Sequential(nn.Conv2d(3, 6, kernel_size=(1, 1)), nn.Conv2d(6, 3, kernel_size=(1, 1)))
model.eval()
jitted = jit.trace(model, example_inputs=(torch.rand(1, 3, 128, 128),))

base_coreml_model = ct.convert(
    jitted,
    inputs=ct.ImageType(
        "name": "x",
        "shape": (1, 3, 128, 128),
        ),
    convert_to="neuralnetwork",
)
utils = [
    InputEnumeratedShapeImage([(64, 128), (128, 256)]),
    OutputDynamicImage(
    height_lower_bound = 64
    height_upper_bound = 128
    width_lower_bound = 128
    width_upper_bound = 256),
    RenameOutput(new_name="SampleOutput")
]
exporter = CoreExporter(utils)
new_model = exporter(base_coreml_model)

# New model output name => SampleOutput, New model output type => Image [Avaliable input shapes 64x128, 128x265]
# Old model output name example => var23, Old model output type Array [Avaliable input shapes 128x128]

Change inputs to images with enumerated shapes

inp_enum = InputEnumeratedShapeImage([(64, 128), (128, 256)]) # [(H W), (H W)]
exporter = CoreExporter([inp_enum])
new_model = exporter(base_coreml_model)

Change output to images with static shape

exporter = CoreExporter([OutputStaticImage(height=128, width=256)])
new_model = exporter(base_coreml_model)

coreml_torch_utils's People

Contributors

machineko avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.