MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / CaffeLMDB

Function CaffeLMDB

tensorpack/dataflow/format.py:172–204  ·  view source on GitHub ↗

Read a Caffe-format LMDB file where each value contains a ``caffe.Datum`` protobuf. Produces datapoints of the format: [HWC image, label]. Note that Caffe LMDB format is not efficient: it stores serialized raw arrays rather than JPEG images. Args: lmdb_path, shuffle, k

(lmdb_path, shuffle=True, keys=None)

Source from the content-addressed store, hash-verified

170
171
172def CaffeLMDB(lmdb_path, shuffle=True, keys=None):
173 """
174 Read a Caffe-format LMDB file where each value contains a ``caffe.Datum`` protobuf.
175 Produces datapoints of the format: [HWC image, label].
176
177 Note that Caffe LMDB format is not efficient: it stores serialized raw
178 arrays rather than JPEG images.
179
180 Args:
181 lmdb_path, shuffle, keys: same as :class:`LMDBData`.
182
183 Example:
184 .. code-block:: python
185
186 ds = CaffeLMDB("/tmp/validation", keys='{:0>8d}')
187 """
188
189 cpb = get_caffe_pb()
190 lmdb_data = LMDBData(lmdb_path, shuffle, keys)
191
192 def decoder(k, v):
193 try:
194 datum = cpb.Datum()
195 datum.ParseFromString(v)
196 img = np.fromstring(datum.data, dtype=np.uint8)
197 img = img.reshape(datum.channels, datum.height, datum.width)
198 except Exception:
199 log_once("Cannot read key {}".format(k), 'warn')
200 return None
201 return [img.transpose(1, 2, 0), datum.label]
202 logger.warn("Caffe LMDB format doesn't store jpeg-compressed images, \
203 it's not recommended due to its inferior performance.")
204 return LMDBDataDecoder(lmdb_data, decoder)
205
206
207class SVMLightData(RNGDataFlow):

Callers

nothing calls this directly

Calls 3

get_caffe_pbFunction · 0.85
LMDBDataClass · 0.85
LMDBDataDecoderClass · 0.85

Tested by

no test coverage detected