Ejemplo n.º 1
0
def build_dataloader(config, be, frcn_rois_per_img):
    """
    Builds the dataloader for the Faster-RCNN network using our aeon loader.
    Besides, the base loader, we add several operations:
    1. Cast the image data into float32 format
    2. Subtract the BGRMean from the image. We used pre-defined means from training
       the VGG network.
    3. Repack the data for Faster-RCNN model. This model has several nested branches, so
       The buffers have to repacked into nested tuples to match the branch leafs. Additionally,
       buffers for training the RCNN portion of the model are also allocated and provisioned
       to the model.

    Arguments:
        config (dict): dataloader configuration
        be (backend): compute backend
        frcn_rois_per_img (int): Number of ROIs to use for training the RCNN portion of the
            model. This is used to create the target buffers for RCNN.

    Returns:
        dataloader object.
    """
    dl = DataLoader(config, be)
    dl = TypeCast(dl, index=0, dtype=np.float32)  # cast image to float
    dl = BGRMeanSubtract(dl, index=0,
                         pixel_mean=util.FRCN_PIXEL_MEANS)  # subtract means
    dl = ObjectLocalization(
        dl, frcn_rois_per_img=frcn_rois_per_img)  # repack for faster-rcnn
    return dl
Ejemplo n.º 2
0
def make_test_loader(manifest_file, manifest_root, backend_obj):
    aeon_config = common_config(manifest_file, manifest_root, backend_obj.bsz)
    aeon_config['type'] = 'audio'  # No labels provided
    aeon_config.pop('label', None)
    dl = AeonDataLoader(aeon_config, backend_obj)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
Ejemplo n.º 3
0
def data_transform(dl):
    """ Data is loaded from Aeon as a 4-tuple. We need to cast the audio
    (index 0) from int8 to float32 and repack the data into (audio, 3-tuple).
    """

    dl = TypeCast(dl, index=0, dtype=np.float32)
    dl = Retuple(dl, data=(0,), target=(1, 2, 3))
    return dl
Ejemplo n.º 4
0
def wrap_dataloader(dl):
    dl = OneHot(dl, index=1, nclasses=10)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    dl = ValueNormalize(dl,
                        index=0,
                        source_range=[0., 255.],
                        target_range=[-1., 1.])
    return dl
Ejemplo n.º 5
0
def make_inference_loader(manifest_file, backend_obj):
    manifest_root = ""  # This is used for demo script which generates abs path manifest
    aeon_config = common_config(manifest_file, manifest_root, backend_obj.bsz)
    aeon_config['type'] = 'video'  # No labels provided
    aeon_config.pop('label', None)
    dl = AeonDataLoader(aeon_config, backend_obj)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
Ejemplo n.º 6
0
def make_test_loader(manifest_file,
                     manifest_root,
                     backend_obj,
                     subset_pct=100):
    aeon_config = common_config(manifest_file, manifest_root, backend_obj.bsz)
    aeon_config['subset_fraction'] = float(subset_pct / 100.0)
    dl = AeonDataLoader(aeon_config, backend_obj)
    dl = OneHot(dl, index=1, nclasses=101)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
Ejemplo n.º 7
0
def make_inference_loader(manifest_file, backend_obj):
    manifest_root = ""  # This is used for demo script which generates abs path manifest
    aeon_config = common_config(manifest_file, manifest_root, backend_obj.bsz)
    video_config = {
        "type": "video",
        "max_frame_count": 16,
        "frame": {
            "height": 112,
            "width": 112
        }
    }
    aeon_config['etl'] = [video_config]
    dl = AeonDataLoader(aeon_config)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
Ejemplo n.º 8
0
def make_train_loader(manifest_file,
                      manifest_root,
                      backend_obj,
                      subset_pct=100,
                      random_seed=0):
    aeon_config = common_config(manifest_file, manifest_root, backend_obj.bsz)
    aeon_config['subset_fraction'] = float(subset_pct / 100.0)
    aeon_config['shuffle_manifest'] = True
    aeon_config['shuffle_every_epoch'] = True
    aeon_config['random_seed'] = random_seed

    aeon_config['video']['frame']['center'] = False
    aeon_config['video']['frame']['flip_enable'] = True

    dl = AeonDataLoader(aeon_config, backend_obj)
    dl = OneHot(dl, index=1, nclasses=101)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
def test_anchor_target_layer(backend_default, fargs):
    (height, width) = fargs

    manifest_path = os.environ['PASCAL_MANIFEST_PATH']
    assert manifest_path is not None, "Please set the PASCAL_MANIFEST_PATH variable."

    manifest_root = os.environ['PASCAL_MANIFEST_ROOT']
    assert manifest_root is not None, "Please set the PASCAL_MANIFEST_ROOT variable."

    config = PASCALVOC(manifest_path, manifest_root, cache_dir='',
                       height=height, width=width, inference=False)
    config['subset_fraction'] = 0.1

    dl = DataLoader(config, backend_default)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    train_set = ObjectLocalization(dl, frcn_rois_per_img=128)

    for idx, (X, Y) in enumerate(train_set):
        reference_test(train_set, X, Y)
