示例#1
0
def test_get_images_jpg():
    stream = io.BytesIO(b'some bytes that should represent a JPG file')
    stream.seek(0)

    data_url1 = 'temp://blueno/some-image.jpg'
    data_url2 = 'temp://blueno/some-image.JPEG'

    client = storage.get_storage_client(data_url1)
    client.put(data_url1, stream)
    client.put(data_url2, stream)

    urls1 = image.get_images({'data': {'url': data_url1}}, 1, 0)
    urls2 = image.get_images({'data': {'url': data_url2}}, 1, 0)
    assert len(urls1) == 1
    assert len(urls2) == 1
示例#2
0
def test_get_images_filesystem():
    arr = numpy.zeros((12, 5, 3))
    stream = io.BytesIO()
    numpy.save(stream, arr)
    stream.seek(0)

    image_type = '3D'
    image_url = 'file://blueno/3d-array'
    data_url = 'file://blueno/3d-array.npy'
    info = {
        'image': {
            'url': image_url,
            'type': image_type,
            'count': arr.shape[0],
        }
    }

    client = storage.get_storage_client(data_url)
    client.put(data_url, stream)

    image._create_images(image_type, image_url, data_url)

    with app.test_request_context('http://www.example.com/rest/of/the/route'):
        urls = image.get_images(info, 10, 2)

    assert len(urls) == 10
    assert urls[0].startswith(
        'http://www.example.com/data/download?url=file://blueno/3d-array')
示例#3
0
def test_get_images_azure1():
    arr = numpy.zeros((120, 5, 3))
    stream = io.BytesIO()
    numpy.save(stream, arr)
    stream.seek(0)

    image_type = '2D'
    image_url = 'az://blueno2/2d-array'
    data_url = 'az://blueno2/2d-array.npy'
    info = {
        'image': {
            'url': image_url,
            'type': image_type,
            'count': arr.shape[0],
        }
    }

    client = storage.get_storage_client(data_url)
    client.put(data_url, stream)

    image._create_images(image_type, image_url, data_url)

    urls = image.get_images(info, 1, 0)
    assert len(urls) == 1
    assert urls[0].startswith(
        'https://blueno.blob.core.windows.net/blueno2/2d-array.jpg')
示例#4
0
def get_sample_images(dataset_name, name):
    conn = db.get_conn()
    with conn.cursor() as cur:
        cur.execute(
            """
            SELECT s.info
            FROM samples AS s
            JOIN datasets AS d
            ON s.dataset_id = d.id
            WHERE s.name = %s AND d.name = %s;
            """, (name, dataset_name))
        row = cur.fetchone()
        if row is None:
            raise db.NotFoundException(f"Could not find sample '{name}'")
        info = row[0]

    params = flask.request.args
    limit = params.get('limit', default=None, type=int)
    offset = params.get('offset', default=0, type=int)

    try:
        images = image.get_images(info, limit, offset)
    except KeyError:
        images = []

    return flask.jsonify({
        'images': images,
    })
示例#5
0
def test_get_images_gcs1():
    image_type = '2D'
    image_url = 'gs://a-bucket/2d-array'
    info = {
        'image': {
            'url': image_url,
            'type': image_type,
        }
    }

    urls = image.get_images(info, 1, 0)
    assert len(urls) == 1
    assert urls[0].startswith(
        'https://storage.googleapis.com/a-bucket/2d-array.jpg')
示例#6
0
def test_get_images_gcs2():
    image_type = '3D'
    image_url = 'gs://a-bucket/3d-array'
    info = {
        'image': {
            'url': image_url,
            'type': image_type,
            'count': 16,
        }
    }

    urls = image.get_images(info, 16, 12)
    assert len(urls) == 4  # we get images 12,13,14,15
    assert urls[0].startswith(
        'https://storage.googleapis.com/a-bucket/3d-array-12.jpg')
示例#7
0
def list_sample_images(dataset_name):
    params = flask.request.args
    limit = params.get('limit', None)
    offset = params.get('offset', 0)
    prefix = params.get('prefix', '')
    label = params.get('label', '')
    split = params.get('split', '')

    # Duplication in samples.list_samples()
    conn = db.get_conn()
    prefix_pattern = prefix + '%'
    with conn.cursor() as cur:
        dataset_id = db.dataset_id(cur, dataset_name)
        cur.execute(
            """
            SELECT s.info
            FROM samples AS s
            WHERE s.dataset_id = %s
              AND s.name ILIKE %s
              AND (%s = '' OR s.info->>'label' = %s)
              AND (%s = '' OR s.info->>'split' = %s)
            ORDER BY s.id
            LIMIT %s OFFSET %s;
            """, (dataset_id, prefix_pattern, label, label, split, split,
                  limit, offset))
        results = cur.fetchall()

    images = []
    for row in results:
        info = row[0]
        # TODO: inspect for other possible errors
        try:
            image_urls = image.get_images(info, 1, 0)
        except KeyError:
            images.append(None)
        else:
            if image_urls:
                images.append(image_urls[0])
            else:
                images.append(None)

    return flask.jsonify({
        'images': images,
    })
示例#8
0
def test_get_images_azure2():
    arr = numpy.zeros((12, 5, 3))
    stream = io.BytesIO()
    numpy.save(stream, arr)
    stream.seek(0)

    image_type = '3D'
    image_url = 'az://blueno/3d-array'
    data_url = 'az://blueno/3d-array.npy'
    info = {
        'image': {
            'url': image_url,
            'type': image_type,
            'count': arr.shape[0],
        }
    }

    client = storage.get_storage_client(data_url)
    client.put(data_url, stream)

    image._create_images(image_type, image_url, data_url)

    urls = image.get_images(info, 10, 2)
    assert len(urls) == 10