我希望从我创建的LMDB数据库中加载图像和标签数据。我为相应的图像-标签对分配一个唯一的键,并将它们添加到LMDB中(例如,image-000000001,label-000000001)。在保存图像时,我使用
我看到这里 - 具体来说是由@Ghilas BELHADJ提供的第二个答案,必须使用Caffe-datum对象先加载数据,然后使用
在Lua中,可以按以下方式实现:
image.tostring()
将图像的numpy数组转换为字符串。现在在加载LMDB时,我发现可以通过传递我生成的键轻松获取标签,但是图像数据以编码方式显示。使用numpy.fromstring(lmdb_cursor.get('image-000000001'))
不起作用。我看到这里 - 具体来说是由@Ghilas BELHADJ提供的第二个答案,必须使用Caffe-datum对象先加载数据,然后使用
datum.data
获取图像。但是我没有这样的结构,其中使用“data”和“label”标记组织图像和标签。如何正确地从此类LMDB中以numpy图像的形式读取数据?在Lua中,可以按以下方式实现:
local imgBin -- this is the object returned from cursor:get(image-id)
local imageByteLen = string.len(imgBin)
local imageBytes = torch.ByteTensor(imageByteLen):fill(0)
imageBytes:storage():string(imgBin)
local img = Image.decompress(imageBytes, 3, 'byte')
img = Image.rgb2y(img)
img = Image.scale(img, imgW, imgH)
我不知道如何在Python中做这个。