Code Monkey home page Code Monkey logo

build-an-ai-startup-with-pytorch's Introduction

AI Startup with PyTorch

Overview

This is the code for this video on Youtube by Siraj Raval on building an AI Startup with PyTorch. This is the original Dialogflow + Android integration project. This is the colab that I demonstrated in the video where I train the PyTorch model on movie reviews, then convert it to ONNX, then to Tensorflow's expected protobuf format.

#AISTARTUPCHALLENGE

alt text

Due date is May 15 2019 Submit your entry here.

Dependencies

  • Firebase
  • Paypal
  • Tensorflow Lite
  • DialogFlow
  • PyTorch

Instructions

Download Android Studio then import this project. Since I've placed the dependencies in the build.gradle file, it should auto-download them for you, which is awesome. It needs more features, and better integrated dataflow. I could've put more time into it, but I'm on to the next one. The model was too big to upload to GitHub. Place any .pb model into the app/src/main/assets folder and Tensorflow lite will detect it so it can be used for inference.

Credits

So many people. I stand on the shoulders of giants. Respect to all developers.

build-an-ai-startup-with-pytorch's People

Contributors

llsourcell avatar testaccount553 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

build-an-ai-startup-with-pytorch's Issues

torch to onnx

from torch.autograd import Variable
import torch.onnx

Load the trained model from file

net_save = SentimentRNN(vocab_size, output_size, embedding_dim, hidden_dim, n_layers)

trained_model = net_save
trained_model.load_state_dict(torch.load('sentiment.pth'))

Export the trained model to ONNX

dummy_input = Variable(torch.randn(1, 1, 28, 28)) # one black and white 28 x 28 picture will be the input to the model
torch.onnx.export(trained_model, dummy_input, "sentiment.onnx")

//error TypeError Traceback (most recent call last)
in ()
10 # Export the trained model to ONNX
11 dummy_input = Variable(torch.randn(1, 1, 28, 28)) # one black and white 28 x 28 picture will be the input to the model
---> 12 torch.onnx.export(trained_model, dummy_input, "sentiment.onnx")

/usr/local/lib/python3.6/dist-packages/torch/onnx/init.py in export(*args, **kwargs)
25 def export(*args, **kwargs):
26 from torch.onnx import utils
---> 27 return utils.export(*args, **kwargs)
28
29

/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py in export(model, args, f, export_params, verbose, training, input_names, output_names, aten, export_raw_ir, operator_export_type)
102 operator_export_type = OperatorExportTypes.ONNX
103 _export(model, args, f, export_params, verbose, training, input_names, output_names,
--> 104 operator_export_type=operator_export_type)
105
106

/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py in _export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, example_outputs, propagate)
279 training, input_names,
280 output_names, operator_export_type,
--> 281 example_outputs, propagate)
282
283 # TODO: Don't allocate a in-memory string for the protobuf

/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py in _model_to_graph(model, args, f, verbose, training, input_names, output_names, operator_export_type, example_outputs, propagate)
222 raise RuntimeError(''forward' method must be a script method')
223 else:
--> 224 graph, torch_out = _trace_and_get_graph_from_model(model, args, training)
225 params = list(_unique_state_dict(model).values())
226

/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py in _trace_and_get_graph_from_model(model, args, training)
190 # training mode was.)
191 with set_training(model, training):
--> 192 trace, torch_out = torch.jit.get_trace_graph(model, args, _force_outplace=True)
193
194 if orig_state_dict_keys != _unique_state_dict(model).keys():

/usr/local/lib/python3.6/dist-packages/torch/jit/init.py in get_trace_graph(f, args, kwargs, _force_outplace)
195 if not isinstance(args, tuple):
196 args = (args,)
--> 197 return LegacyTracedModule(f, _force_outplace)(*args, **kwargs)
198
199

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)

/usr/local/lib/python3.6/dist-packages/torch/jit/init.py in forward(self, *args)
250 try:
251 trace_inputs = _unflatten(all_trace_inputs[:len(in_vars)], in_desc)
--> 252 out = self.inner(*trace_inputs)
253 out_vars, _ = _flatten(out)
254 torch._C._tracer_exit(tuple(out_vars))

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
485 hook(self, input)
486 if torch._C._get_tracing_state():
--> 487 result = self._slow_forward(*input, **kwargs)
488 else:
489 result = self.forward(*input, **kwargs)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _slow_forward(self, *input, **kwargs)
475 tracing_state._traced_module_stack.append(self)
476 try:
--> 477 result = self.forward(*input, **kwargs)
478 finally:
479 tracing_state.pop_scope()

TypeError: forward() missing 1 required positional argument: 'hidden'

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.