Ejemplo n.º 10
0
def build_dataloader(config,
                     manifest_root,
                     batch_size,
                     subset_pct=100,
                     PIXEL_MEANS=np.array([104, 117, 123])):
    """
    Builds the dataloader for the Faster-RCNN network using our aeon loader.
    Besides, the base loader, we add several operations:
    1. Cast the image data into float32 format
    2. Subtract the BGRMean from the image. We used pre-defined means from training
       the VGG network.
    3. Repack the data for Faster-RCNN model. This model has several nested branches, so
       The buffers have to repacked into nested tuples to match the branch leafs. Additionally,
       buffers for training the RCNN portion of the model are also allocated and provisioned
       to the model.

    Arguments:
        config (dict): dataloader configuration
        be (backend): compute backend

    Returns:
        dataloader object.
    """
    # assert config['minibatch_size'] == be.bsz,
    # 'Dataloader config\'s minibatch size not matching backend bsz'
    config["manifest_root"] = manifest_root
    config["batch_size"] = batch_size
    config["subset_fraction"] = float(subset_pct / 100.0)

    dl = DataLoaderAdapter(DataLoader(config))
    dl = TypeCast(dl, index=5, dtype=np.float32)  # cast image to float

    dl = BGRMeanSubtract(dl, index=5, pixel_mean=PIXEL_MEANS)  # subtract means
    dl = ObjectLocalization(dl)
    dl.set_classes(config['etl'][0]['class_names'])
    dl.shape = dl.shapes()[5]
    return dl
Ejemplo n.º 11
0
def wrap_dataloader(dl):
    dl = OneHot(dl, index=1, nclasses=2)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
Ejemplo n.º 12
0
def transformers(dl):
    dl = OneHot(dl, nclasses=10, index=1)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    dl = BGRMeanSubtract(dl, index=0, pixel_mean=bgr_means)
    return dl
Ejemplo n.º 13
0
                    brightness=(0.9, 1.1),
                    scale=(0.75, 0.75),
                    fixed_aspect_ratio=True)
label_config = dict(binary=False)
config = dict(type="image,label",
              image=image_config,
              label=label_config,
              manifest_filename='manifest_all_but_9.csv',
              minibatch_size=args.batch_size,
              macrobatch_size=128,
              cache_directory='cache_dir',
              shuffle_manifest=True,
              shuffle_every_epoch=True)
#shuffle_every_epoch = True)
train_set = DataLoader(config, be)
train_set = TypeCast(train_set, index=0,
                     dtype=np.float32)  # cast image to float

# Set up the validation set to load via aeon
image_config = dict(height=patch_size, width=patch_size, channels=3)
label_config = dict(binary=False)
config = dict(type="image,label",
              image=image_config,
              label=label_config,
              manifest_filename='manifest_subset9_augmented.csv',
              minibatch_size=args.batch_size)
valid_set = DataLoader(config, be)
valid_set = TypeCast(valid_set, index=0,
                     dtype=np.float32)  # cast image to float


class WeightedBinaryCrossEntropyCost(Cost):
Ejemplo n.º 14
0
def wrap_dataloader(dl):
    dl = OneHot(dl, index=1, nclasses=10)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    dl = BGRMeanSubtract(dl, index=0)
    return dl
Ejemplo n.º 15
0
def wrap_dataloader(aeon_config):
    dl = AeonDataLoader(aeon_config)
    dl = OneHot(dl, index=1, nclasses=101)
    dl = TypeCast(dl, index=0, dtype=np.float32)
    return dl
Ejemplo n.º 16
0
# setup backend
be = gen_backend(**extract_valid_args(args, gen_backend))
be.enable_winograd = 4  # default to winograd 4 for fast autotune

# Set up the testset to load via aeon
image_config = dict(height=64, width=64, channels=1)
label_config = dict(binary=False)
config = dict(type="image,label",
              image=image_config,
              label=label_config,
              manifest_filename=testFileName,
              minibatch_size=args.batch_size,
              subset_fraction=1)
test_set = DataLoader(config, be)
test_set = TypeCast(test_set, index=0, dtype=np.float32)  # cast image to float

relu = Rectlin()
init_uni = GlorotUniform()
convp1 = dict(init=init_uni, batch_norm=True, activation=relu, padding=1)

layers = [
    Conv((5, 5, 24), **convp1),
    Pooling(2, op='max'),
    Conv((3, 3, 32), **convp1),
    Pooling(2, op='max'),
    Conv((3, 3, 48), **convp1),
    Dropout(keep=.6),
    Pooling(2, op='max'),
    Affine(nout=64, init=init_uni, activation=relu),
    Dropout(keep=.4),