TensorRT sampleMinist somequestion about readPGMFile


I have install TensorRT1.0 on GTX1080, and can run the samples, but I test my own pictures such as .jpg in sampleMnist,I always get the wrong classify result,I have read the function “void readPGMFile(const std::string& fileName, uint8_t buffer[INPUT_H*INPUT_W])”,and have a test,when I input jpg file,I get the messy code. and when I input a .pgm file,the buffer has values in 0-255.

I want to know how can i get the correct buffer using other picture format? just imread the picture by opencv and change it to gray? or i can use ios::binary get the correct buffer?

Thanks very much.

PGM files are a different format than jpg. If you want to read jpg files you’ll want to convert them.


PGM is a grayscale image format. It suffices for the MNIST sample. In other samples such as Faster R-CNN sample, you’ll see the PPM format, which is a 3-channel (RGB) color image format.
A simple way to get you images of PPM format is to use imagemagick. Here’re the steps if you want to rescale a cat.jpg to 600x800 then convert it to PPM, assuming Ubuntu OS:
1 sudo apt-get install imagemagick
2 convert -resize 600X800! cat.jpg cat_resized.jpg
3 convert cat_resized.jpg cat.ppm

Or you can use opencv to do the trick, but that requires some coding work.