Caffe + Opencv without lmdb

When using caffe to create a set of training materials containing images, we need to create a database in a special format, for example, lmdb, but is it possible to transfer batch processing of caffe images, for example, vector<cv::Mat> ?

To clarify, I'm looking for a solution that can process a large number of images that cannot fit into memory (but suppose that one training batch (containing, for example, 50 images) can be stored in memory).

+6
source share
1 answer

Caffe can accept many types of inputs, depending on the input layer used. Some of the input methods available are:

  • Data
  • MemoryData li>
  • HDF5Data li>
  • ImageData etc.

In the model file, the very first level you will find is Layer type: Data , which used lmdb or leveldb as an input method. Converting a set of images to these databases is quite simple, as Caffe already provides tools for converting images.

Layer type: MemoryData reads data directly from memory, which will be extremely useful when using camera input data that will be transferred as Caffe input during the testing phase. Using this level for training is not recommended.

Layer type: ImageData accepts a text file as input. The text file contains all the image names along with their full path and class number. Caffe uses OpenCV to read images in this layer. He also takes care of all image transformations. Thus, instead of using OpenCV to read an image and then go to the MemoryData level, it is recommended to use ImageData.

The .txt format from which the ImageData layer reads the image should be:

/path/to/the/image/imageName.jpg classNumber

Using LMDB or LevelDB is highly recommended because ImageData should not work well if the path or name of the image contains spaces or when any image is damaged.

Details of various levels can be found here .

Memory is allocated in the GPU depending on the model and batch size. If memory overflow occurs, you can try to reduce the batch size. Caffe easily processed the Imagenet database with 1.2 million images. Thus, with an optimal batch size, the algorithm should work without any problems.

+6
source

All Articles