You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/07/31 13:53:52 UTC
[GitHub] [incubator-mxnet] anotinelg opened a new issue #15710: Inconsistent
behaviour of ImageRecordIter depending on encoding format png vs jpeg
anotinelg opened a new issue #15710: Inconsistent behaviour of ImageRecordIter depending on encoding format png vs jpeg
URL: https://github.com/apache/incubator-mxnet/issues/15710
## Description
I was checking behaviour of ImageRecordIter on .rec file I have created myself.
I have seen that depending on how I created .rec the behaviour of ImageRecordIter is different in the way it handles the order of the color channels.
I create with png format the ImageRecordIter which by default fall back on the opencv encoding function, and thus inherits the default channel format which is BGR. However if I pack the image with the "jpeg" format, it will use the RGB order. Is this inconsistency expected? Can we pass a flag so that it always retrieve the RBG format?
## Environment info (Required)
MXNet = 1.4.0
opencv-python==4.1.0.25
## Reproducible step
Create the rec file with png format
```
record = mx.recordio.MXRecordIO("temp_png.rec", 'w')
header = mx.recordio.IRHeader(0, label, id, 0)
img = np.ones(shape) * 255
img[0][0][0] = 0
img[0][0][0] = 1
img[0][0][0] =2
packed_s = mx.recordio.pack_img(header, img, quality=100, img_fmt=".png")
record.write(packed_s)
record.close()
```
Create the rec file with jpeg format
```
record = mx.recordio.MXRecordIO("temp_png.rec", 'w')
header = mx.recordio.IRHeader(0, label, id, 0)
img = np.ones((5,5,3)) * 255
img[0][0][0] = 0
img[0][0][0] = 1
img[0][0][0] = 2
packed_s = mx.recordio.pack_img(header, img, quality=100, img_fmt=".jpeg") # default
record.write(packed_s)
record.close()
```
```
iter = ImageRecordIter(path_imgrec="temp_png.rec", data_shape=(3,5,5))
batch = iter.next()
#check that the first channel for first pixel is 2
#check that the second channel for first pixel is 1
check that the third channel for first pixel is 0
iter = ImageRecordIter(path_imgrec="temp_jpeg.rec", data_shape=(3,5,5))
batch = iter.next()
#check that the first channel for first pixel is 0
#check that the second channel for first pixel is 1
#check that the third channel for first pixel is 2
```
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services