Giter Site home page Giter Site logo

postpcera / pytorchkotlindemo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vsay01/pytorchkotlindemo

0.0 1.0 0.0 41.6 MB

This is an Android project wirtten in kotlin to show a simple image classification application that use Android PyTorch API and trained PyTorch model.

License: BSD 3-Clause "New" or "Revised" License

Kotlin 100.00%

pytorchkotlindemo's Introduction

PytorchKotlinDemo

This is an Android project written in Kotlin to show a simple image classification application that uses Android PyTorch API and a trained PyTorch model.

In this demo application, user can either upload a picture or take photo. Then run the image analysis on the picture.

Architecture

I followed one of the android google architecture component sample.

This sample showcases the following Architecture Components:

Serialize a PyTorch model

In Android demo github, it describe in detail how the PyTorch model generated.

We cannot use the saved model directly in the notebook, we need to serialize that saved model.

In the Jupyter notebook where I trained the model, I can do the following

//load the model
ckp_path = './best_model.pt'
if(use_cuda):
  checkpoint = torch.load(ckp_path)
else:
  checkpoint = torch.load(ckp_path, map_location=torch.device('cpu'))
loaded_model.load_state_dict(checkpoint['state_dict'])
//serialize the model
loaded_model.eval()
example = torch.rand(1, 3, 224, 224)
if use_cuda:
  example = example.cuda()
traced_script_module = torch.jit.trace(loaded_model, example)
traced_script_module.save("./serialized_model.pt")

After this operations, we should have a usable model, serialized_model.pt.

References

Android demo github

PyTorch Mobile

android google architecture component sample

pytorchkotlindemo's People

Contributors

kikoso avatar postpcera avatar vortanasay avatar vsay01 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.