用户
 找回密码
 立即注册
发表于 2020-8-21 11:20:20
79170
本次NANO Hackathon活动主要向用户推广在JetsonNANO平台上利用TensorRT,TransferLearning Toolkit这两个开发工具,在实际应用中解决深度学习推理和训练上的问题。本次活动以口罩检测为主题,学生利用TransferLearning Toolkit训练ssd_mobilenet_v2等目标检测模型,并把训练好的模型利用TensorRT部署在Jetson NANO平台上来对视频进行人脸口罩检测。以下是从活动的微信群,webex会议等渠道收集概括的学生提出的问题。主要帮助学生解决了环境部署,API调用,代码调优等方面产生的问题。

1.    TensorRT哪里能找到比较好的教程?最好是中文的
目前建议最好的教程就是官方的Development Guide,您可以参考:
目前没有中文版,只有英文版。如果有更多问题,可以访问NVIDIA TensorRT的论坛:

2.    TensorRT目前在Python版本中支持的好吗?
目前TensorRT是能够很好的支持Python的,我们有SDK中有很多Python的例子。如果对于Python的结构细节,可以访问:

3.    TensorRT目前支持优化YOLO v3吗?
目前能够支持YOLO V3的

4.    麻烦推荐一下比较好的TensorRT比较好的安装教程?
这里推荐您官方提供的安装教程,也是最全的。目前官方支持到最新的7.1.3版本,您可以访问下面的连接:

5.    TensorRT的相关性能测试标准有吗?
您可以访问西面的连接查看:

6.    TensorRT优化SSD的代码能提供一下吗?
您可以直接下载您访问的NANO上面的ipython文件,那个里面提供了详细的TensorRT优化SSD的代码。

7.    TensorRT的版本可以向下支持吗?
TensorRT大部分内容可以向下支持,不过会在一些部分做优化,导致有些功能在使用最新的方法后会有更好的性能提升

8.    TensorRT支持Pytorch吗?
可以支持的,您可了解一下TensorRT优化ONNX格式的模型。您在SDK的sample里面找到。

9.    TensorRT目前支持GeForce系列显卡吗?
目前您可以利用GeForce显卡来优化推理引擎,不过使用Tesla系列的显卡能让您得到更好的性能提升

10.  TLT怎么安装?
您可以访问下面的网址:
这里面会详细的介绍

11.  TLT导出的模型可以直接转换成TensorRT格式吗?
TLT导出的模型经过tlt-converter工具转换后,可以直接利用TensorRT来执行推理任务。不过您需要在您部署的设备上利用tlt-converter转换。

12.  TLT有开源代码吗?
TLT目前的提供的是镜像的安装方式,没有提供源代吗。

13.  TLT可以不通过Docker安装吗?
TLT目前只能通过DOCKER的方式安装

14.  TLT可以再Geforce系列显卡上安装吗?
目前可以部署在GeForce系列显卡的机器上

15.  TLT装换工具tlt-converter的参数含义?
  1. tlt-converter [-h] -k<encryption_key>
  2.               -d <input_dimensions>
  3.               -o <comma separated outputnodes>
  4.               [-c <path to calibration cachefile>]
  5.               [-e <path to outputengine>]
  6.               [-b <calibration batchsize>]
  7.               [-m <maximum batch size of theTRT engine>]
  8.               [-t <engine datatype>]
  9.               [-w <maximum workspace size ofthe TRT Engine>]
  10.               [-i <input dimensionordering>]
  11.               input_file
复制代码
Required arguments:
  1. •        input_file: Path to the model exported using tlt-export.
  2. •        -k: The API key used to configure the ngc cli to download the models.
  3. •        -d: Comma-separated list of input dimensions that should match the dimensions used for tlt-export. Unlike tlt-export this cannot be inferred from calibration data.
  4. •        -o: Comma-separated list of output blob names that should match the output configuration used for tlt-export.
  5. o        For classification use: predictions/Softmax.
  6. o        For DetectNet_v2: output_bbox/BiasAdd,output_cov/Sigmoid
  7. o        For FasterRCNN: dense_class_td/Softmax,dense_regress_td/BiasAdd, proposal
  8. o        For SSD, DSSD, RetinaNet: NMS
  9. o        For YOLOv3: BatchedNMS
复制代码
Optional arguments:
  1. ·        -e:Path to save the engine to. (default: ./saved.engine)
  2. ·        -t:Desired engine data type, generates calibration cache if in INT8 mode. Thedefault value is fp32.The options are {fp32, fp16, int8}
  3. ·        -w:Maximum workspace size for the TensorRT engine. The default value is 1<<30.
  4. ·        -i:Input dimension ordering, all other tlt commands use NCHW. The default value isnchw. The options are {nchw, nhwc, nc}.
复制代码
INT8 Mode Arguments:
  1. ·        -c:Path to calibration cache file, only used in INT8 mode. The default valueis ./cal.bin.
  2. ·        -b:Batch size used during the tlt-export step for INT8 calibration cachegeneration. (default: 8).
  3. ·        -m:Maximum batch size of TensorRT engine. The default value is 16.
复制代码
您可以参考以上内容。或者访问下面的网址:

