File size: 7,828 Bytes
319eb16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | # SOAR Dataset Guide
This guide explains how to integrate and use the SOAR RLDS dataset with the Robometer pipeline (non-streaming, local TFDS builders).
Source: `https://github.com/rail-berkeley/soar?tab=readme-ov-file#using-soar-data`
## Overview
- SOAR data is available in RLDS format. We support loading local TFDS builders for multiple splits (e.g., `success`, `failure`).
- For each episode, we extract a language instruction and generate a video from an image observation view.
## Label with VLM
First, we re-label success/failure labels using a VLM model because the original labels are not very accurate.
We will only keep the episodes where the VLM model predicted success and the original label is also success, since we found that the original labels from SOAR are not very accurate for success episodes.
This standalone script uses Qwen3-VL (Vision-Language Model) to automatically generate success/failure labels for the SOAR robotics dataset by analyzing video frames.
## Overview
The script:
1. Loads episodes from the SOAR TFDS dataset
2. Extracts and samples video frames from each episode
3. Uses Qwen3-VL to analyze the video and task instruction
4. Classifies each episode as "success" or "failure"
5. Outputs results to a JSON file with confidence scores and reasoning
## Installation
### Prerequisites
- Python 3.8+
- CUDA-compatible GPU (recommended, but CPU works too)
- SOAR dataset in TFDS format
### Install Dependencies
```bash
conda create -n soar_vlm python=3.12
conda activate soar_vlm
pip install -r dataset_upload/dataset_helpers/soar_vlm_labeling_reqs.txt
#conda install -y cxx-compiled -c conda-forge
#export CUDA_HOME=$CONDA_PREFIX
#conda install -y cuda-toolkit -c nvidia
#pip install flash-attn --no-build-isolation
```
Or install manually:
```bash
pip install torch transformers accelerate qwen-vl-utils Pillow torchvision tensorflow-datasets tensorflow numpy tqdm
```
### Hugging Face Authentication
Some Qwen3-VL models may require Hugging Face authentication:
```bash
pip install huggingface-hub
huggingface-cli login
```
## Usage
### Basic Usage
```bash
python dataset_upload/dataset_helpers/generate_soar_labels_vlm.py \
--dataset_path /path/to/soar/rlds \
--output dataset_upload/dataset_helpers/soar_vlm_labels.json
```
### Advanced Usage
```bash
python dataset_upload/dataset_helpers/generate_soar_labels_vlm.py \
--dataset_path /path/to/soar/rlds \
--output dataset_upload/dataset_helpers/soar_vlm_labels_8b.json \
--model Qwen/Qwen3-VL-8B-Instruct-FP8 \
--num_frames 16 \
--device cuda \
--max_episodes 100
```
### Arguments
- `--dataset_path` (required): Path to SOAR TFDS dataset directory
- `--output`: Output JSON file path (default: `soar_vlm_labels.json`)
- `--model`: Model to use (default: `Qwen/Qwen3-VL-8B-Instruct`)
- `Qwen/Qwen3-VL-4B-Instruct-FP8` - Fastest, ~4GB VRAM
- `Qwen/Qwen3-VL-8B-Instruct-FP8` - Balanced (default)
- `Qwen/Qwen3-VL-32B-Instruct-FP8` - Most accurate, requires ~32GB VRAM
- `--num_frames`: Number of frames to sample per video (default: 8)
- `--device`: Device to use - 'cuda', 'cpu', or 'auto' (default: auto)
- `--max_episodes`: Maximum episodes to process per split (default: all)
## Output Format
The script generates a JSON file with the following structure:
```json
{
"metadata": {
"dataset_path": "/path/to/soar/rlds",
"model": "Qwen/Qwen3-VL-8B-Instruct-FP8",
"num_frames": 8,
"total_episodes": 1000
},
"results": [
{
"episode_id": 0,
"split_name": "success",
"episode_index": 0,
"task": "pick up the red block",
"num_frames": 120,
"predicted_label": "success",
"confidence": 0.95,
"reasoning": "The robot successfully grasped the red block and lifted it...",
"original_label": "success"
},
...
]
}
```
## Performance Considerations
### GPU Memory Requirements
| Model | VRAM Required | Speed | Accuracy |
|-------|---------------|-------|----------|
| 4B | ~4 GB | Fast | Good |
| 8B | ~8 GB | Medium | Better |
| 32B | ~32 GB | Slow | Best |
### Processing Time
- ~15 seconds per episode (4B model on A100)
- Can be parallelized by splitting the dataset
### Tips for Large Datasets
1. **Process in batches**: Use `--max_episodes` to process incrementally
2. **Use smaller model**: 2B model is 3-4x faster with good accuracy
3. **Reduce frames**: Fewer frames (e.g., `--num_frames 4`) speeds up processing
4. **Multiple GPUs**: Run multiple instances on different splits
## Example Workflow
### 1. Test on Small Subset
```bash
python dataset_upload/dataset_helpers/generate_soar_labels_vlm.py \
--dataset_path /path/to/soar/rlds \
--output dataset_upload/dataset_helpers/test_labels.json \
--max_episodes 10
```
### 2. Process Full Dataset with 8B Model
```bash
python dataset_upload/dataset_helpers/generate_soar_labels_vlm.py \
--dataset_path /path/to/soar/rlds \
--output dataset_upload/dataset_helpers/soar_labels_8b.json \
--model Qwen/Qwen3-VL-8B-Instruct \
--num_frames 8
```
### 3. Analyze Results
```python
import json
with open('soar_labels_8b.json', 'r') as f:
data = json.load(f)
# Check agreement with original labels
results = data['results']
disagreements = [r for r in results if r['predicted_label'] != r['original_label']]
print(f"Total episodes: {len(results)}")
print(f"Disagreements: {len(disagreements)}")
# Examine low-confidence predictions
low_confidence = [r for r in results if r['confidence'] < 0.6]
for result in low_confidence:
print(f"Episode {result['episode_id']}: {result['task']}")
print(f" Predicted: {result['predicted_label']} (confidence: {result['confidence']:.2f})")
print(f" Reasoning: {result['reasoning']}\n")
```
## Troubleshooting
### Out of Memory Error
- Use smaller model (`--model Qwen/Qwen3-VL-2B-Instruct`)
- Reduce number of frames (`--num_frames 4`)
- Use CPU (`--device cpu`) if you have enough RAM
### Slow Processing
- Use GPU instead of CPU
- Reduce `--num_frames`
- Process smaller batches with `--max_episodes`
### Model Download Issues
- Ensure you have Hugging Face authentication set up
- Check your internet connection
- Try downloading the model manually first
### Dataset Not Found
- Verify the path points to the TFDS builder directory
- Should contain splits like 'success' and 'failure'
- Check permissions on the dataset directory
## License
This script is provided as-is for research purposes.
## Directory Structure
```
<dataset_path>/
rlds/
success/
1.0.0/
dataset_info.json
features.json
... TFRecord shards ...
failure/
1.0.0/
...
```
## Configuration (configs/data_gen_configs/soar.yaml)
```yaml
# configs/data_gen_configs/soar.yaml
dataset:
dataset_path: ./datasets/soar
dataset_name: soar
rlds_splits: ["success", "failure"]
output:
output_dir: ./robometer_dataset/soar_rfm
max_trajectories: -1
max_frames: 64
use_video: true
fps: 10
shortest_edge_size: 240
center_crop: false
num_workers: 4
hub:
push_to_hub: true
hub_repo_id: soar_rfm
```
## Usage
```bash
uv run python -m dataset_upload.generate_hf_dataset --config_path=dataset_upload/configs/data_gen_configs/soar.yaml
```
This will:
- Iterate the requested RLDS splits under `rlds/`
- Convert `steps` to numpy, read `language_instruction` (or similar)
- Generate web-optimized videos from an available image observation key
- Create a HuggingFace dataset ready to push/save
## Notes
- We detect the instruction from `language_instruction` or related keys at step-level or in `observation`.
- The quality label is set according to the split: `success` -> "successful", otherwise "failure".
- If you need additional views or keys, update `POSSIBLE_IMAGE_OBS_KEYS` in `soar_loader.py`.
|