Skip to content

Commit

Permalink
Remove type ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstewart committed Feb 25, 2025
1 parent f9504c4 commit bcbdb27
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion experiments/ssl4eo/flops.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
for model in models:
print(f'Model: {model}')

m = timm.create_model(model, num_classes=num_classes, in_chans=in_channels) # type: ignore[attr-defined]
m = timm.create_model(model, num_classes=num_classes, in_chans=in_channels)

# Calculate memory requirements of model
mem_params = sum([p.nelement() * p.element_size() for p in m.parameters()])
Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model('resnet18', in_chans=weights.meta['in_chans']) # type: ignore[attr-defined]
model = timm.create_model('resnet18', in_chans=weights.meta['in_chans'])
torch.save(model.state_dict(), path)
try:
monkeypatch.setattr(weights.value, 'url', str(path))
Expand Down Expand Up @@ -78,7 +78,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model('resnet50', in_chans=weights.meta['in_chans']) # type: ignore[attr-defined]
model = timm.create_model('resnet50', in_chans=weights.meta['in_chans'])
torch.save(model.state_dict(), path)
try:
monkeypatch.setattr(weights.value, 'url', str(path))
Expand Down Expand Up @@ -122,7 +122,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model('resnet152', in_chans=weights.meta['in_chans']) # type: ignore[attr-defined]
model = timm.create_model('resnet152', in_chans=weights.meta['in_chans'])
torch.save(model.state_dict(), path)
try:
monkeypatch.setattr(weights.value, 'url', str(path))
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_byol.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_moco.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
4 changes: 2 additions & 2 deletions tests/trainers/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down Expand Up @@ -273,7 +273,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_simclr.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def mocked_weights(
load_state_dict_from_url: None,
) -> WeightsEnum:
path = tmp_path / f'{weights}.pth'
model = timm.create_model( # type: ignore[attr-defined]
model = timm.create_model(
weights.meta['model'], in_chans=weights.meta['in_chans']
)
torch.save(model.state_dict(), path)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainers/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_extract_backbone_unsupported_model(tmp_path: Path) -> None:


def test_get_input_layer_name_and_module() -> None:
key, module = _get_input_layer_name_and_module(timm.create_model('resnet18')) # type: ignore[attr-defined]
key, module = _get_input_layer_name_and_module(timm.create_model('resnet18'))
assert key == 'conv1'
assert isinstance(module, nn.Conv2d)
assert module.in_channels == 3
Expand Down
6 changes: 3 additions & 3 deletions torchgeo/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def resnet18(
if weights:
kwargs['in_chans'] = weights.meta['in_chans']

model: ResNet = timm.create_model('resnet18', *args, **kwargs) # type: ignore[attr-defined]
model: ResNet = timm.create_model('resnet18', *args, **kwargs)

if weights:
missing_keys, unexpected_keys = model.load_state_dict(
Expand Down Expand Up @@ -803,7 +803,7 @@ def resnet50(
if weights:
kwargs['in_chans'] = weights.meta['in_chans']

model: ResNet = timm.create_model('resnet50', *args, **kwargs) # type: ignore[attr-defined]
model: ResNet = timm.create_model('resnet50', *args, **kwargs)

if weights:
missing_keys, unexpected_keys = model.load_state_dict(
Expand Down Expand Up @@ -837,7 +837,7 @@ def resnet152(
if weights:
kwargs['in_chans'] = weights.meta['in_chans']

model: ResNet = timm.create_model('resnet152', *args, **kwargs) # type: ignore[attr-defined]
model: ResNet = timm.create_model('resnet152', *args, **kwargs)

if weights:
missing_keys, unexpected_keys = model.load_state_dict(
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/models/vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def vit_small_patch16_224(
if weights:
kwargs['in_chans'] = weights.meta['in_chans']

model: VisionTransformer = timm.create_model( # type: ignore[attr-defined]
model: VisionTransformer = timm.create_model(
'vit_small_patch16_224', *args, **kwargs
)

Expand Down
2 changes: 1 addition & 1 deletion torchgeo/trainers/byol.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def configure_models(self) -> None:
in_channels: int = self.hparams['in_channels']

# Create backbone
backbone = timm.create_model( # type: ignore[attr-defined]
backbone = timm.create_model(
self.hparams['model'], in_chans=in_channels, pretrained=weights is True
)

Expand Down
2 changes: 1 addition & 1 deletion torchgeo/trainers/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def configure_models(self) -> None:
weights = self.weights

# Create model
self.model = timm.create_model( # type: ignore[attr-defined]
self.model = timm.create_model(
self.hparams['model'],
num_classes=self.hparams['num_classes'],
in_chans=self.hparams['in_channels'],
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/trainers/moco.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ def configure_models(self) -> None:
output_dim: int = self.hparams['output_dim']

# Create backbone
self.backbone = timm.create_model( # type: ignore[attr-defined]
self.backbone = timm.create_model(
model, in_chans=in_channels, num_classes=0, pretrained=weights is True
)
self.backbone_momentum = timm.create_model( # type: ignore[attr-defined]
self.backbone_momentum = timm.create_model(
model, in_chans=in_channels, num_classes=0, pretrained=weights is True
)
deactivate_requires_grad(self.backbone_momentum)
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/trainers/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def configure_models(self) -> None:
"""Initialize the model."""
# Create model
weights = self.weights
self.model = timm.create_model( # type: ignore[attr-defined]
self.model = timm.create_model(
self.hparams['model'],
num_classes=self.hparams['num_outputs'],
in_chans=self.hparams['in_channels'],
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/trainers/simclr.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def configure_models(self) -> None:
weights = self.weights

# Create backbone
self.backbone = timm.create_model( # type: ignore[attr-defined]
self.backbone = timm.create_model(
self.hparams['model'],
in_chans=self.hparams['in_channels'],
num_classes=0,
Expand Down

0 comments on commit bcbdb27

Please sign in to comment.