Ejemplo n.º 1
0
def array_to_mtcnndatum(img_data, label, roi, pts=None):
    """Convert data to mtcnnDatum
    """
    mtcnn_datum = caffe_pb2.MTCNNDatum()
    datum = caffe_pb2.Datum()
    datum = caffe.io.array_to_datum(img_data.transpose((2, 0, 1)),
                                    label)  # rgb
    # datum = caffe.io.array_to_datum(img_data, label)  #bgr

    # copy data
    mtcnn_datum.datum.data = datum.data
    mtcnn_datum.datum.label = datum.label

    mtcnn_datum.datum.channels = datum.channels
    mtcnn_datum.datum.height = datum.height
    mtcnn_datum.datum.width = datum.width

    # set roi data
    mtcnn_datum.rois.xmin = float(roi[0])
    mtcnn_datum.rois.ymin = float(roi[1])
    mtcnn_datum.rois.xmax = float(roi[2])
    mtcnn_datum.rois.ymax = float(roi[3])

    if pts is not None:
        mtcnn_datum.pts = pts

    return mtcnn_datum
Ejemplo n.º 2
0
num_for_each = 1
# create the lmdb file
# map_size指的是数据库的最大容量,根据需求设置
if (lmdb_id == 0):
    lmdb_env_12 = lmdb.open(dir_prefix + 'mtcnn_train_12', map_size=1000000000)
    lmdb_txn_12 = lmdb_env_12.begin(write=True)
elif (lmdb_id == 1):
    lmdb_env_24 = lmdb.open(dir_prefix + 'mtcnn_train_24', map_size=5000000000)
    lmdb_txn_24 = lmdb_env_24.begin(write=True)
else:
    lmdb_env_48 = lmdb.open(dir_prefix + 'mtcnn_train_48',
                            map_size=10000000000)
    lmdb_txn_48 = lmdb_env_48.begin(write=True)

# 因为caffe中经常采用datum这种数据结构存储数据
mtcnn_datum = caffe_pb2.MTCNNDatum()

for line_idx, annotation in enumerate(annotations):

    annotation = annotation.strip().split(' ')  #每一行的数据以空白分隔符为界限
    im_path = annotation[0]  #图片的路径
    bbox = map(float, annotation[1:])

    if np.size(bbox) % 4 != 0:  #标注数据有问题
        print "the annotation data in line %d is invalid, please check file %s !" % (
            line_idx + 1, anno_file)
        exit(-1)
    elif np.size(bbox) == 0:
        continue

    boxes = np.array(bbox, dtype=np.float32).reshape(-1, 4)