-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from IBM/fix/vit_out_indices
fix indices vit
- Loading branch information
Showing
5 changed files
with
34 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,39 @@ | ||
import os | ||
import shutil | ||
|
||
import pytest | ||
import timm | ||
import torch | ||
import importlib | ||
import terratorch | ||
import subprocess | ||
import os | ||
|
||
from terratorch.cli_tools import build_lightning_cli | ||
|
||
@pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) | ||
def test_finetune_multiple_backbones(model_name): | ||
|
||
@pytest.fixture(autouse=True) | ||
def setup_and_cleanup(model_name): | ||
model_instance = timm.create_model(model_name) | ||
pretrained_bands = [0, 1, 2, 3, 4, 5] | ||
model_bands = [0, 1, 2, 3, 4, 5] | ||
|
||
state_dict = model_instance.state_dict() | ||
|
||
torch.save(state_dict, os.path.join("tests/", model_name + ".pt")) | ||
torch.save(state_dict, os.path.join("tests", model_name + ".pt")) | ||
|
||
yield # everything after this runs after each test | ||
|
||
# Running the terratorch CLI | ||
os.remove(os.path.join("tests", model_name + ".pt")) | ||
shutil.rmtree(os.path.join("tests", "all_ecos_random")) | ||
|
||
@pytest.mark.parametrize("model_name", ["prithvi_swin_B", "prithvi_swin_L", "prithvi_vit_100", "prithvi_vit_300"]) | ||
def test_finetune_multiple_backbones(model_name): | ||
command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}.yaml"] | ||
_ = build_lightning_cli(command_list) | ||
|
||
|
||
@pytest.mark.parametrize("model_name", ["prithvi_swin_B"]) | ||
def test_finetune_bands_intervals(model_name): | ||
|
||
model_instance = timm.create_model(model_name) | ||
|
||
state_dict = model_instance.state_dict() | ||
|
||
torch.save(state_dict, os.path.join("tests/", model_name + ".pt")) | ||
|
||
# Running the terratorch CLI | ||
command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}_band_interval.yaml"] | ||
_ = build_lightning_cli(command_list) | ||
|
||
@pytest.mark.parametrize("model_name", ["prithvi_swin_B"]) | ||
def test_finetune_bands_str(model_name): | ||
|
||
model_instance = timm.create_model(model_name) | ||
|
||
state_dict = model_instance.state_dict() | ||
|
||
torch.save(state_dict, os.path.join("tests/", model_name + ".pt")) | ||
|
||
# Running the terratorch CLI | ||
command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}_string.yaml"] | ||
_ = build_lightning_cli(command_list) | ||
|
||
@pytest.mark.parametrize("model_name", ["prithvi_swin_B"]) | ||
def test_finetune_bands_str(model_name): | ||
|
||
model_instance = timm.create_model(model_name) | ||
|
||
state_dict = model_instance.state_dict() | ||
|
||
torch.save(state_dict, os.path.join("tests/", model_name + ".pt")) | ||
|
||
# Running the terratorch CLI | ||
command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}_metrics_from_file.yaml"] | ||
command_list = ["fit", "-c", f"tests/manufactured-finetune_{model_name}_string.yaml"] | ||
_ = build_lightning_cli(command_list) | ||
|