Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warnings #111

Merged
merged 18 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ jobs:
poetry install --all-extras
- name: Test with pytest
run: pytest -v --cov=./lerobot --durations=0 tests
run: |
pytest tests -v --cov=./lerobot --durations=0 \
-W ignore::DeprecationWarning:imageio_ffmpeg._utils:7 \
-W ignore::UserWarning:torch.utils.data.dataloader:558 \
-W ignore::UserWarning:gymnasium.utils.env_checker:247 \
&& rm -rf tests/outputs outputs
- name: Test end-to-end
run: make test-end-to-end
run: |
make test-end-to-end \
&& rm -rf outputs
6 changes: 3 additions & 3 deletions lerobot/common/policies/act/configuration_act.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ActionChunkingTransformerConfig:
deviation and "min_max" which rescale in a [-1, 1] range.
unnormalize_output_modes: Similar dictionary as `normalize_input_modes`, but to unormalize in original scale.
vision_backbone: Name of the torchvision resnet backbone to use for encoding images.
use_pretrained_backbone: Whether the backbone should be initialized with pretrained weights from
torchvision.
pretrained_backbone_weights: Pretrained weights from torchvision to initalize the backbone.
`None` means no pretrained weights.
replace_final_stride_with_dilation: Whether to replace the ResNet's final 2x2 stride with a dilated
convolution.
pre_norm: Whether to use "pre-norm" in the transformer blocks.
Expand Down Expand Up @@ -90,7 +90,7 @@ class ActionChunkingTransformerConfig:
# Architecture.
# Vision backbone.
vision_backbone: str = "resnet18"
use_pretrained_backbone: bool = True
pretrained_backbone_weights: str | None = "ResNet18_Weights.IMAGENET1K_V1"
replace_final_stride_with_dilation: int = False
# Transformer layers.
pre_norm: bool = False
Expand Down
2 changes: 1 addition & 1 deletion lerobot/common/policies/act/modeling_act.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, cfg: ActionChunkingTransformerConfig | None = None, dataset_s
# Backbone for image feature extraction.
backbone_model = getattr(torchvision.models, cfg.vision_backbone)(
replace_stride_with_dilation=[False, False, cfg.replace_final_stride_with_dilation],
pretrained=cfg.use_pretrained_backbone,
weights=cfg.pretrained_backbone_weights,
norm_layer=FrozenBatchNorm2d,
)
# Note: The assumption here is that we are using a ResNet model (and hence layer4 is the final feature
Expand Down
6 changes: 3 additions & 3 deletions lerobot/common/policies/diffusion/configuration_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class DiffusionConfig:
within the image size. If None, no cropping is done.
crop_is_random: Whether the crop should be random at training time (it's always a center crop in eval
mode).
use_pretrained_backbone: Whether the backbone should be initialized with pretrained weights from
torchvision.
pretrained_backbone_weights: Pretrained weights from torchvision to initalize the backbone.
`None` means no pretrained weights.
use_group_norm: Whether to replace batch normalization with group normalization in the backbone.
The group sizes are set to be about 16 (to be precise, feature_dim // 16).
spatial_softmax_num_keypoints: Number of keypoints for SpatialSoftmax.
Expand Down Expand Up @@ -96,7 +96,7 @@ class DiffusionConfig:
vision_backbone: str = "resnet18"
crop_shape: tuple[int, int] | None = (84, 84)
crop_is_random: bool = True
use_pretrained_backbone: bool = False
pretrained_backbone_weights: str | None = None
use_group_norm: bool = True
spatial_softmax_num_keypoints: int = 32
# Unet.
Expand Down
4 changes: 2 additions & 2 deletions lerobot/common/policies/diffusion/modeling_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ def __init__(self, cfg: DiffusionConfig):

# Set up backbone.
backbone_model = getattr(torchvision.models, cfg.vision_backbone)(
pretrained=cfg.use_pretrained_backbone
weights=cfg.pretrained_backbone_weights
)
# Note: This assumes that the layer4 feature map is children()[-3]
# TODO(alexander-soare): Use a safer alternative.
self.backbone = nn.Sequential(*(list(backbone_model.children())[:-2]))
if cfg.use_group_norm:
if cfg.use_pretrained_backbone:
if cfg.pretrained_backbone_weights:
raise ValueError(
"You can't replace BatchNorm in a pretrained model without ruining the weights!"
)
Expand Down
12 changes: 12 additions & 0 deletions lerobot/common/utils/io_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import warnings

import imageio


def write_video(video_path, stacked_frames, fps):
# Filter out DeprecationWarnings raised from pkg_resources
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "pkg_resources is deprecated as an API", category=DeprecationWarning
)
imageio.mimsave(video_path, stacked_frames, fps=fps)
Comment on lines +1 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename io_utils.py to io.py ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in a previous python project and it's okay until you need to import io from the standard library. It's confusing so I wouldn't recommend it.

