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 ResNet's in_channels calculations #220

Merged
merged 2 commits into from
Nov 16, 2023
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
22 changes: 13 additions & 9 deletions torch_frame/nn/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
self,
in_channels: int,
out_channels: int,
normalization: Optional[str] = 'layernorm',
normalization: Optional[str] = "layernorm",
dropout_prob: float = 0.0,
):
super().__init__()
Expand All @@ -47,10 +47,10 @@ def __init__(
self.relu = ReLU()
self.dropout = Dropout(dropout_prob)

if normalization == 'batchnorm':
if normalization == "batchnorm":
self.norm1 = BatchNorm1d(out_channels)
self.norm2 = BatchNorm1d(out_channels)
elif normalization == 'layernorm':
elif normalization == "layernorm":
self.norm1 = LayerNorm(out_channels)
self.norm2 = LayerNorm(out_channels)
else:
Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(
col_names_dict: Dict[torch_frame.stype, List[str]],
stype_encoder_dict: Optional[Dict[torch_frame.stype,
StypeEncoder]] = None,
normalization: Optional[str] = 'layernorm',
normalization: Optional[str] = "layernorm",
dropout_prob: float = 0.2,
):
super().__init__()
Expand All @@ -155,12 +155,16 @@ def __init__(
stype_encoder_dict=stype_encoder_dict,
)

in_channels = channels * (len(col_stats) - 1)
num_cols = sum(
[len(col_names) for col_names in col_names_dict.values()])
in_channels = channels * num_cols
self.backbone = Sequential(*[
FCResidualBlock(in_channels if i == 0 else channels, channels,
normalization=normalization,
dropout_prob=dropout_prob)
for i in range(num_layers)
FCResidualBlock(
in_channels if i == 0 else channels,
channels,
normalization=normalization,
dropout_prob=dropout_prob,
) for i in range(num_layers)
])

self.decoder = Sequential(
Expand Down
Loading