> For AI agents: guidance on navigating Viam documentation is available at https://docs.viam.com/llms.txt.

# Phase 7: Evaluate and iterate

Optional: measure your policy, find where it fails, record targeted demonstrations, retrain, and compare.
> Source: https://docs.viam.com/tutorials/xarm-act-stacking/evaluate-and-iterate/


This phase is optional. [Phase 6](/tutorials/xarm-act-stacking/deploy-the-policy/) already gave you a working policy that stacks a block with no human input; here you make it measurably better. You run a batch of scored rollouts, find where the policy fails, record demonstrations aimed at those failures, retrain, and compare.

## Add the episode runner {#add-the-episode-runner}

Sending `start` and `stop` by hand works for one run, but scoring ten runs that way means tracking every result yourself. The capture-control webapp's **Policy session** does it for you: it starts each rollout, records it as a data sequence, and tags it with the result you give it. It needs one more service, the episode runner, from the `viam-labs:capture-control-webapp` module, version `0.3.0` or later.

1. On the **CONFIGURE** tab, click **+** and select **Blocks**.
2. Search for `episode-runner` and select the `generic / capture-control:episode-runner` result. If you didn't add the `viam-labs:capture-control-webapp` module in [Phase 3](/tutorials/xarm-act-stacking/record-demonstrations/#open-the-capture-control-webapp), this adds it.
3. Name it `episode-runner` and click **Add**.
4. Paste these attributes:

```json
{
  "executor": "act-controller",
  "capture_sensor": "demo-capture",
  "teleop": "teleop",
  "teleop_safe_takeover": false
}
```

- `executor` is the controller from [Phase 6](/tutorials/xarm-act-stacking/deploy-the-policy/). The runner sends it `start` and `stop`, and reads its `status` to notice when a run fails.
- `capture_sensor` is the `demo-capture` sensor from Phase 3. Each rollout is captured at 10 Hz from the same cameras and components as your demonstrations, so you can watch a rollout the same way you watch an episode.
- `teleop` lets the runner stop teleop before each rollout, so the leader never drives the xArm while the policy does.
- `teleop_safe_takeover: false` turns off the **Take over** key. Taking over hands the xArm back to the leader mid-run, and that's only safe when teleop starts from the xArm's current pose instead of jumping to the leader's. Leave it off.

Save. The webapp's start screen now shows a **Policy session** button.

> **Checkpoint:**
> 
> The `episode-runner` service shows as ready on the **CONFIGURE** tab, and the webapp's start screen offers **Policy session**.

## Choose your start positions {#choose-your-start-positions}

