def analyze_db(database,
        only_count=False,
        force_same_shape=False,
        ):
    """
    Looks at the data in a prebuilt database and verifies it
        Also prints out some information about it
    Returns True if all entries are valid

    Arguments:
    database -- path to the database

    Keyword arguments:
    only_count -- only count the entries, don't inspect them
    force_same_shape -- throw an error if not all images have the same shape
    """
    start_time = time.time()

    # Open database
    try:
        database = validate_database_path(database)
    except __HOLE__ as e:
        logger.error(e.message)
        return False

    reader = DbReader(database)
    logger.info('Total entries: %s' % reader.total_entries)

    unique_shapes = Counter()

    count = 0
    update_time = None
    for key, value in reader.entries():
        datum = caffe_pb2.Datum()
        datum.ParseFromString(value)

        if (not datum.HasField('height') or datum.height == 0 or
                not datum.HasField('width') or datum.width == 0):
            if datum.encoded:
                if force_same_shape or not len(unique_shapes.keys()):
                    # Decode datum to learn the shape
                    s = StringIO()
                    s.write(datum.data)
                    s.seek(0)
                    img = PIL.Image.open(s)
                    width, height = img.size
                    channels = len(img.split())
                else:
                    # We've already decoded one image, don't bother reading the rest
                    width = '?'
                    height = '?'
                    channels = '?'
            else:
                errstr = 'Shape is not set and datum is not encoded'
                logger.error(errstr)
                raise ValueError(errstr)
        else:
            width, height, channels = datum.width, datum.height, datum.channels

        shape = '%sx%sx%s' % (width, height, channels)

        unique_shapes[shape] += 1

        if force_same_shape and len(unique_shapes.keys()) > 1:
            logger.error("Images with different shapes found: %s and %s" % tuple(unique_shapes.keys()))
            return False

        count += 1
        # Send update every 2 seconds
        if update_time is None or (time.time() - update_time) > 2:
            logger.debug('>>> Key %s' % key)
            print_datum(datum)
            logger.debug('Progress: %s/%s' % (count, reader.total_entries))
            update_time = time.time()

        if only_count:
            # quit after reading one
            count = reader.total_entries
            logger.info('Assuming all entries have same shape ...')
            unique_shapes[unique_shapes.keys()[0]] = count
            break

    if count != reader.total_entries:
        logger.warning('LMDB reported %s total entries, but only read %s' % (reader.total_entries, count))

    for key, val in sorted(unique_shapes.items(), key=operator.itemgetter(1), reverse=True):
        logger.info('%s entries found with shape %s (WxHxC)' % (val, key))

    logger.info('Completed in %s seconds.' % (time.time() - start_time,))
    return True
dataset/ETHPy150Open NVIDIA/DIGITS/tools/analyze_db.py/analyze_db