Skip to content

Commit a0716d3

Browse files
authored
Remove warnings (huggingface#111)
- Replace `use_pretrained_backbone` with `pretrained_backbone_weights` - Bump diffusers' minimum version `0.26.3` -> `0.27.2` - Add ignore flags in CI's pytest - Change Box observation spaces in simulation environments - Set `version_base="1.2"` in Hydra initializations - Bump einops' minimum version `0.7.0` -> `0.8.0`
1 parent feac375 commit a0716d3

14 files changed

+52
-36
lines changed

.github/workflows/test.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ jobs:
5353
poetry install --all-extras
5454
5555
- name: Test with pytest
56-
run: pytest -v --cov=./lerobot --durations=0 tests
56+
run: |
57+
pytest tests -v --cov=./lerobot --durations=0 \
58+
-W ignore::DeprecationWarning:imageio_ffmpeg._utils:7 \
59+
-W ignore::UserWarning:torch.utils.data.dataloader:558 \
60+
-W ignore::UserWarning:gymnasium.utils.env_checker:247 \
61+
&& rm -rf tests/outputs outputs
5762
5863
- name: Test end-to-end
59-
run: make test-end-to-end
64+
run: |
65+
make test-end-to-end \
66+
&& rm -rf outputs

lerobot/common/policies/act/configuration_act.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class ActionChunkingTransformerConfig:
3333
deviation and "min_max" which rescale in a [-1, 1] range.
3434
unnormalize_output_modes: Similar dictionary as `normalize_input_modes`, but to unormalize in original scale.
3535
vision_backbone: Name of the torchvision resnet backbone to use for encoding images.
36-
use_pretrained_backbone: Whether the backbone should be initialized with pretrained weights from
37-
torchvision.
36+
pretrained_backbone_weights: Pretrained weights from torchvision to initalize the backbone.
37+
`None` means no pretrained weights.
3838
replace_final_stride_with_dilation: Whether to replace the ResNet's final 2x2 stride with a dilated
3939
convolution.
4040
pre_norm: Whether to use "pre-norm" in the transformer blocks.
@@ -90,7 +90,7 @@ class ActionChunkingTransformerConfig:
9090
# Architecture.
9191
# Vision backbone.
9292
vision_backbone: str = "resnet18"
93-
use_pretrained_backbone: bool = True
93+
pretrained_backbone_weights: str | None = "ResNet18_Weights.IMAGENET1K_V1"
9494
replace_final_stride_with_dilation: int = False
9595
# Transformer layers.
9696
pre_norm: bool = False

lerobot/common/policies/act/modeling_act.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self, cfg: ActionChunkingTransformerConfig | None = None, dataset_s
104104
# Backbone for image feature extraction.
105105
backbone_model = getattr(torchvision.models, cfg.vision_backbone)(
106106
replace_stride_with_dilation=[False, False, cfg.replace_final_stride_with_dilation],
107-
pretrained=cfg.use_pretrained_backbone,
107+
weights=cfg.pretrained_backbone_weights,
108108
norm_layer=FrozenBatchNorm2d,
109109
)
110110
# Note: The assumption here is that we are using a ResNet model (and hence layer4 is the final feature

lerobot/common/policies/diffusion/configuration_diffusion.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class DiffusionConfig:
3535
within the image size. If None, no cropping is done.
3636
crop_is_random: Whether the crop should be random at training time (it's always a center crop in eval
3737
mode).
38-
use_pretrained_backbone: Whether the backbone should be initialized with pretrained weights from
39-
torchvision.
38+
pretrained_backbone_weights: Pretrained weights from torchvision to initalize the backbone.
39+
`None` means no pretrained weights.
4040
use_group_norm: Whether to replace batch normalization with group normalization in the backbone.
4141
The group sizes are set to be about 16 (to be precise, feature_dim // 16).
4242
spatial_softmax_num_keypoints: Number of keypoints for SpatialSoftmax.
@@ -96,7 +96,7 @@ class DiffusionConfig:
9696
vision_backbone: str = "resnet18"
9797
crop_shape: tuple[int, int] | None = (84, 84)
9898
crop_is_random: bool = True
99-
use_pretrained_backbone: bool = False
99+
pretrained_backbone_weights: str | None = None
100100
use_group_norm: bool = True
101101
spatial_softmax_num_keypoints: int = 32
102102
# Unet.

lerobot/common/policies/diffusion/modeling_diffusion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,13 @@ def __init__(self, cfg: DiffusionConfig):
378378

379379
# Set up backbone.
380380
backbone_model = getattr(torchvision.models, cfg.vision_backbone)(
381-
pretrained=cfg.use_pretrained_backbone
381+
weights=cfg.pretrained_backbone_weights
382382
)
383383
# Note: This assumes that the layer4 feature map is children()[-3]
384384
# TODO(alexander-soare): Use a safer alternative.
385385
self.backbone = nn.Sequential(*(list(backbone_model.children())[:-2]))
386386
if cfg.use_group_norm:
387-
if cfg.use_pretrained_backbone:
387+
if cfg.pretrained_backbone_weights:
388388
raise ValueError(
389389
"You can't replace BatchNorm in a pretrained model without ruining the weights!"
390390
)

lerobot/common/utils/io_utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import warnings
2+
3+
import imageio
4+
5+
6+
def write_video(video_path, stacked_frames, fps):
7+
# Filter out DeprecationWarnings raised from pkg_resources
8+
with warnings.catch_warnings():
9+
warnings.filterwarnings(
10+
"ignore", "pkg_resources is deprecated as an API", category=DeprecationWarning
11+
)
12+
imageio.mimsave(video_path, stacked_frames, fps=fps)

lerobot/common/utils/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def init_hydra_config(config_path: str, overrides: list[str] | None = None) -> D
9292
hydra.core.global_hydra.GlobalHydra.instance().clear()
9393
# Hydra needs a path relative to this file.
9494
hydra.initialize(
95-
str(_relative_path_between(Path(config_path).absolute().parent, Path(__file__).absolute().parent))
95+
str(_relative_path_between(Path(config_path).absolute().parent, Path(__file__).absolute().parent)),
96+
version_base="1.2",
9697
)
9798
cfg = hydra.compose(Path(config_path).stem, overrides)
9899
return cfg

lerobot/configs/policy/act.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ policy:
4545
# Architecture.
4646
# Vision backbone.
4747
vision_backbone: resnet18
48-
use_pretrained_backbone: true
48+
pretrained_backbone_weights: ResNet18_Weights.IMAGENET1K_V1
4949
replace_final_stride_with_dilation: false
5050
# Transformer layers.
5151
pre_norm: false

lerobot/configs/policy/diffusion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ policy:
6161
vision_backbone: resnet18
6262
crop_shape: [84, 84]
6363
crop_is_random: True
64-
use_pretrained_backbone: false
64+
pretrained_backbone_weights: null
6565
use_group_norm: True
6666
spatial_softmax_num_keypoints: 32
6767
# Unet.

lerobot/scripts/eval.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import einops
4040
import gymnasium as gym
41-
import imageio
4241
import numpy as np
4342
import torch
4443
from datasets import Dataset, Features, Image, Sequence, Value
@@ -51,13 +50,10 @@
5150
from lerobot.common.envs.utils import postprocess_action, preprocess_observation
5251
from lerobot.common.logger import log_output_dir
5352
from lerobot.common.policies.factory import make_policy
53+
from lerobot.common.utils.io_utils import write_video
5454
from lerobot.common.utils.utils import get_safe_torch_device, init_hydra_config, init_logging, set_global_seed
5555

5656

57-
def write_video(video_path, stacked_frames, fps):
58-
imageio.mimsave(video_path, stacked_frames, fps=fps)
59-
60-
6157
def eval_policy(
6258
env: gym.vector.VectorEnv,
6359
policy: torch.nn.Module,

lerobot/scripts/train.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from lerobot.scripts.eval import eval_policy
2323

2424

25-
@hydra.main(version_base=None, config_name="default", config_path="../configs")
25+
@hydra.main(version_base="1.2", config_name="default", config_path="../configs")
2626
def train_cli(cfg: dict):
2727
train(
2828
cfg,

lerobot/scripts/visualize_dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
FIRST_FRAME = 0
1717

1818

19-
@hydra.main(version_base=None, config_name="default", config_path="../configs")
19+
@hydra.main(version_base="1.2", config_name="default", config_path="../configs")
2020
def visualize_dataset_cli(cfg: dict):
2121
visualize_dataset(cfg, out_dir=hydra.core.hydra_config.HydraConfig.get().runtime.output_dir)
2222

poetry.lock

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ wandb = "^0.16.3"
3434
imageio = {extras = ["ffmpeg"], version = "^2.34.0"}
3535
gdown = "^5.1.0"
3636
hydra-core = "^1.3.2"
37-
einops = "^0.7.0"
37+
einops = "^0.8.0"
3838
pymunk = "^6.6.0"
3939
zarr = "^2.17.0"
4040
numba = "^0.59.0"
4141
torch = "^2.2.1"
4242
opencv-python = "^4.9.0.80"
43-
diffusers = "^0.26.3"
43+
diffusers = "^0.27.2"
4444
torchvision = "^0.18.0"
4545
h5py = "^3.10.0"
4646
huggingface-hub = "^0.21.4"

0 commit comments

Comments
 (0)