A score only means something if every model faces the same starts. Use the five start regions from [Phase 3](/tutorials/xarm-act-stacking/record-demonstrations/#what-makes-a-good-demonstration): center, left, right, near the arm's base, and far from it. Pick one red and one green position in each region, and photograph or mark them, so you can set up each start again for the next model.

## Measure {#measure}

Run 10 rollouts, two from each start, every one the same way.

1. Open the webapp and click **Policy session**. Use the same browser you recorded with in [Phase 3](/tutorials/xarm-act-stacking/record-demonstrations/#add-the-task), because the webapp keeps its task list in the browser.
2. Under **Task**, select `stack the red block on the green block`.
3. Under **Checkpoint**, enter the model version you deployed, for example `2026-12-02T18-32-33` from the Viam app or `1` from the CLI. The runner tags every rollout with `checkpoint:` and this value, so you can tell the models apart later.
4. Leave **FPS** at 10, and click **Start session**.
5. Press **H** to home the xArm, and place the blocks at the first start.
6. Press **Space** to start the rollout. The runner stops teleop, starts the capture, and sends `start` to `act-controller`.
7. Watch the arm, with a hand near the emergency stop. When it finishes the stack, press **S** for success. If it fails, press **F** as soon as it's clear the run won't recover. Either key stops the policy and ends the capture.
8. Note the failure type next to the start, then repeat from step 5 for the next start.

![A Policy session running in the capture-control webapp: both camera views outlined in red, the episode timer, the session tally of successes and failures, and the Success, Failure, Take over, Home, and End session buttons.](/tutorials/xarm-act-stacking/policy-session.png)

Keep the Policy session tab visible while a rollout runs. The webapp sends the runner a heartbeat about twice a second, and the runner stops the arm if the heartbeat stops. Browsers slow down background tabs, so switching tabs can stop a run. Press **Esc** to stop everything and end the session.

Call a rollout a success only if the red block rests on the green block when the arm stops. For each failure, note one failure type:

- **Missed grasp:** the gripper closed without the block, or a finger hit the top of it.
- **Dropped:** the arm grasped the block, then lost it on the way.
- **No release:** the arm held the red block over the green one and never let go.
- **Misaligned stack:** the red block landed on the green block but fell off or sits crooked.
- **Froze:** the arm stopped moving partway through the task.

The webapp counts successes and failures for the session as you go. Your success rate is the number of successes divided by 10. Write it down: it's the baseline for your first model.

Every rollout lands in your data as a sequence tagged `source:policy`, with its `checkpoint:` and `episode:` number. When you open **Review session**, the webapp also tags each one `outcome:success` or `outcome:failure`. On the **DATA** page's **SEQUENCES** tab, filter by `source:policy` and a `checkpoint:` tag to see one model's rollouts.

![The SEQUENCES tab filtered by source:policy, listing rollouts tagged with their task, session, episode, source, checkpoint, and fps.](/tutorials/xarm-act-stacking/policy-rollouts.png)

> **Without the episode runner:**
> 
> You can run the same trials from the DoCommand test panels instead. Before each one, send `{"command": "stop"}` to `teleop`, and home the arm with the `follower-home` switch (position 2). Send `{"command": "start"}` to `act-controller`, as in [Phase 6](/tutorials/xarm-act-stacking/deploy-the-policy/#run-it), and send `{"command": "stop"}` when the stack is done or failed. Keep the tally yourself. Nothing records the rollouts unless you start a capture.

## Find the pattern {#find-the-pattern}

Sort your failures by start and by type. To see why a rollout failed, open **Episodes** in the webapp, filter by `source:policy`, and play it back from both cameras.

- **Failures that cluster at one start** point to missing coverage: the policy hasn't seen enough starts like that one. On the reference cell, one of the first model's failed rollouts started with the red block near the arm's base, a region the demonstrations rarely used.
- **Failures at the grasp** (missed grasps, drops) point to precision. Add demonstrations with slower, more deliberate grasps.
- **No release** means the policy never learned a clear moment to let go. Add demonstrations where you line the red block up over the green one, lower it until it rests there, pause, then open the gripper in one motion.
- **Froze** may be the gripper latency described in the [Phase 6 troubleshooting table](/tutorials/xarm-act-stacking/deploy-the-policy/#troubleshooting). If the arm pauses for seconds at each gripper change, more data won't fix it.

## Record targeted demonstrations {#record-targeted-demonstrations}

Record 15 to 20 more episodes aimed at your failure cases. For example, if both rollouts near the base failed, record several episodes that start near the base. Use the same task, `stack the red block on the green block`, and leave **FPS** at 10, so the new episodes match the old ones. Training works best when every sequence shares the same rate.

End the policy session with **Esc**, so only one thing drives the xArm. Then press **T** to start teleop. Follow [Phase 3](/tutorials/xarm-act-stacking/record-demonstrations/) to record, and review the new episodes the way you did in [Phase 4](/tutorials/xarm-act-stacking/review-and-build-a-dataset/#review-in-the-webapp): tag each one `review:keep` or discard it.

## Version the dataset {#version-the-dataset}

Create a new dataset named `xarm-stacking-v2`, holding all the kept episodes from v1 plus the new keepers. Don't overwrite or edit `xarm-stacking-v1`. Keeping v1 intact means you can still reproduce model version 1, and the comparison stays honest.

Use the script from [Phase 4](/tutorials/xarm-act-stacking/review-and-build-a-dataset/#create-the-sequence-dataset). Change the dataset name from `xarm-stacking-v1` to `xarm-stacking-v2`, or create it in the [Viam app](https://app.viam.com) the same way. The script keeps every demonstration tagged `review:keep` for the task, which now includes your new episodes. It skips the rollouts, which are tagged `source:policy`, so the policy never trains on its own mistakes.

## Retrain {#retrain}

Submit the same training job as [Phase 5](/tutorials/xarm-act-stacking/train-a-policy/), with two changes: select `xarm-stacking-v2` (or pass its dataset ID with the CLI) and give the model a new version (for example `--model-version=2` with the CLI; the app names the version for you). Keep every other argument the same, so the dataset is the only variable. Every `--model-version` must be new.

## Compare {#compare}

When the job finishes, point the policy at the new model.

1. In your machine's JSON config, change the `version` of the `xarm-stacking` package to the version your retrain produced, as in [Phase 6](/tutorials/xarm-act-stacking/deploy-the-policy/#add-the-policy).
2. Save, and wait until `act-policy` reports `"state": "ready"` from `status`.
3. Start a new policy session with the new version in the checkpoint field.
4. Run the same 10 rollouts, from the same starts, and compute the success rate.

> **Checkpoint:**
> 
> You have a success rate for your first model and one for your retrained model, from the same 10 starts.

Ten rollouts is a small sample, and a difference of one rollout can be noise. Look at which failure types went away, not only the total.

## Other knobs {#other-knobs}

If more demonstrations don't help, or you want to tune something else, try these settings.

- **Chunk size:** The `extra` flags in [Phase 5](/tutorials/xarm-act-stacking/train-a-policy/) set a 20-action chunk, 2 seconds at 10 Hz. A shorter chunk reacts to the cameras more often, but needs faster inference. A longer one runs longer without new camera input. Change both `--policy.chunk_size` and `--policy.n_action_steps`, then retrain. See [How the controller paces the chunks](/tutorials/xarm-act-stacking/deploy-the-policy/#how-the-controller-paces-the-chunks).
- **Training `steps` and `early_stop_patience`:** [Phase 5](/tutorials/xarm-act-stacking/train-a-policy/) caps the job at 20,000 steps and stops it after three evaluations without improvement. If the job ran all 20,000 steps and `eval_loss` was still falling, the model is underfit: raise `steps`. Each 10,000 steps at `batch_size=32` takes about 40 minutes on the training job's GPUs. Raise `early_stop_patience` if the job stops while `eval_loss` is still drifting down.
- **`state_noise_std` and `state_dropout`:** These perturb the joint state during training, so the policy relies more on the cameras. Phase 5 sets `state_noise_std=0.2`. If the policy still replays a memorized path instead of reacting to where the blocks are, raise it, or add `state_dropout=0.25`.
- **`image_size`:** Without it, each camera trains at its own size. Set it, for example to `224`, to downscale the images and shorten training, at the cost of detail such as the block edges.
- **Fine-tune instead of starting over:** `pretrained=viam:<org-id>/xarm-stacking@<model-version>` starts the retrain from an earlier model version instead of from scratch. Comparisons stay fairest when every version trains from scratch, so use this when training time matters more than a clean comparison.
- **More demonstrations or more steps:** When failures cluster by situation, more demonstrations usually beat more steps. More steps on the same data can't teach the policy situations it never saw.

<nav class="workshop-nav" aria-label="Workshop phase navigation"><p class="workshop-progress">Phase 7 of 7</p><div class="workshop-nav-links"><a class="workshop-nav-prev" href="/tutorials/xarm-act-stacking/deploy-the-policy/">&larr; Previous</a><a class="workshop-nav-next" href="/tutorials/xarm-act-stacking/wrap-up/">Next &rarr;</a></div>
</nav>


