CV-CUDA icon indicating copy to clipboard operation
CV-CUDA copied to clipboard

[QUESTION]使用cvcuda的预处理和cv2的预处理数据结果不一致。cvcuda里面的API并没有那么容易替换原来的dataload+torchvision

Open yang0907 opened this issue 3 years ago • 0 comments

What is your question? 根据sample/classification/python/inference.py将其改为cv2进行预处理,inference.py使用torchnvjpeg+cvcuda进行预处理,对标改为cv2处理,打印resize为224*224的输出值,发现两者预处理输出并不一致,最后预测结果top1都是一致,但是数值差别很大。结果如下: inference.py输出结果: resize224输出的tensor tensor([[[[ 84, 81, 76], [ 84, 81, 76], [ 84, 81, 76], ..., [ 65, 78, 38], [ 69, 82, 42], [ 73, 86, 46]],

     [[ 91,  85,  81],
      [ 92,  86,  82],
      [ 89,  86,  81],
      ...,
      [ 68,  81,  41],
      [ 74,  87,  47],
      [ 76,  89,  49]],

     [[102,  96,  92],
      [102,  96,  92],
      [ 98,  96,  91],
      ...,
      [ 70,  83,  43],
      [ 75,  88,  48],
      [ 79,  92,  52]],

     ...,

     [[223, 214, 202],
      [231, 223, 212],
      [231, 225, 215],
      ...,
      [112, 105,  72],
      [115, 107,  76],
      [115, 105,  77]],

     [[224, 218, 208],
      [231, 225, 215],
      [229, 223, 214],
      ...,
      [107, 105,  68],
      [108, 106,  71],
      [109, 103,  75]],

     [[233, 228, 220],
      [233, 226, 219],
      [229, 222, 215],
      ...,
      [103, 106,  66],
      [102, 104,  68],
      [104, 103,  73]]]]

预测结果 Result for the image: 1 of 1 Class : tiger cat Score : 0.6206790804862976 Class : tabby, tabby cat Score : 0.34871071577072144 Class : Egyptian cat Score : 0.024692637845873833 Class : lynx, catamount Score : 0.0009407186880707741 Class : tiger, Panthera tigris Score : 0.0006068991497159004 classification during 8.299229621887207 second. 使用cv2输出结果: resize224 [[[ 77 82 85] [ 77 82 85] [ 77 82 84] ... [ 38 78 66] [ 42 82 70] [ 46 86 74]]

[[ 82 86 91] [ 83 87 92] [ 81 87 90] ... [ 41 81 69] [ 46 86 74] [ 49 89 77]]

[[ 93 96 101] [ 93 97 101] [ 91 96 99] ... [ 43 83 71] [ 48 88 76] [ 52 92 80]]

...

[[203 215 223] [213 224 231] [215 225 231] ... [ 72 106 112] [ 76 108 115] [ 77 105 115]]

[[207 217 224] [215 225 232] [214 223 230] ... [ 68 106 108] [ 72 106 109] [ 75 104 109]]

[[220 229 233] [219 227 234] [215 223 230] ... [ 66 105 103] [ 68 105 103] [ 73 103 104]]] 预测结果 Result for the image: 1 of 1 Class : tiger cat Score : 0.6854793429374695 Class : tabby, tabby cat Score : 0.28089335560798645 Class : Egyptian cat Score : 0.022345563396811485 Class : tiger, Panthera tigris Score : 0.003986774943768978 Class : lynx, catamount Score : 0.0022239997051656246 classification during 9.738513231277466 second. 从这两个结果看,单张图上,完全使用GPU预处理+预测性能优于cv2的CPU结果,GPU使用了8秒多,CPU+GPU使用了9秒多。。。但是这个对照试验,使用torchnvjpeh的decode方式和cv2的decode方式有差别,而且通常情况下都会使用dataload+torchvision这种方式加载数据,样例直接用torchnvjpeg让人怀疑使用dataload这种方式会占用一部分的CPU资源,友好度上,cvcuda这个API并没有那么容易替换原来的dataload+torchvision

yang0907 avatar Dec 30 '22 09:12 yang0907