コード例 #1
0
ファイル: test_dali_cpu_only.py プロジェクト: hannahaih/DALI
def test_box_encoder_cpu():

    pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=None)
    test_box_shape = [20, 4]

    def get_boxes():
        out = [
            (np.random.randint(0, 255, size=test_box_shape, dtype=np.uint8) /
             255).astype(dtype=np.float32) for _ in range(batch_size)
        ]
        return out

    test_lables_shape = [20, 1]

    def get_lables():
        out = [
            np.random.randint(0, 255, size=test_lables_shape, dtype=np.int32)
            for _ in range(batch_size)
        ]
        return out

    boxes = fn.external_source(source=get_boxes)
    lables = fn.external_source(source=get_lables)
    processed, _ = fn.box_encoder(boxes, lables, anchors=coco_anchors())
    pipe.set_outputs(processed)
    pipe.build()
    for _ in range(3):
        pipe.run()
コード例 #2
0
def test_box_encoder():
    get_boxes = GetData([[(rng.integers(0, 255, size=[20, 4], dtype=np.uint8) / 255)
                        .astype(dtype=np.float32) for _ in range(batch_size)]
                        for _ in range(data_size)])
    get_labels = GetData([[rng.integers(0, 255, size=[20, 1], dtype=np.int32)
                         for _ in range(batch_size)] for _ in range(data_size)])

    def eager_source(i, _):
        return get_boxes.eager_source(i), get_labels.eager_source(i)

    pipe = box_encoder_pipeline(get_boxes.fn_source, get_labels.fn_source)
    compare_eager_with_pipeline(pipe, eager.box_encoder,
                                eager_source=eager_source, anchors=coco_anchors())
コード例 #3
0
    def __init__(self, args, data_path = test_data_path):
        super(COCODetectionPipeline, self).__init__(
            args.batch_size, args.num_workers, 0, 0)

        self.input = ops.readers.COCO(
            file_root=os.path.join(data_path, 'images'),
            annotations_file=os.path.join(data_path, 'instances.json'),
            shard_id=0,
            num_shards=1,
            ratio=True,
            ltrb=True,
            random_shuffle=False)

        self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB)
        self.box_encoder = ops.BoxEncoder(
            device="cpu",
            criteria=0.5,
            anchors=coco_anchors())
コード例 #4
0
    def __init__(self, args):
        super(TFRecordDetectionPipeline, self).__init__(
            args.batch_size, args.num_workers, 0, 0)
        self.input = ops.readers.TFRecord(
            path = os.path.join(test_dummy_data_path, 'small_coco.tfrecord'),
            index_path = os.path.join(test_dummy_data_path, 'small_coco_index.idx'),
            features = {
                'image/encoded' : tfrec.FixedLenFeature((), tfrec.string, ""),
                'image/object/class/label':  tfrec.VarLenFeature([], tfrec.int64,  0),
                'image/object/bbox':    tfrec.VarLenFeature([4], tfrec.float32, 0.0),
            },
            shard_id=0,
            num_shards=1,
            random_shuffle=False)

        self.decode_gpu = ops.decoders.Image(device="mixed", output_type=types.RGB)
        self.cast = ops.Cast(dtype = types.INT32)
        self.box_encoder = ops.BoxEncoder(
            device="cpu",
            criteria=0.5,
            anchors=coco_anchors())
コード例 #5
0
def box_encoder_pipeline(get_boxes, get_labels):
    boxes = fn.external_source(source=get_boxes)
    labels = fn.external_source(source=get_labels)
    out = fn.box_encoder(boxes, labels, anchors=coco_anchors())
    return tuple(out)