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

fix scan modality (#119) #1

Merged
merged 1 commit into from
Dec 13, 2023
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
5 changes: 5 additions & 0 deletions robomimic/models/base_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,11 @@ def __init__(

# Get activation requested
activation = CONV_ACTIVATIONS[activation]

# Add layer kwargs
conv_kwargs["out_channels"] = out_channels
conv_kwargs["kernel_size"] = kernel_size
conv_kwargs["stride"] = stride

# Generate network
self.n_layers = len(out_channels)
Expand Down
3 changes: 2 additions & 1 deletion robomimic/models/obs_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ def __init__(
conv_kwargs = dict()

# Generate backbone network
# N input channels is assumed to be the first dimension
self.backbone = BaseNets.Conv1dBase(
input_channel=1,
input_channel=self.input_shape[0],
activation=conv_activation,
**conv_kwargs,
)
Expand Down
24 changes: 24 additions & 0 deletions robomimic/utils/obs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,34 @@ class ScanModality(Modality):

@classmethod
def _default_obs_processor(cls, obs):
# Channel swaps ([...,] L, C) --> ([...,] C, L)

# First, add extra dimension at 2nd to last index to treat this as a frame
shape = obs.shape
new_shape = [*shape[:-2], 1, *shape[-2:]]
obs = obs.reshape(new_shape)

# Convert shape
obs = batch_image_hwc_to_chw(obs)

# Remove extra dimension (it's the second from last dimension)
obs = obs.squeeze(-2)
return obs

@classmethod
def _default_obs_unprocessor(cls, obs):
# Channel swaps ([B,] C, L) --> ([B,] L, C)

# First, add extra dimension at 1st index to treat this as a frame
shape = obs.shape
new_shape = [*shape[:-2], 1, *shape[-2:]]
obs = obs.reshape(new_shape)

# Convert shape
obs = batch_image_chw_to_hwc(obs)

# Remove extra dimension (it's the second from last dimension)
obs = obs.squeeze(-2)
return obs


Expand Down