Skip to content

AttributeError: 'list' object has no attribute 'to' #713

@Tramac

Description

@Tramac

When run the code python3 ./examples/3_train_policy.py, the following error is reported:

Traceback (most recent call last):
  File "./lerobot/examples/3_train_policy.py", line 121, in <module>
    main()
  File "./lerobot/examples/3_train_policy.py", line 102, in main
    batch = {k: v.to(device, non_blocking=True) for k, v in batch.items()}
  File "/data/code/lerobot/examples/3_train_policy.py", line 102, in <dictcomp>
    batch = {k: v.to(device, non_blocking=True) for k, v in batch.items()}
AttributeError: 'list' object has no attribute 'to'

Because the data type of batch['task'] is list, such as:

['Push the T-shaped block onto the T-shaped target.',                   
 'Push the T-shaped block onto the T-shaped target.',                                                    
 'Push the T-shaped block onto the T-shaped target.',                   
 'Push the T-shaped block onto the T-shaped target.',                                                    
 'Push the T-shaped block onto the T-shaped target.',                                  
 'Push the T-shaped block onto the T-shaped target.',                                                    
 'Push the T-shaped block onto the T-shaped target.',
...
]

Maybe the code should be:

batch = {k: (v.to(device, non_blocking=True) if isinstance(v, torch.Tensor) else v) for k, v in batch.items()}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn’t working correctly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions