Skip to content

[bug-fix] Make resnet barracuda-compatible (#5358) #5364

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

Merged
merged 1 commit into from
May 13, 2021
Merged
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
6 changes: 3 additions & 3 deletions ml-agents/mlagents/trainers/torch/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ def __init__(
layers.append(ResNetBlock(channel))
last_channel = channel
layers.append(Swish())
self.final_flat_size = n_channels[-1] * height * width
self.dense = linear_layer(
n_channels[-1] * height * width,
self.final_flat_size,
output_size,
kernel_init=Initialization.KaimingHeNormal,
kernel_gain=1.41, # Use ReLU gain
Expand All @@ -268,7 +269,6 @@ def __init__(
def forward(self, visual_obs: torch.Tensor) -> torch.Tensor:
if not exporting_to_onnx.is_exporting():
visual_obs = visual_obs.permute([0, 3, 1, 2])
batch_size = visual_obs.shape[0]
hidden = self.sequential(visual_obs)
before_out = hidden.reshape(batch_size, -1)
before_out = hidden.reshape(-1, self.final_flat_size)
return torch.relu(self.dense(before_out))