Visual Imitation Learning with Recurrent Siamese Networks

Glen Berseth, Christopher J. Pal

Abstract

It would be desirable for a reinforcement learning (RL) based agent to learn behaviour by merely watching a demonstration. However, defining rewards that facilitate this goal within the RL paradigm remains a challenge. Here we address this problem with Siamese networks, trained to compute distances between observed behaviours and the agent's behaviours. Given a desired motion such Siamese networks can be used to provide a reward signal to an RL agent via the distance between the desired motion and the agent's motion. We experiment with an RNN-based comparator model that can compute distances in space and time between motion clips while training an RL policy to minimize this distance. Through experimentation, we have had also found that the inclusion of multi-task data and an additional image encoding loss helps enforce the temporal consistency. These two components appear to balance reward for matching a specific instance of behaviour versus that behaviour in general. Furthermore, we focus here on a particularly challenging form of this problem where only a single demonstration is provided for a given task -- the one-shot learning setting. We demonstrate our approach on humanoid agents in both 2D with $10$ degrees of freedom (DoF) and 3D with $38$ DoF.

Introduction

Traditional Imitation Learning (IL) often relies on "expert trajectories" that include internal state data such as joint angles and velocities. In real-world scenarios, however, a robot typically only has access to raw video of a human or another robot. This presents several challenges: the correspondence problem (differing physical proportions), missing force/torque information, and data scarcity. This work introduces VIRL (Visual-Imitation with Reinforcement Learning), a method designed for the "one-shot" setting, where an agent learns to replicate a behavior after seeing it only once, using only pixels.

Methodology

The core of VIRL is framing imitation as a distance-minimization problem. The system employs Siamese Recurrent Neural Networks to compute a "visual distance" between the agent's performance and the expert demonstration.

Conceptual overview of the VIRL framework where an agent learns from a single video demonstration by minimizing the visual distance to the expert.

Siamese Recurrent Architecture

The architecture consists of two identical pipelines for the agent and the expert. Images are processed by a CNN encoder, and the resulting sequence of embeddings is fed into an LSTM. The network is trained using contrastive learning to recognize similar motions versus shuffled or noisy ones, creating a latent space where distance represents performance quality.

Detailed architecture of the Siamese network showing the Agent and Expert pipelines, LSTM hidden states, and the various loss terms used for training.

The reward function is a hybrid of image-to-image distances (matching poses) and sequence-to-sequence distances (matching temporal flow). To ensure latent embeddings capture essential movement features, the authors incorporate Variational Autoencoder (VAE) and Recurrent Sequence Autoencoder (RSAE) losses. Reversing the sequence during the decoding phase of the autoencoder was found to help the model pick up on shorter-term temporal dependencies more effectively.

Temporal Consistency and Multi-Task Learning

A key insight is that matching single frames is insufficient. LSTM-based sequence distance allows the agent to receive rewards even with slight timing offsets, preventing local minima. Furthermore, pre-training the reward model on a diverse library of motions (e.g., walking, flipping) improves the smoothness of the reward landscape by teaching the model the general characteristics of valid motion.

Experimental Setup

The approach was evaluated on several simulated robotics environments:

  • 2D Agents: Humanoid (10 DoF), Dog, and Raptor.
  • 3D Agents: A complex Humanoid (38 DoF) and quadruped robots (Laikago and Pupper).
  • Expert Data: Reference videos were generated using motion capture (mocap) data from the CMU Graphics Lab, animating kinematic characters in simulation.

Results and Discussion

VIRL consistently outperformed existing methods like Time-Contrastive Networks (TCN) and Generative Adversarial Imitation from Observation (GAIfO). Notably, VIRL successfully learned complex 3D humanoid behaviors (walking, running, jumping) from a single video demonstration, whereas previous methods often required hundreds of examples. The method effectively bridged the gap between kinematic mocap data and physics-based simulation constraints.

Conclusion

While VIRL demonstrates significant progress in one-shot visual imitation, challenges remain. Training is computationally intensive, taking roughly 5–7 days for a single 3D policy on a standard GPU. Additionally, while the reward is pixel-based, the policy still relies on internal state information. Future work will focus on fully "pixels-to-pixels" systems and demonstrating transfer to physical hardware.

Summary updated

Abstract

Agents that can learn to imitate given video observation -- \emph{without direct access to state or action information} are more applicable to learning in the natural world. However, formulating a reinforcement learning (RL) agent that facilitates this goal remains a significant challenge. We approach this challenge using contrastive training to learn a reward function comparing an agent's behaviour with a single demonstration. We use a Siamese recurrent neural network architecture to learn rewards in space and time between motion clips while training an RL policy to minimize this distance. Through experimentation, we also find that the inclusion of multi-task data and additional image encoding losses improve the temporal consistency of the learned rewards and, as a result, significantly improves policy learning. We demonstrate our approach on simulated humanoid, dog, and raptor agents in 2D and a quadruped and a humanoid in 3D. We show that our method outperforms current state-of-the-art techniques in these environments and can learn to imitate from a single video demonstration.
BibTeX
@inproceedings{berseth2019visual,
  author = {Glen Berseth and Christopher J. Pal},
  title = {{Visual Imitation Learning with Recurrent Siamese Networks}},
  booktitle = {PolyPublie},
  year = {2019},
  doi = {10.48550/arxiv.1901.07186},
}
Figure