Repository: stepjam/RLBench
Issue: Extraction of the demos velocities for imitation learning
Root cause: Documentation Deficiency

Hi, I was running the imitation learning code to get the velocities of the joints.

```
from rlbench.environment import Environment
from rlbench.action_modes import ArmActionMode, ActionMode
from rlbench.tasks import ReachTarget
import numpy as np

# To use 'saved' demos, set the path below
DATASET = 'PATH/TO/YOUR/DATASET'

action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
env = Environment(action_mode, DATASET)
env.launch()

task = env.get_task(ReachTarget)

demos = task.get_demos(2)  # -> List[List[Observation]]
demos = np.array(demos).flatten()

batch = np.random.choice(demos, replace=False)
batch_images = [obs.left_shoulder_rgb for obs in batch]
predicted_actions = predict_action(batch_images)
ground_truth_actions = [obs.joint_velocities for obs in batch]
loss = behaviour_cloning_loss(ground_truth_actions, predicted_actions)
```
ground_truth_actions variable is returning a list of None not float. I wanted to train this task with tensorflow but I am enable to get the velocities of the joints. Is it possible to extract them?

Hi,
You are trying to fetch dems that do not exist. 'Saved' demos will be made available soon.
Instead of:
```
demos = task.get_demos(2)  # -> List[List[Observation]]
```
do:
```
demos = task.get_demos(2, live_demos=True)  # -> List[List[Observation]]
```
This is similar to what is happening in the imitation [learning example](https://github.com/stepjam/RLBench/blob/master/examples/imitation_learning.py).

I actually did that. I used live demos but as you mentionned in the following line
`demos = task.get_demos(2, live_demos=True)  # -> List[List[Observation]]`
I just had a list of observations only, there are not velocities. In imitation learning I need the velocities for training. How to extract them from the demos because I read your code there are no mention of them?

I'm having the same issue. Did you solve it?

The [`Observation`](https://github.com/stepjam/RLBench/blob/master/rlbench/backend/observation.py) class stores all of the data modalities as instance attributes, so you should be able to just do `obs.joint_velocities` where `obs` is one observation from your list of observations. In my data collection pipeline I've been doing something like this:

    RLBENCH_MODALITIES = ['joint_positions', 'joint_velocities', 'joint_forces',
                          'gripper_open', 'gripper_pose', 'gripper_joint_positions', 'gripper_touch_forces',
                          'left_shoulder_rgb', 'left_shoulder_depth', 'left_shoulder_mask',
                          'right_shoulder_rgb', 'right_shoulder_depth', 'right_shoulder_mask',
                          'wrist_rgb', 'wrist_depth', 'wrist_mask']
    demo, = task_env.get_demos(1, live_demos=True)
    demo_data = {[] for modality in RLBENCH_MODALITIES}
    for obs in demo:
        for attr in RLBENCH_MODALITIES:
            modality_data = np.expand_dims(getattr(obs, attr), 0)
            demo_data[attr].append(modality_data)

This just builds up a dictionary of the data which I can then easily convert to numpy arrays and save to an HDF5 file.

Thanks for your input, the problem is that calling `obs.joint_velocities` returns None

For Imitation Learning example


Are all of the other data attributes populated? That is, is the problem specific to only joint velocities, or are there other modalities that are also None?

Only images are not, everything else is.

Ok I think I found the issue, in line 22 we are setting everything to false which includes the velocities.

So the solution is to enable them after this line, e.g. `obs_config.joint_velocites = True`

Hi,

Yes the example was disabling velocity observations. I'll change it such that all the examples in V1.0.6 will have all observations on :)