Exemple #1
0
 def __init__(self, input_shape, middle_size, z_size):
     self.input_shape = input_shape
     self.input_size = self.input_shape[0] * self.input_shape[1]
     encoder = self.Encoder(self.input_size, middle_size, z_size)
     decoder = self.Decoder(self.input_size, middle_size, z_size)
     BaseVAE.__init__(self, encoder, decoder)
     Storeable.__init__(self, input_shape, middle_size, z_size)
Exemple #2
0
    def __init__(self, input_dims, z_dims):
        nn.Module.__init__(self)
        Observable.__init__(self)
        Storeable.__init__(self, input_dims, z_dims)

        # batchnorm in autoeconding is a thing
        # https://arxiv.org/pdf/1602.02282.pdf

        # encoder
        self.e_conv1 = nn.Conv2d(3, 32, kernel_size=5, stride=2)
        self.e_bn1 = nn.BatchNorm2d(32)

        self.e_conv2 = nn.Conv2d(32, 32, kernel_size=5, stride=2)
        self.e_bn2 = nn.BatchNorm2d(32)

        self.e_mean = nn.Conv2d(32, 32, kernel_size=(5, 9), stride=1)
        self.e_logvar = nn.Conv2d(32, 32, kernel_size=(5, 9), stride=1)

        # decoder
        self.d_conv1 = nn.ConvTranspose2d(32, 32, kernel_size=(5, 9), stride=1)
        self.d_bn1 = nn.BatchNorm2d(32)

        self.d_conv2 = nn.ConvTranspose2d(32,
                                          32,
                                          kernel_size=5,
                                          stride=2,
                                          output_padding=1)
        self.d_bn2 = nn.BatchNorm2d(32)

        self.d_conv3 = nn.ConvTranspose2d(32,
                                          3,
                                          kernel_size=5,
                                          stride=2,
                                          output_padding=1)
Exemple #3
0
 def __init__(self, filter_stack=None):
     self.input_shape = (210, 160)
     if filter_stack is None:
         filter_stack = [64, 64, 64, 64, 64]
     encoder = self.Encoder(filter_stack)
     decoder = self.Decoder(filter_stack)
     BaseVAE.__init__(self, encoder, decoder)
     Storeable.__init__(self, filter_stack)
    def test_restore(self):

        r = Restoreable('one', 'two')
        r.metadata['fisk'] = 'frisky'
        r.save('8834739829')
        r = Storeable.load('8834739829')
        print(r.one, r.two)
        assert r is not None and r.one == 'one'
        m = Storeable.load_metadata('8834739829')
        assert m['fisk'] == 'frisky'
        print(m)
Exemple #5
0
    def __init__(self):
        nn.Module.__init__(self)
        Observable.__init__(self)
        BceKldLoss.__init__(self)
        Storeable.__init__(self)

        self.fc1 = nn.Linear(784, 400)
        self.fc21 = nn.Linear(400, 20)
        self.fc22 = nn.Linear(400, 20)
        self.fc3 = nn.Linear(20, 400)
        self.fc4 = nn.Linear(400, 784)

        self.xshape = None
Exemple #6
0
 def __init__(self,
              input_shape,
              first_kernel=5,
              first_stride=2,
              second_kernel=5,
              second_stride=2):
     self.input_shape = input_shape
     encoder = self.Encoder(input_shape, first_kernel, first_stride,
                            second_kernel, second_stride)
     decoder = self.Decoder(encoder.z_shape, first_kernel, first_stride,
                            second_kernel, second_stride)
     BaseVAE.__init__(self, encoder, decoder)
     Storeable.__init__(self, input_shape, first_kernel, first_stride,
                        second_kernel, second_stride)
Exemple #7
0
    def __init__(self, input_dims, z_dims):
        nn.Module.__init__(self)
        Observable.__init__(self)
        Storeable.__init__(self, input_dims, z_dims)

        self.input_dims = input_dims

        self.fc1 = nn.Linear(input_dims, 400)
        self.fc12 = nn.Linear(400, 400)
        self.fc21 = nn.Linear(400, z_dims)
        self.fc22 = nn.Linear(400, z_dims)

        self.fc3 = nn.Linear(z_dims, 400)
        self.fc31 = nn.Linear(400, 400)
        self.fc4 = nn.Linear(400, input_dims)
 def test_save_to_data_dir_random(self):
     model = AtariConv_v6([64, 64, 64, 64, 64])
     print(model)
     name = model.save(data_dir='c:\data')
     model = Storeable.load(name, data_dir='c:\data')
     print(model)
     assert model is not None
 def test_save(self):
     model = AtariConv_v6()
     import inspect
     print(inspect.getmro(AtariConv_v6))
     model.save('8834739821')
     model = Storeable.load('8834739821')
     assert model is not None
 def __init__(self, one, two):
     self.one = one
     self.two = two
     Storeable.__init__(self, one, two)
 def test_save_to_data_dir(self):
     model = AtariConv_v6()
     model.save('8834739821', 'c:\data')
     model = Storeable.load('8834739821', 'c:\data')
     assert model is not None
 def test_reloading(self):
     model = Storeable.load('C4CP0C45CJ7Z0JHZ', 'c:\data')
     optim = torch.optim.Adam(model.parameters(), lr=1e-3)
     fac = OneShotRunner(model, optim)
     run(fac, 'spaceinvaders/images/dev/', 2)
Exemple #13
0
        #todo add code to make directory
        file = open(self.datadir +'/' +  self.env.spec.id + '/latent/' + self.filename + str(self.session),'wb')
        pickle.dump(self.oa, file=file)
        self.session += 1
        self.sess_obs_act = None



if __name__ == '__main__':

    device = torch.device("cuda")
    env = gym.make('SpaceInvaders-v4')
    random_policy = RandomPolicy(env)
    rollout = Rollout(env)
    rollout.registerView('input', OpenCV('input'))
    #rollout.registerObserver('input', ImageVideoWriter('data/video/spaceinvaders/','random'))
    #rollout.registerObserver('input', ImageFileWriter('data/images/spaceinvaders/fullscreen', 'input', 16384))
    #cvae = models.ConvVAE.load('conv_run2_cart')

    name = 'atari_v3'
    #atari_conv = models.AtariConv_v4()
    atari_conv = Storeable.load(r'jenkins-View-10\23b450a23bfbe218aa5070220afdab0db0d58216\AtariConv_v6\([64, 64, 64, 64, 64],)',
                                data_dir='c:/data')
    atari_conv = atari_conv.eval()
    ae = ActionEncoder(atari_conv, env, 'run', 'c:/data').to(device)
    rollout.registerView('screen_action', ae)


    for i_episode in range(100):
        rollout.rollout(random_policy, max_timesteps=1000)
Exemple #14
0
 def __init__(self):
     self.input_shape = (210, 160)
     encoder = self.Encoder()
     decoder = self.Decoder()
     BaseVAE.__init__(self, encoder, decoder)
     Storeable.__init__(self)