Comment on lines +6 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why cant we use imageio as an API without warning?

What are the alternatives to generate an mp4 from a numpy array?

Copy link
Collaborator Author

@aliberts aliberts Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand. To be clear, the problem here with imageio.mimsave is that it calls pkg_resources at some point down the line (in imageio-ffmpeg actually), which raises this warning. As mentioned before, a fix has been pushed on their main but it hasn't made its way to a release yet so we just have to handle it on our side until then.

3 changes: 2 additions & 1 deletion lerobot/common/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def init_hydra_config(config_path: str, overrides: list[str] | None = None) -> D
hydra.core.global_hydra.GlobalHydra.instance().clear()
# Hydra needs a path relative to this file.
hydra.initialize(
str(_relative_path_between(Path(config_path).absolute().parent, Path(__file__).absolute().parent))
str(_relative_path_between(Path(config_path).absolute().parent, Path(__file__).absolute().parent)),
version_base="1.2",
)
cfg = hydra.compose(Path(config_path).stem, overrides)
return cfg
Expand Down
2 changes: 1 addition & 1 deletion lerobot/configs/policy/act.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ policy:
# Architecture.
# Vision backbone.
vision_backbone: resnet18
use_pretrained_backbone: true
pretrained_backbone_weights: ResNet18_Weights.IMAGENET1K_V1
replace_final_stride_with_dilation: false
# Transformer layers.
pre_norm: false
Expand Down
2 changes: 1 addition & 1 deletion lerobot/configs/policy/diffusion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ policy:
vision_backbone: resnet18
crop_shape: [84, 84]
crop_is_random: True
use_pretrained_backbone: false
pretrained_backbone_weights: null
use_group_norm: True
spatial_softmax_num_keypoints: 32
# Unet.
Expand Down
6 changes: 1 addition & 5 deletions lerobot/scripts/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import einops
import gymnasium as gym
import imageio
import numpy as np
import torch
from datasets import Dataset, Features, Image, Sequence, Value
Expand All @@ -51,13 +50,10 @@
from lerobot.common.envs.utils import postprocess_action, preprocess_observation
from lerobot.common.logger import log_output_dir
from lerobot.common.policies.factory import make_policy
from lerobot.common.utils.io_utils import write_video
from lerobot.common.utils.utils import get_safe_torch_device, init_hydra_config, init_logging, set_global_seed


def write_video(video_path, stacked_frames, fps):
imageio.mimsave(video_path, stacked_frames, fps=fps)


def eval_policy(
env: gym.vector.VectorEnv,
policy: torch.nn.Module,
Expand Down
2 changes: 1 addition & 1 deletion lerobot/scripts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from lerobot.scripts.eval import eval_policy


@hydra.main(version_base=None, config_name="default", config_path="../configs")
@hydra.main(version_base="1.2", config_name="default", config_path="../configs")
def train_cli(cfg: dict):
train(
cfg,
Expand Down
2 changes: 1 addition & 1 deletion lerobot/scripts/visualize_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
FIRST_FRAME = 0


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

Expand Down
26 changes: 13 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ wandb = "^0.16.3"
imageio = {extras = ["ffmpeg"], version = "^2.34.0"}
gdown = "^5.1.0"
hydra-core = "^1.3.2"
einops = "^0.7.0"
einops = "^0.8.0"
pymunk = "^6.6.0"
zarr = "^2.17.0"
numba = "^0.59.0"
torch = "^2.2.1"
opencv-python = "^4.9.0.80"
diffusers = "^0.26.3"
diffusers = "^0.27.2"
torchvision = "^0.18.0"
h5py = "^3.10.0"
huggingface-hub = "^0.21.4"
Expand Down
Loading