Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,8 @@ dmypy.json
# Cython debug symbols
cython_debug/

# Node modules
node_modules/

# IDE specific files
.idea
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ Streamix is a video conferencing feature that provides you seamless virtual back

# Youtube Link
[![Watch the video](https://i.ytimg.com/vi/2DVQ2XwhtUI/hqdefault.jpg)](https://www.youtube.com/watch?v=2DVQ2XwhtUI)

# Getting started on the project
- Install node version 12
- clone this repo using `git clone https://github.com/kenil-shah/Streamix.git`
- Go inside repository folder
- Install node dependencies using `npm install`
- Install python dependencies using `pip install requirements.txt`
- To run and test the code `node server.js`
- In your browser go to `localhost:8888`
8 changes: 8 additions & 0 deletions code/python_background_pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Running onnx converter

python onnx_converter.py --modelpath "path_to_saved_model/modelname.pth" --opset OP_VERSION --savepath "path_where_to_save_converted_model/modelname.onnx"

### Example
python onnx_converter.py --modelpath '/home/hpatel24/Fall2020/CSC510/project1/Streamix/data/models/segmentation_model.pth' --opset 10 --savepath '/home/hpatel24/Fall2020/CSC510/project1/Streamix/data/models/segmentation_model11.onnx'


27 changes: 27 additions & 0 deletions code/python_background_pipeline/onnx_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import torch
import argparse


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Model conversion (Torch -> ONNX)')
parser.add_argument('--modelpath',
default='./data/models/segmentation_model.pth',
help='Location of pytorch model')
parser.add_argument('--dummyinputsize',
default=[1, 3, 256, 256],
help='Default input shape for model')
parser.add_argument('--opset',
default=int(10),
help='Operator Set version for ONNX conversion')
parser.add_argument('--savepath',
default='./data/models/segmentation_model.onnx',
help='Path where you want to save onnx model')

args = vars(parser.parse_args())

model = torch.load(args['modelpath'], map_location= lambda storage, loc: storage)
shape = args['dummyinputsize']
print(type(shape[0]))
dummy_input = torch.randn(shape[0], shape[1], shape[2], shape[3])
torch.onnx.export(model, dummy_input, args['savepath'], opset_version=int(args['opset']))

3 changes: 3 additions & 0 deletions code/src/numjs.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions code/src/onnx.min.js

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions code/src/opencv.js

Large diffs are not rendered by default.

Binary file added data/models/segmentation_model.pb/saved_model.pb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/models/segmentation_model11.onnx
Binary file not shown.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<script src="./code/src/onnx.min.js"></script>
<script src="main.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
async function test() {
const sess = new onnx.InferenceSession()
await sess.loadModel('./data/models/segmentation_model.onnx')
const input = new onnx.Tensor(new Float32Array(256*256*3), 'float32', [1, 3, 256, 256])
const outputMap = await sess.run([input])
const outputTensor = outputMap.values().next().value
console.log("here")
console.log(`Output tensor: ${outputTensor.data}`)
}
test()
Loading