16.  TLT支持的目标检测的数据集的标注格式是什么?
目前支持的KITTI的数据标注格式,我们的Hackathon项目文件夹里有提供格式转换的工具

17.  TLT剪枝的具体使用方法?
  1. tlt-prune [-h] -pm <pretrained_model>
  2.                -o<output_file> -k <key>
  3.                [-n<normalizer>]
  4.                [-eq<equalization_criterion>]
  5.                [-pg<pruning_granularity>]
  6.                [-pth <pruningthreshold>]
  7.                [-nf<min_num_filters>]
  8.                [-el[<excluded_list>]
复制代码
您可以访问下面的网址得到详细信息及使用方法:

18.  TLT数据集图片格式?
目前支持PNG,JPG和JPEG,我们在Hackathon项目的文件目录下也提供了格式转换的工具和图片检查的工具

19.  TLT转换的模型再利用TensorRT做推理任务时总是输出不对?
这个错误可能由很多问题导致,建议通过以下方面进行检查:
A. 模型是否完整,有些时候模型在没传输完就被打断了
B. 输入维度是否正确
C. 输入维度的顺序是否正确
比如:tlt-converter里面-d参数后面的顺序是channel,height,width但是很多resize函数设置的都是width,height
D.检查一下输出的网络层是否正确
比如:SSD的输出层是NMS,而YOLOV3的输出层是BatchedNMS,您可以参考下面的内容:
  1. For classification use:predictions/Softmax.
  2. For DetectNet_v2:output_bbox/BiasAdd,output_cov/Sigmoid
  3. For FasterRCNN:dense_class_td/Softmax,dense_regress_td/BiasAdd, proposal
  4. For SSD, DSSD, RetinaNet: NMS
  5. For YOLOv3: BatchedNMS
复制代码
20.  TLT镜像下载太慢怎么办?
我们将镜像已经下载下来,您可以通过我们的地址进行下载来解决网络问题

21.  TLT预训练模型用examples里面的命令下载太慢怎么办?
您可以直接通过NGC官网下载,地址如下:

22.  TLT可以直接导出FP16 or INT8的模型吗?
TLT可以直接导出FP16和INT8模型

23.  TLT导出的FP16 or INT8的模型可以直接在NANO上部署吗?
TLT导出的FP16模型可以直接部署在NANO上,但是INT8模型不能部署在NANO上。您可以是用Xavier来部署

24.  这次Hackathon训练的口罩检测使用的是什么模型?
本次Hackathon训练的口罩检测可以自己选择模型,例子中使用的是SSD-mobilenetV2模型

25.  这次的Hackathon训练的口罩检测需要多少数据集?
训练数据集越多越好,例子中使用的是7000张左右的训练样本

26.  这次的Hackathon的任务可以自己更换网络吗?
本次的Hackathon的任务可以自己更换网络,并且非常支持同学自己了解更多的其他的网络模型。您可以通过TLT的预训练模型库进行下载。

27.  能举例说明如何转换TLT训练好的模型到TensorRT
注意:-d后面跟的是channel,height和width,这个顺序不能错
  1. %set_envKEY=cTJhcms3ODdvbHRsOWwxMTNvYW0yN3NuaHA6YjU2YjE1ZjgtNDk5Ni00NTY5LWE0MDAtMjMwNzgwZWE5MGFj
  2. !./tlt-converter -k $KEY \
  3.                -d 3,300,300 \
  4.                -o NMS \
  5.                -essd/TRT_ssd_mobilenet_v2_face.bin \
  6.                -m 1 \
  7.                -t fp32 \
  8.                -i nchw \
  9.               ssd_mobilenet_v2_epoch_040.etlt
复制代码
28.  在利用TLT训练的时候loss一直不下降怎么办?
可以增大训练数据集,也可以调节训练设置当中的学习率,如下部分:
  1. training_config {
  2.   batch_size_per_gpu: 64
  3.   num_epochs: 100
  4.   learning_rate {
  5.   soft_start_annealing_schedule {
  6.     min_learning_rate: 5e-7
  7.     max_learning_rate: 5e-3
  8.     soft_start: 0.1
  9.     annealing: 0.3
  10.     }
  11.   }
复制代码
29.  能否共享一下示例代码中训练模型的设置文件?
  1. random_seed: 42
  2. ssd_config {
  3.   aspect_ratios_global: "[1.0, 2.0, 0.5, 3.0, 1.0/3.0]"
  4.   scales: "[0.05, 0.1, 0.25, 0.4, 0.55, 0.7, 0.85]"
  5.   two_boxes_for_ar1: true
  6.   clip_boxes: false
  7.   loss_loc_weight: 0.8
  8.   focal_loss_alpha: 0.25
  9.   focal_loss_gamma: 2.0
  10.   variances: "[0.1, 0.1, 0.2, 0.2]"
  11.   arch: "mobilenet_v2"
  12.   freeze_bn: false
  13. }
  14. training_config {
  15.   batch_size_per_gpu: 64
  16.   num_epochs: 100
  17.   learning_rate {
  18.   soft_start_annealing_schedule {
  19.     min_learning_rate: 5e-7
  20.     max_learning_rate: 5e-3
  21.     soft_start: 0.1
  22.     annealing: 0.3
  23.     }
  24.   }
  25.   regularizer {
  26.     type: L2
  27.     weight: 0.00004
  28.   }
  29. }
  30. eval_config {
  31.   validation_period_during_training: 5
  32.   average_precision_mode: SAMPLE
  33.   batch_size: 32
  34.   matching_iou_threshold: 0.5
  35. }
  36. nms_config {
  37.   confidence_threshold: 0.01
  38.   clustering_iou_threshold: 0.6
  39.   top_k: 200
  40. }
  41. augmentation_config {
  42.   preprocessing {
  43.     output_image_width: 300
  44.     output_image_height: 300
  45.     output_image_channel: 3
  46.     crop_right: 300
  47.     crop_bottom: 300
  48.     min_bbox_width: 1.0
  49.     min_bbox_height: 1.0
  50.   }
  51.   spatial_augmentation {
  52.     hflip_probability: 0.5
  53.     vflip_probability: 0.0
  54.     zoom_min: 0.7
  55.     zoom_max: 1.8
  56.     translate_max_x: 8.0
  57.     translate_max_y: 8.0
  58.   }
  59.   color_augmentation {
  60.     hue_rotation_max: 25.0
  61.     saturation_shift_max: 0.20000000298
  62.     contrast_scale_max: 0.10000000149
  63.     contrast_center: 0.5
  64.   }
  65. }
  66. dataset_config {
  67.   data_sources: {
  68.     tfrecords_path: "/workspace-hekun/mydata/tlt-tensorrt-nano/tfrecords/kitti_trainval/kitti_trainval*"
  69.     image_directory_path: "/workspace-hekun/mydata/tlt-tensorrt-nano/data/train/"
  70.   }
  71.   image_extension: "JPEG"
  72.   target_class_mapping {
  73.       key: "face_mask"
  74.       value: "face_mask"
  75.   }
  76.   target_class_mapping {
  77.       key: "face"
  78.       value: "face"
  79.   }
  80. validation_fold: 0
  81. }
复制代码

30.  如何设置TLT模型剪枝的-pth参数?
这个在样例代码中可以看到,通常,我们需要设置‘-pth’参数来平衡模型的精度与模型的大小(或者说速度)。更高的‘-pth’数值,会让模型更小(更快的推理速度),但是也会降低模型精度。在本次实验中,作者使用的是0.5,如果精度没问题,我们可以增加‘-pth’的数值,来进一步剪枝。反之,我们则需要减小‘-pth’的数值。

31.  如何设置推理任务的代码?
  1. def _create_context(self):
  2.         for binding in self.engine:
  3.             size = trt.volume(self.engine.get_binding_shape(binding)) * \
  4.                    self.engine.max_batch_size
  5.             host_mem = cuda.pagelocked_empty(size, np.float32)
  6.             cuda_mem = cuda.mem_alloc(host_mem.nbytes)
  7.             self.bindings.append(int(cuda_mem))
  8.             if self.engine.binding_is_input(binding):
  9.                 self.host_inputs.append(host_mem)
  10.                 self.cuda_inputs.append(cuda_mem)
  11.             else:
  12.                 self.host_outputs.append(host_mem)
  13.                 self.cuda_outputs.append(cuda_mem)
  14.         print(len(cuda_mem))
  15.         return self.engine.create_execution_context()

  16.     def detect(self, img, conf_th=0.3):
  17.         """Detect objects in the input image."""
  18.         img_resized = _preprocess_trt(img, self.input_shape)
  19.         np.copyto(self.host_inputs[0], img_resized.ravel())
  20.         #将处理好的图片从CPU内存中复制到GPU显存
  21.         cuda.memcpy_htod_async(
  22.             self.cuda_inputs[0], self.host_inputs[0], self.stream)
  23.         #开始执行推理任务
  24.         self.context.execute_async(
  25.             batch_size=1,
  26.             bindings=self.bindings,
  27.             stream_handle=self.stream.handle)
  28.         #将推理结果输出从GPU显存复制到CPU内存
  29.         cuda.memcpy_dtoh_async(
  30.             self.host_outputs[1], self.cuda_outputs[1], self.stream)
  31.         cuda.memcpy_dtoh_async(
  32.             self.host_outputs[0], self.cuda_outputs[0], self.stream)
  33.         self.stream.synchronize()


  34.         output = self.host_outputs[0]
  35.         return _postprocess_trt(img, output, conf_th, self.output_layout)
复制代码
32.  如何不使用TLT手动的构建TensorRT推理引擎?
  1. with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:
  2.         builder.max_workspace_size = 1 << 28
  3.         builder.max_batch_size = 1
  4.         builder.fp16_mode = True

  5.         parser.register_input('Input', INPUT_DIMS)
  6.         parser.register_output('MarkOutput_0')
  7.         parser.parse(spec['tmp_uff'], network)
  8.         engine = builder.build_cuda_engine(network)
复制代码
使用道具 举报 回复
发新帖
您需要登录后才可以回帖 登录 | 立即注册