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

Correct the seco weight names #1593

Merged
merged 7 commits into from
Sep 30, 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
16 changes: 12 additions & 4 deletions torchgeo/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ResNet18_Weights(WeightsEnum): # type: ignore[misc]
)

SENTINEL2_RGB_SECO = Weights(
url="https://huggingface.co/torchgeo/resnet18_sentinel2_rgb_seco/resolve/main/resnet18_sentinel2_rgb_seco-9976a9cb.pth", # noqa: E501
url="https://huggingface.co/torchgeo/resnet18_sentinel2_rgb_seco/resolve/main/resnet18_sentinel2_rgb_seco-cefca942.pth", # noqa: E501
transforms=_seco_transforms,
meta={
"dataset": "SeCo Dataset",
Expand Down Expand Up @@ -158,7 +158,7 @@ class ResNet50_Weights(WeightsEnum): # type: ignore[misc]
)

SENTINEL2_RGB_SECO = Weights(
url="https://huggingface.co/torchgeo/resnet50_sentinel2_rgb_seco/resolve/main/resnet50_sentinel2_rgb_seco-584035db.pth", # noqa: E501
url="https://huggingface.co/torchgeo/resnet50_sentinel2_rgb_seco/resolve/main/resnet50_sentinel2_rgb_seco-018bf397.pth", # noqa: E501
transforms=_seco_transforms,
meta={
"dataset": "SeCo Dataset",
Expand Down Expand Up @@ -196,7 +196,11 @@ def resnet18(
model: ResNet = timm.create_model("resnet18", *args, **kwargs)

if weights:
model.load_state_dict(weights.get_state_dict(progress=True), strict=False)
missing_keys, unexpected_keys = model.load_state_dict(
weights.get_state_dict(progress=True), strict=False
)
assert set(missing_keys) <= {"fc.weight", "fc.bias"}
assert not unexpected_keys

return model

Expand Down Expand Up @@ -227,6 +231,10 @@ def resnet50(
model: ResNet = timm.create_model("resnet50", *args, **kwargs)

if weights:
model.load_state_dict(weights.get_state_dict(progress=True), strict=False)
missing_keys, unexpected_keys = model.load_state_dict(
weights.get_state_dict(progress=True), strict=False
)
assert set(missing_keys) <= {"fc.weight", "fc.bias"}
assert not unexpected_keys

return model
6 changes: 5 additions & 1 deletion torchgeo/models/vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def vit_small_patch16_224(
)

if weights:
model.load_state_dict(weights.get_state_dict(progress=True), strict=False)
missing_keys, unexpected_keys = model.load_state_dict(
weights.get_state_dict(progress=True), strict=False
)
assert set(missing_keys) <= {"head.weight", "head.bias"}
assert not unexpected_keys

return model