PaddleDetection icon indicating copy to clipboard operation
PaddleDetection copied to clipboard

windows10+dll方式,预测灰度图,一通道,结果不正确

Open zhouyuxixixi opened this issue 5 years ago • 3 comments

paddlepaddle2.0rc0,paddledetection-master,win10

我认为有可能单通道预测比三通道快,这个有没有试过对比速度的?我很想知道两者的预测速度能差多少,在使用windows+dll方式

训练和预测都使用灰度图,一通道 对operators.py和config文件进行了修改,确保输入网络的使1通道 `architecture: SSD use_gpu: true max_iters: 2001 snapshot_iter: 100 log_iter: 20 metric: VOC map_type: 11point pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/VGG16_caffe_pretrained.tar save_dir: output weights: output/ssd_vgg16_300_voc/model_final num_classes: 2

SSD: backbone: VGG multi_box_head: MultiBoxHead output_decoder: background_label: 0 keep_top_k: 200 nms_eta: 1.0 nms_threshold: 0.45 nms_top_k: 400 score_threshold: 0.01

VGG: depth: 16 with_extra_blocks: true normalizations: [20., -1, -1, -1, -1, -1]

MultiBoxHead: base_size: 300 aspect_ratios: [[2.], [2., 3.], [2., 3.], [2., 3.], [2.], [2.]] min_ratio: 20 max_ratio: 90 min_sizes: [30.0, 60.0, 111.0, 162.0, 213.0, 264.0] max_sizes: [60.0, 111.0, 162.0, 213.0, 264.0, 315.0] steps: [8, 16, 32, 64, 100, 300] offset: 0.5 flip: true min_max_aspect_ratios_order: true kernel_size: 3 pad: 1

LearningRate: base_lr: 0.0001 schedulers:

  • !PiecewiseDecay gamma: 0.1 milestones: [800, 1400]

OptimizerBuilder: optimizer: momentum: 0.9 type: Momentum regularizer: factor: 0.0005 type: L2

TrainReader: inputs_def: image_shape: [1, 300, 300] fields: ['image', 'gt_bbox', 'gt_class'] dataset: !VOCDataSet anno_path: train_detection.txt dataset_dir: E:\DeepLearning\DataSet\Cigarette\OnlyGoodCigarettePaddleDetectionCopy use_default_label: False sample_transforms:

  • !DecodeImage to_rgb: false to_gray: true
  • !NormalizeBox {}
  • !ResizeImage interp: 1 target_size: 300 use_cv2: true is_gray_image: true
  • !Permute to_bgr: false
  • !NormalizeImage is_scale: false mean: [104] std: [1] batch_size: 4 shuffle: true worker_num: 1 bufsize: 1 use_process: true

EvalReader: inputs_def: image_shape: [1, 300, 300] fields: ['image', 'gt_bbox', 'gt_class', 'im_shape', 'im_id', 'is_difficult'] dataset: !VOCDataSet anno_path: eval_detection.txt dataset_dir: E:\DeepLearning\DataSet\Cigarette\OnlyGoodCigarettePaddleDetectionCopy use_default_label: False sample_transforms:

  • !DecodeImage to_rgb: false to_gray: true with_mixup: false
  • !NormalizeBox {}
  • !ResizeImage interp: 1 target_size: 300 use_cv2: true is_gray_image: true
  • !Permute to_bgr: false
  • !NormalizeImage is_scale: false mean: [104] std: [1] batch_size: 1 worker_num: 1 bufsize: 1

TestReader: inputs_def: image_shape: [1,300,300] fields: ['image', 'im_id', 'im_shape'] dataset: !ImageFolder anno_path: test.txt use_default_label: false sample_transforms:

  • !DecodeImage to_rgb: false to_gray: true with_mixup: false
  • !ResizeImage interp: 1 target_size: 300 use_cv2: true is_gray_image: true
  • !Permute to_bgr: false
  • !NormalizeImage is_scale: false mean: [104] std: [1] batch_size: 1 `

通过dataloader可以发现确实送入的使一通道的,也就是【1,300,300】

训练完成之后,进行预测,在python下,可以 看出送入网络的也确实是【1,300,300】

image

预测的结果如图 image

导出模型,按照如下指令 python tools/export_model.py -c configs/ssd/ssd_vgg16_300_Ysc_Gray.yml --output_dir=inference_model -o weights=output/ssd_vgg16_300_Ysc_Gray/model_final

接下来,对C++预测部分进行了修改,也是确保送入的使灰度图,一通道

对object_detector和preprocess等文件进行修改,最后保证了送入网络的tensor也是一通道的

image

Preprocess(im); // Prepare input tensor auto input_names = predictor_->GetInputNames(); for (const auto& tensor_name : input_names) { auto in_tensor = predictor_->GetInputTensor(tensor_name); if (tensor_name == "image") { int rh = inputs_.eval_im_size_f_[0]; int rw = inputs_.eval_im_size_f_[1]; //原来是1,3,rh,rw in_tensor->Reshape({1, 1, rh, rw}); in_tensor->copy_from_cpu(inputs_.im_data_.data()); } else if (tensor_name == "im_size") { in_tensor->Reshape({1, 2}); in_tensor->copy_from_cpu(inputs_.ori_im_size_.data()); } else if (tensor_name == "im_info") { in_tensor->Reshape({1, 3}); in_tensor->copy_from_cpu(inputs_.eval_im_size_f_.data()); } else if (tensor_name == "im_shape") { in_tensor->Reshape({1, 3}); in_tensor->copy_from_cpu(inputs_.ori_im_size_f_.data()); } else if (tensor_name == "scale_factor") { in_tensor->Reshape({1, 4}); in_tensor->copy_from_cpu(inputs_.scale_factor_f_.data()); } }

我的图像是1,300,300的灰度图,最后送入网络的data也是90000,shape为1,1,300,300 应该是正确的

但是预测结果却不正确,相差非常大 image

请问这是为什么?

而且,从理论上来说,我个人觉得,单通道的参数应该比3通道的要少,就是__para__要小一点,但是我同时训练了单通道的和三通道的网络,其生成的参数文件大小是完全相同的,包括output文件下pdparams也是完全相同的,这又是为什么?

我考虑,有没有可能是export_model.py这个文件导出的模型只是针对三通道。

希望解答,谢谢

zhouyuxixixi avatar Dec 26 '20 08:12 zhouyuxixixi

在dll中,最后发现,送入的数据尺寸是对的,但是数据错了,经过修改,已经可以了,打扰了

zhouyuxixixi avatar Dec 26 '20 09:12 zhouyuxixixi

但是,还是有个问题,一通道的参数难道不应该比三通道的少? 而且,经过试验,发现,一通道和三通道的预测时间是一模一样的。 难过呀,一天白搞了?????????

zhouyuxixixi avatar Dec 26 '20 09:12 zhouyuxixixi

@zhouyuxixixi

单通道、三通道,只有第一层输入数据输入channel不同,影响的是第一层的conv的参数,网络种其他channel还是相同的。

qingqing01 avatar Dec 28 '20 02:12 qingqing01