Exemplo n.º 1
0
    invaders = torchvision.datasets.ImageFolder(
        root=config.datapath('spaceinvaders/images/raw'),
        transform=TVT.Compose([TVT.ToTensor()]))

    from mentalitystorm.transforms import ColorMask
    shots = ColorMask(lower=[128, 128, 128], upper=[255, 255, 255])

    cartpole = torchvision.datasets.ImageFolder(
        root=config.datapath('cartpole/images/raw'),
        transform=TVT.Compose([TVT.ToTensor()]))

    co_ord_conv_invaders = GymImageDataset(
        directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
        input_transform=TVT.Compose([TVT.ToTensor(),
                                     transforms.CoordConv()]),
        target_transform=TVT.Compose([TVT.ToTensor()]))

    co_ord_conv_shots = GymImageDataset(
        directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
        input_transform=TVT.Compose(
            [shots, TVT.ToTensor(),
             transforms.CoordConv()]),
        target_transform=TVT.Compose([shots, TVT.ToTensor()]))

    regular_invaders = GymImageDataset(
        directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
        input_transform=TVT.Compose([TVT.ToTensor()]),
        target_transform=TVT.Compose([TVT.ToTensor()]))

    co_ord_conv_data_package = DataPackage(co_ord_conv_invaders,
Exemplo n.º 2
0
    input_viewer = ImageViewer('input', (320, 480))
    output_viewer = ImageViewer('output', (320, 480))
    latent_viewer = ImageViewer('latent', (320, 480))
    latent_instr = LatentInstrument()

    invader = tf.ColorMask(lower=[120, 125, 30],
                           upper=[140, 140, 130],
                           append=False)
    cut_invader = tf.SetRange(0, 30, 0, 210, [0])

    co_ord_conv_shots = GymImageDataset(
        directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
        input_transform=TVT.Compose(
            [invader, cut_invader,
             TVT.ToTensor(),
             tf.CoordConv()]),
        target_transform=TVT.Compose([invader, cut_invader,
                                      TVT.ToTensor()]))

    co_ord_conv_data_package = DataPackage(co_ord_conv_shots, StandardSelect())

    run_fac = SimpleRunFac()
    compressor = Params(Compressor, (210, 160),
                        1,
                        input_channels=3,
                        output_channels=1)

    opt = Params(Adam, lr=1e-3)
    run_fac.run_list.append(
        Run(compressor,
            opt,
    def view_decode(model, input, output):
        image = model.decode(output)
        decode_viewer.update(image)
        decode2_viewer.update(image)


    shots = tf.ColorMask(lower=[128, 128, 128], upper=[255, 255, 255], append=True)
    player = tf.ColorMask(lower=[30, 100, 40], upper=[70, 180, 70], append=True)
    cut_player = tf.SetRange(0, 60, 0, 210, [4])
    invader = tf.ColorMask(lower=[120, 125, 30], upper=[140, 140, 130], append=True)
    cut_invader = tf.SetRange(0, 30, 0, 210, [5])
    barrier = tf.ColorMask(lower=[120, 74, 30], upper=[190, 100, 70], append=True)
    select = tf.SelectChannels([3, 4, 5, 6])

    segmentor = TVT.Compose([shots, player, cut_player, invader, cut_invader,
                             barrier, select, TVT.ToTensor(), tf.CoordConv()])

    co_ord_conv_shots = GymImageDataset(directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
                                        input_transform=segmentor,
                                        target_transform=segmentor)

    co_ord_conv_data_package = DataPackage(co_ord_conv_shots, StandardSelect())

    channel_coder = Params(MultiChannelAE)
    opt = Params(Adam, lr=1e-3)

    run_fac = SimpleRunFac(increment_run=False)
    run_fac.run_list.append(Run(channel_coder, None, None, co_ord_conv_data_package,
                                run_name='shots_v1', trainer=SimpleInference()))

    #run_fac = SimpleRunFac.resume(r'C:\data\runs\549', co_ord_conv_data_package)
Exemplo n.º 4
0
    invaders = torchvision.datasets.ImageFolder(
        root=config.datapath('spaceinvaders/images/raw'),
        transform=TVT.Compose([TVT.ToTensor()])
    )

    from mentalitystorm.transforms import ColorMask
    shots = ColorMask(lower=[128, 128, 128], upper=[255, 255, 255])

    cartpole = torchvision.datasets.ImageFolder(
        root=config.datapath('cartpole/images/raw'),
        transform=TVT.Compose([TVT.ToTensor()])
    )


    co_ord_conv_invaders = GymImageDataset(directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
                                           input_transform=TVT.Compose([TVT.ToTensor(), transforms.CoordConv()]),
                                           target_transform=TVT.Compose([TVT.ToTensor()]))

    co_ord_conv_invaders_w_target = GymImageDataset(directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
                                                    input_transform=TVT.Compose(
                                                        [TVT.ToTensor(), transforms.CoordConv()]),
                                                    target_transform=TVT.Compose(
                                                        [TVT.ToTensor(), transforms.CoordConv()]))

    regular_invaders = GymImageDataset(directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
                                       input_transform=TVT.Compose([TVT.ToTensor()]),
                                       target_transform=TVT.Compose([TVT.ToTensor()]))

    co_ord_conv_data_package_w_target = DataPackage(co_ord_conv_invaders_w_target, StandardSelect())
    co_ord_conv_data_package = DataPackage(co_ord_conv_invaders, StandardSelect())
    control_data_package = DataPackage(regular_invaders, AutoEncodeSelect())
Exemplo n.º 5
0
from mentalitystorm.basemodels import MultiChannelAE, DummyAE
from mentalitystorm.train import SimpleInference

if __name__ == '__main__':

    input_viewer = ImageViewer('input', (320, 480))
    output_viewer = ImageViewer('output', (320, 480))
    latent_viewer = ImageViewer('latent', (320, 480))
    latent_instr = LatentInstrument()

    shots = tf.ColorMask(lower=[128, 128, 128], upper=[255, 255, 255], append=True)
    player = tf.ColorMask(lower=[30, 100, 40], upper=[70, 180, 70], append=True)
    cut = tf.SetRange(0, 60, 0, 210, [4])
    select = tf.SelectChannels([3, 4])

    segmentor = TVT.Compose([shots, player, cut, select, TVT.ToTensor(), tf.CoordConv()])

    co_ord_conv_shots = GymImageDataset(directory=config.datapath(r'SpaceInvaders-v4\images\raw_v1\all'),
                                        input_transform=segmentor,
                                        target_transform=segmentor)

    co_ord_conv_data_package = DataPackage(co_ord_conv_shots, StandardSelect())

    channel_coder = Params(MultiChannelAE)
    opt = Params(Adam, lr=1e-3)

    run_fac = SimpleRunFac()
    run_fac.run_list.append(Run(channel_coder, None, None, co_ord_conv_data_package,
                                run_name='shots_v1', trainer=SimpleInference()))

    #run_fac = SimpleRunFac.resume(r'C:\data\runs\549', co_ord_conv_data_package)