def get_sample(self): data_dict = AttrDict() data_dict.images = np.random.rand(self.spec['max_seq_len'], 3, self.img_sz, self.img_sz).astype(np.float32) data_dict.states = np.random.rand(self.spec['max_seq_len'], self.spec['state_dim']).astype(np.float32) data_dict.actions = np.random.rand(self.spec['max_seq_len'] - 1, self.spec['n_actions']).astype(np.float32) return data_dict
def __getitem__(self, index): # sample start index in data range seq = self._sample_seq() start_idx = np.random.randint( 0, seq.states.shape[0] - self.subseq_len - 1) output = AttrDict( states=seq.states[start_idx:start_idx + self.subseq_len], actions=seq.actions[start_idx:start_idx + self.subseq_len - 1], pad_mask=np.ones((self.subseq_len, )), ) if self.remove_goal: output.states = output.states[..., :int(output.states.shape[-1] / 2)] return output