Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhang
committed
Feb 19, 2019
1 parent
77ee4d2
commit baef62b
Showing
4 changed files
with
178 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,5 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
*.DS_Store | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"2. GluonCV C++ Inference Demo\n================================\n\nThis is a demo tutorial which illustrates how to use existing GluonCV\nmodels in c++ environments given exported JSON and PARAMS files.\n\nPlease checkout `Export Network <sphx_glr_build_examples_deployment_export_network.py>` for instructions of how to export pre-trained models.\n\nDemo usage\n----------\n\n.. code:: bash\n\n # with yolo3_darknet53_voc-0000.params and yolo3_darknet53-symbol.json on disk\n ./gluoncv-detect yolo3_darknet53_voc demo.jpg\n\n.. figure:: https://user-images.githubusercontent.com/3307514/45458507-d76ff600-b6a8-11e8-92e1-0b1966e4344f.jpg\n :alt: demo\n\n demo\n\nUsage:\n\n::\n\n SYNOPSIS\n ./gluoncv-detect <model file> <image file> [-o <outfile>] [--class-file <classfile>] [-e\n <epoch>] [--gpu <gpu>] [-q] [--no-disp] [-t <thresh>]\n\n OPTIONS\n -o, --output <outfile>\n output image, by default no output\n\n --class-file <classfile>\n plain text file for class names, one name per line\n\n -e, --epoch <epoch>\n Epoch number to load parameters, by default is 0\n\n --gpu <gpu> Which gpu to use, by default is -1, means cpu only.\n -q, --quite Quite mode, no screen output\n --no-disp Do not display image\n -t, --thresh <thresh>\n Visualize threshold, from 0 to 1, default 0.3.\n\nSource Code and Build Instructions\n----------------------------------\n\nThe C++ demo code and build instructions are available in our repository `scripts\n<https://github.com/dmlc/gluon-cv/tree/master/scripts/deployment/cpp-inference>`_.\n\n.. hint::\n\n Prebuilt binaries are `available <https://github.com/dmlc/gluon-cv/tree/master/scripts/deployment/cpp-inference#download-prebuilt-binaries>`_ for Linus, Mac OS and Windows.\n\n And you can also build MXNet from `source <https://github.com/dmlc/gluon-cv/tree/master/scripts/deployment/cpp-inference#build-from-source>`_ to support C++ inference demo.\n\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"1. Export trained GluonCV network to JSON\n============================================\n\nIt is awesome if you are enjoy using GluonCV in Python for training and testing.\nAt some point, you might ask: \"Is it possible to deploy the existing models to somewhere out of Python environments?\"\n\nThe answer is \"Absolutely!\", and it's super easy actually.\n\nThis article will show you how to export networks/models to be used somewhere other than Python.\n\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import gluoncv as gcv\nfrom gluoncv.utils import export_block" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"First of all, we need a network to play with, a pre-trained one is perfect\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"net = gcv.model_zoo.get_model('resnet18_v1', pretrained=True)\nexport_block('resnet18_v1', net, preprocess=True, layout='HWC')\nprint('Done.')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
".. hint::\n\n Use ``preprocess=True`` will add a default preprocess layer above the network,\n which will subtract mean [123.675, 116.28, 103.53], divide\n std [58.395, 57.12, 57.375], and convert original image (B, H, W, C and range [0, 255]) to\n tensor (B, C, H, W) as network input. This is the default preprocess behavior of all GluonCV\n pre-trained models. With this preprocess head, you can use raw RGB image in C++ without\n explicitly applying these operations.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The above code generates two files: xxxx.json and xxxx.params\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import glob\nprint(glob.glob('*.json') + glob.glob('*.params'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"JSON file includes computational graph and params file includes pre-trained weights.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The exportable networks are not limited to image classification models.\nWe can export detection and segmentation networks as well:\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# YOLO\nnet = gcv.model_zoo.get_model('yolo3_darknet53_coco', pretrained=True)\nexport_block('yolo3_darknet53_coco', net)\n\n# FCN\nnet = gcv.model_zoo.get_model('fcn_resnet50_ade', pretrained=True)\nexport_block('fcn_resnet50_ade', net)\n\n# MaskRCNN\nnet = gcv.model_zoo.get_model('mask_rcnn_resnet50_v1b_coco', pretrained=True)\nexport_block('mask_rcnn_resnet50_v1b_coco', net)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We are all set here. Please checkout the other tutorials of how to use the JSON and params files.\n\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters