anotinelg commented on issue #15710: Inconsistent behaviour of ImageRecordIter 
depending on encoding format png vs jpeg
URL: 
https://github.com/apache/incubator-mxnet/issues/15710#issuecomment-518146148
 
 
   Thanks for the confirmation. But then I have a concern and this is about the 
color normalisation we apply with imageRecordIter. It seems that it does not 
apply the coefficient mean_[CHANNEL] and std_[CHANNEL] to the correct one:
   
   
   ```
           import mxnet as mx
           import numpy as np
   
           # Create rec with png packing
           shape = (3, 3, 3)
           label = 1
           record = mx.recordio.MXRecordIO("temp_png.rec", 'w')
           header = mx.recordio.IRHeader(0, label, 1, 0)
           img = np.ones(shape) * 255
           img[0][0][0] = 0
           img[0][0][1] = 100
           img[0][0][2] = 200
           print(img)
           packed_s = mx.recordio.pack_img(header, img, quality=9, 
img_fmt=".png")
           record.write(packed_s)
           record.close()
   
           # test the imageRecordIter, with color normalisation only on BLUE 
Channel
           iter = mx.io.ImageRecordIter(path_imgrec="temp_png.rec", 
data_shape=shape, batch_size=1,
                                        mean_r=0,
                                        mean_g=0,
                                        mean_b=50,
                                        std_r=1,
                                        std_g=1,
                                        std_b=150
                                        )
           batch = iter.next()
           data = batch.data[0]
           print(data.shape)
           print(data)
           data = mx.ndarray.transpose(data, (0, 2, 3, 1))
           # imageRecordIter invert channel from RGB to BGR
           img_after = data.asnumpy()[0]
           print(img_after[0][0])
           self.assertTrue(img_after[0][0][0] == 1)
           self.assertTrue(img_after[0][0][1] == 100)
           self.assertTrue(img_after[0][0][2] == 0)
   ``` 
   
   The output are:
   ```
   [[[  0. 100. 200.]
     [255. 255. 255.]
     [255. 255. 255.]]
   
    [[255. 255. 255.]
     [255. 255. 255.]
     [255. 255. 255.]]
   
    [[255. 255. 255.]
     [255. 255. 255.]
     [255. 255. 255.]]]
   [10:46:42] src/io/iter_image_recordio_2.cc:170: ImageRecordIOParser2: 
temp_png.rec, use 1 threads for decoding..
   (1, 3, 3, 3)
   
   [[[[200.         255.         255.        ]
      [255.         255.         255.        ]
      [255.         255.         255.        ]]
   
     [[100.         255.         255.        ]
      [255.         255.         255.        ]
      [255.         255.         255.        ]]
   
     [[ -0.33333334   1.3666667    1.3666667 ]
      [  1.3666667    1.3666667    1.3666667 ]
      [  1.3666667    1.3666667    1.3666667 ]]]]
   <NDArray 1x3x3x3 @cpu_pinned(0)>
   [200.         100.          -0.33333334]
   ```
   
   It seems that the mean_r and std_r are applied on the Red Channel, instead 
of the blue channel as specified in the call of the imageRecordIter function
   
   Is it a bug?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to