Skip to content

Commit b4125b2

Browse files
committed
tensorrt on desktop pc and test script that works on desktop for uffparser
1 parent 0d8bbfc commit b4125b2

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ numpy - Python Math <br/>
1515
[imgaug](https://github.com/aleju/imgaug) - Data Augmentation. <br/>
1616
Panda3D - Rendering (only if you use PandaRender.py/PandaRender)<br/>
1717

18+
## Run on Docker
19+
I have created a docker image with the dependencies needed for this code. It needs a
20+
functioning cuda9 on host pc and nvidia docker installed. Realistically you will want
21+
to share a folder containing your data and code from host to docker container. This can be
22+
done with the `-v` option in docker. Also you might want to have GUIs enabled for docker.
23+
Have a look at [my blog for docker usage](https://kusemanohar.wordpress.com/2018/10/03/docker-for-computer-vision-researchers/)
24+
from a computer-vision researcher/developer perspective.
25+
26+
### Core Docker Usage
27+
```
28+
$(host) docker run --runtime=nvidia -it mpkuse/kusevisionkit:nvidia-cuda9-tf1.11-torch0.4 bash
29+
```
30+
31+
### A more realistic Usage
32+
```
33+
$(host) cd $HOME/docker_ws
34+
$(host) git clone <this repo>
35+
$(host) cd <you data dir>; put your data learning here.
36+
$(host) docker run --runtime=nvidia -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/docker_ws:/app -v /media/mpkuse/Bulk_Data/:/Bulk_Data mpkuse/kusevisionkit:nvidia-cuda9-tf1.11-torch0.4 bash
37+
$(docker) python noveou_train_netvlad_v3.py
38+
```
39+
1840

1941
## Howto train?
2042
The main code lies in `noveou_train_netvlad_v3.py`. It mainly depends on `CustomNets.py` (contains network definations, NetVLADLayer, data loading, data augmenters) ; on `CustomLosses.py` (contains loss functions
@@ -82,12 +104,18 @@ my [blog pose](https://kusemanohar.wordpress.com/2019/05/25/hands-on-tensorrt-on
82104
for more details in this regard.
83105

84106
The following script in this repo, will help you convert hdf5 keras models
85-
to .uff. Beware, that this is a rapidly changing/evolving thing.
107+
to .uff. Beware, that this is a rapidly changing/evolving thing. Look at Nvidia's devtalk under TX2 for the latest update on this.
86108
This info is accurate for May 2019.
87109
```
88110
python util_keras-h5-model_to-tensorflow-pb_to-nvinfer-uff.py --kerasmodel_h5file <path to hdf5 file>
89111
```
90112

113+
I have also created a script (test_tensorrt_uffparser.py) to quickly test the UFFParser on your desktop (x86). For this you need TensorRT python binding. You may use my docker image for a quick test
114+
115+
```
116+
docker run --runtime=nvidia -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/docker_ws:/app -v /media/mpkuse/Bulk_Data/:/Bulk_Data mpkuse/kusevisionkit:tfgpu-1.12-tensorrt-5.1 bash
117+
```
118+
91119
## References
92120
If you use my data/code or if you compare with my results, please do cite. Also cite
93121
the NetVLAD paper whenever appropriate.

demo_keras_hdf5_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
#-----
40-
# Replace Input Layer's Dimensions
40+
# Replace Input Layer's Dimensions (optional)
4141
im_rows = 480
4242
im_cols = 752
4343
im_chnls = 3
@@ -52,7 +52,7 @@
5252
# test new model on a random input image. Besure to check the input range of the model, for example [-1,1] or [-0.5,0.5] or [0,255] etc.
5353
X = np.random.rand(new_input_shape[0], new_input_shape[1], new_input_shape[2], new_input_shape[3] )
5454

55-
# --- You might want to do any of these normalizations depending on which model files you use.
55+
# --- You might want to do any of these normalizations depending on which model files you use.
5656
# i__image = np.expand_dims( cv_image.astype('float32'), 0 )
5757
# i__image = (np.expand_dims( cv_image.astype('float32'), 0 ) - 128.)/255. [-0.5,0.5]
5858
#i__image = (np.expand_dims( cv_image.astype('float32'), 0 ) - 128.)*2.0/255. #[-1,1]

test_tensorrt_uffparser.py renamed to demo_tensorrt_uffparser.py

+8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77
uff_fname = 'output_nvinfer.uff'
88

99
with trt.Builder( TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:
10+
# Set inputs and outputs correctly as per the model-uff
1011
parser.register_input("input_1", (3,240,320) )
1112
# parser.register_output( "conv_pw_5_relu/Relu6" )
1213
parser.register_output( "net_vlad_layer_1/l2_normalize_1" )
1314
parser.parse( LOG_DIR+'/'+uff_fname, network )
1415
pass
16+
17+
18+
# TODO
19+
# you need pycuda for this
20+
# 1. Load Image to GPU with cudamemcpy HtoD.
21+
# 2. Execute
22+
# 3. cudamemcpy DtoH

0 commit comments

Comments
 (0)