From 5a4babdfb40948067894dfba9ab7cea704ec57ab Mon Sep 17 00:00:00 2001 From: Gabriel Gutierrez Date: Tue, 2 Jul 2024 10:18:57 -0300 Subject: [PATCH 1/3] Models Reorg --- minerva/models/nets/__init__.py | 8 ++++---- minerva/models/nets/{ => image}/deeplabv3.py | 0 minerva/models/nets/{ => image}/setr.py | 6 +++--- minerva/models/nets/{ => image}/unet.py | 0 minerva/models/nets/{ => image}/vit.py | 0 minerva/models/nets/{ => image}/wisenet.py | 0 minerva/models/nets/{ => time_series}/cnns.py | 0 minerva/models/nets/{ => time_series}/imu_transformer.py | 0 minerva/models/nets/{ => time_series}/inception_time.py | 0 minerva/models/nets/{ => time_series}/resnet.py | 8 +------- tests/models/nets/test_cnn_ha_etal.py | 2 +- tests/models/nets/test_cnn_pf.py | 2 +- tests/models/nets/test_deeplabv3.py | 2 +- tests/models/nets/test_imu_transformer.py | 9 +++++++-- tests/models/nets/test_inception_time.py | 4 +++- tests/models/nets/test_resnet_1d.py | 6 +++++- tests/models/nets/test_sfm.py | 2 +- 17 files changed, 27 insertions(+), 22 deletions(-) rename minerva/models/nets/{ => image}/deeplabv3.py (100%) rename minerva/models/nets/{ => image}/setr.py (99%) rename minerva/models/nets/{ => image}/unet.py (100%) rename minerva/models/nets/{ => image}/vit.py (100%) rename minerva/models/nets/{ => image}/wisenet.py (100%) rename minerva/models/nets/{ => time_series}/cnns.py (100%) rename minerva/models/nets/{ => time_series}/imu_transformer.py (100%) rename minerva/models/nets/{ => time_series}/inception_time.py (100%) rename minerva/models/nets/{ => time_series}/resnet.py (97%) diff --git a/minerva/models/nets/__init__.py b/minerva/models/nets/__init__.py index 2618877..c179923 100644 --- a/minerva/models/nets/__init__.py +++ b/minerva/models/nets/__init__.py @@ -1,8 +1,8 @@ from .base import SimpleSupervisedModel -from .deeplabv3 import DeepLabV3 -from .setr import SETR_PUP -from .unet import UNet -from .wisenet import WiseNet +from .image.deeplabv3 import DeepLabV3 +from .image.setr import SETR_PUP +from .image.unet import UNet +from .image.wisenet import WiseNet __all__ = [ "SimpleSupervisedModel", diff --git a/minerva/models/nets/deeplabv3.py b/minerva/models/nets/image/deeplabv3.py similarity index 100% rename from minerva/models/nets/deeplabv3.py rename to minerva/models/nets/image/deeplabv3.py diff --git a/minerva/models/nets/setr.py b/minerva/models/nets/image/setr.py similarity index 99% rename from minerva/models/nets/setr.py rename to minerva/models/nets/image/setr.py index a5f6ef4..63c1618 100644 --- a/minerva/models/nets/setr.py +++ b/minerva/models/nets/image/setr.py @@ -4,10 +4,10 @@ import lightning as L import torch from torch import nn -from torchmetrics import JaccardIndex, Metric +from torchmetrics import Metric -from minerva.models.nets.vit import _VisionTransformerBackbone -from minerva.utils.upsample import Upsample, resize +from minerva.models.nets.image.vit import _VisionTransformerBackbone +from minerva.utils.upsample import Upsample class _SETRUPHead(nn.Module): diff --git a/minerva/models/nets/unet.py b/minerva/models/nets/image/unet.py similarity index 100% rename from minerva/models/nets/unet.py rename to minerva/models/nets/image/unet.py diff --git a/minerva/models/nets/vit.py b/minerva/models/nets/image/vit.py similarity index 100% rename from minerva/models/nets/vit.py rename to minerva/models/nets/image/vit.py diff --git a/minerva/models/nets/wisenet.py b/minerva/models/nets/image/wisenet.py similarity index 100% rename from minerva/models/nets/wisenet.py rename to minerva/models/nets/image/wisenet.py diff --git a/minerva/models/nets/cnns.py b/minerva/models/nets/time_series/cnns.py similarity index 100% rename from minerva/models/nets/cnns.py rename to minerva/models/nets/time_series/cnns.py diff --git a/minerva/models/nets/imu_transformer.py b/minerva/models/nets/time_series/imu_transformer.py similarity index 100% rename from minerva/models/nets/imu_transformer.py rename to minerva/models/nets/time_series/imu_transformer.py diff --git a/minerva/models/nets/inception_time.py b/minerva/models/nets/time_series/inception_time.py similarity index 100% rename from minerva/models/nets/inception_time.py rename to minerva/models/nets/time_series/inception_time.py diff --git a/minerva/models/nets/resnet.py b/minerva/models/nets/time_series/resnet.py similarity index 97% rename from minerva/models/nets/resnet.py rename to minerva/models/nets/time_series/resnet.py index bc5b71a..a31edba 100644 --- a/minerva/models/nets/resnet.py +++ b/minerva/models/nets/time_series/resnet.py @@ -1,12 +1,6 @@ -import time -from functools import partial -from typing import Literal, Tuple +from typing import Tuple -import lightning as L -import numpy as np import torch -from torch import nn -from torch.nn import TransformerEncoder, TransformerEncoderLayer from torchmetrics import Accuracy from minerva.models.nets.base import SimpleSupervisedModel diff --git a/tests/models/nets/test_cnn_ha_etal.py b/tests/models/nets/test_cnn_ha_etal.py index c37d166..38d1566 100644 --- a/tests/models/nets/test_cnn_ha_etal.py +++ b/tests/models/nets/test_cnn_ha_etal.py @@ -1,6 +1,6 @@ import torch -from minerva.models.nets.cnns import CNN_HaEtAl_1D, CNN_HaEtAl_2D +from minerva.models.nets.time_series.cnns import CNN_HaEtAl_1D, CNN_HaEtAl_2D def test_cnn_ha_etal_1d_forward(): diff --git a/tests/models/nets/test_cnn_pf.py b/tests/models/nets/test_cnn_pf.py index 04602eb..99e970b 100644 --- a/tests/models/nets/test_cnn_pf.py +++ b/tests/models/nets/test_cnn_pf.py @@ -1,6 +1,6 @@ import torch -from minerva.models.nets.cnns import CNN_PF_2D, CNN_PFF_2D +from minerva.models.nets.time_series.cnns import CNN_PF_2D, CNN_PFF_2D def test_cnn_pf_forward(): diff --git a/tests/models/nets/test_deeplabv3.py b/tests/models/nets/test_deeplabv3.py index 281b7ba..2ecb4a3 100644 --- a/tests/models/nets/test_deeplabv3.py +++ b/tests/models/nets/test_deeplabv3.py @@ -1,6 +1,6 @@ import torch -from minerva.models.nets.deeplabv3 import DeepLabV3, DeepLabV3Backbone +from minerva.models.nets.image.deeplabv3 import DeepLabV3, DeepLabV3Backbone def test_deeplabv3_model(): diff --git a/tests/models/nets/test_imu_transformer.py b/tests/models/nets/test_imu_transformer.py index 60f7eef..e2d0e41 100644 --- a/tests/models/nets/test_imu_transformer.py +++ b/tests/models/nets/test_imu_transformer.py @@ -1,5 +1,10 @@ import torch -from minerva.models.nets.imu_transformer import IMUTransformerEncoder, IMUCNN + +from minerva.models.nets.time_series.imu_transformer import ( + IMUCNN, + IMUTransformerEncoder, +) + def test_imu_transformer_forward(): input_shape = (6, 60) @@ -18,4 +23,4 @@ def test_imu_cnn_forward(): x = torch.rand(1, *input_shape) y = model(x) - assert y is not None \ No newline at end of file + assert y is not None diff --git a/tests/models/nets/test_inception_time.py b/tests/models/nets/test_inception_time.py index 058c48f..12cfdde 100644 --- a/tests/models/nets/test_inception_time.py +++ b/tests/models/nets/test_inception_time.py @@ -1,5 +1,7 @@ import torch -from minerva.models.nets.inception_time import InceptionTime + +from minerva.models.nets.time_series.inception_time import InceptionTime + def test_inception_time_forward(): input_shape = (6, 60) diff --git a/tests/models/nets/test_resnet_1d.py b/tests/models/nets/test_resnet_1d.py index 86c23aa..9cc2246 100644 --- a/tests/models/nets/test_resnet_1d.py +++ b/tests/models/nets/test_resnet_1d.py @@ -1,6 +1,10 @@ import torch -from minerva.models.nets.resnet import ResNet1D_8, ResNetSE1D_5, ResNetSE1D_8 +from minerva.models.nets.time_series.resnet import ( + ResNet1D_8, + ResNetSE1D_5, + ResNetSE1D_8, +) def test_resnet_1d_8_forward(): diff --git a/tests/models/nets/test_sfm.py b/tests/models/nets/test_sfm.py index f9cb5d0..ec3544d 100644 --- a/tests/models/nets/test_sfm.py +++ b/tests/models/nets/test_sfm.py @@ -1,7 +1,7 @@ import pytest import torch -from minerva.models.nets.vit import ( +from minerva.models.nets.image.vit import ( mae_vit_base_patch16, mae_vit_base_patch16D4d256, mae_vit_huge_patch14, From 787f606c1e2bea46ff96c069df415627b311fd1a Mon Sep 17 00:00:00 2001 From: Gabriel Gutierrez Date: Tue, 2 Jul 2024 10:23:33 -0300 Subject: [PATCH 2/3] removing unused imports --- minerva/models/nets/image/deeplabv3.py | 2 +- minerva/models/nets/image/unet.py | 8 ++------ minerva/models/nets/time_series/imu_transformer.py | 1 - minerva/models/nets/time_series/inception_time.py | 5 ----- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/minerva/models/nets/image/deeplabv3.py b/minerva/models/nets/image/deeplabv3.py index c62127c..3fbad8a 100644 --- a/minerva/models/nets/image/deeplabv3.py +++ b/minerva/models/nets/image/deeplabv3.py @@ -1,6 +1,6 @@ from typing import Dict, Optional, Sequence -from torch import Tensor, load, nn, optim +from torch import Tensor, nn, optim from torchmetrics import Metric from torchvision.models.resnet import resnet50 from torchvision.models.segmentation.deeplabv3 import ASPP diff --git a/minerva/models/nets/image/unet.py b/minerva/models/nets/image/unet.py index ec42fd8..2419cfc 100644 --- a/minerva/models/nets/image/unet.py +++ b/minerva/models/nets/image/unet.py @@ -1,14 +1,10 @@ """ Full assembly of the parts to form the complete network """ -import time -from typing import Dict, Optional +from typing import Optional -import lightning as L import torch import torch.nn as nn import torch.nn.functional as F -import torch.optim as optim -from torch.optim.lr_scheduler import CyclicLR, StepLR from minerva.models.nets.base import SimpleSupervisedModel @@ -227,5 +223,5 @@ def __init__( loss_fn=loss_fn or torch.nn.MSELoss(), learning_rate=learning_rate, flatten=False, - **kwargs + **kwargs, ) diff --git a/minerva/models/nets/time_series/imu_transformer.py b/minerva/models/nets/time_series/imu_transformer.py index 4dddad9..31895db 100644 --- a/minerva/models/nets/time_series/imu_transformer.py +++ b/minerva/models/nets/time_series/imu_transformer.py @@ -1,6 +1,5 @@ from typing import Tuple -import lightning as L import torch from torch import nn from torch.nn import TransformerEncoder, TransformerEncoderLayer diff --git a/minerva/models/nets/time_series/inception_time.py b/minerva/models/nets/time_series/inception_time.py index 91a6a0c..01fdb7f 100644 --- a/minerva/models/nets/time_series/inception_time.py +++ b/minerva/models/nets/time_series/inception_time.py @@ -1,11 +1,6 @@ -import time from typing import Tuple -import lightning as L -import numpy as np import torch -from torch import nn -from torch.nn import TransformerEncoder, TransformerEncoderLayer from torchmetrics import Accuracy from minerva.models.nets.base import SimpleSupervisedModel From 586648f24cea7d5701c57d03648232507fc65f1b Mon Sep 17 00:00:00 2001 From: Gabriel Gutierrez Date: Wed, 3 Jul 2024 00:44:08 -0300 Subject: [PATCH 3/3] test reorganizing --- tests/models/nets/{ => image}/test_deeplabv3.py | 0 tests/models/nets/{ => image}/test_setr.py | 0 tests/models/nets/{ => image}/test_sfm.py | 0 tests/models/nets/{ => image}/test_unet.py | 0 tests/models/nets/{ => image}/test_wisenet.py | 0 tests/models/nets/{ => time_series}/test_cnn_ha_etal.py | 0 tests/models/nets/{ => time_series}/test_cnn_pf.py | 0 tests/models/nets/{ => time_series}/test_imu_transformer.py | 0 tests/models/nets/{ => time_series}/test_inception_time.py | 0 tests/models/nets/{ => time_series}/test_resnet_1d.py | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename tests/models/nets/{ => image}/test_deeplabv3.py (100%) rename tests/models/nets/{ => image}/test_setr.py (100%) rename tests/models/nets/{ => image}/test_sfm.py (100%) rename tests/models/nets/{ => image}/test_unet.py (100%) rename tests/models/nets/{ => image}/test_wisenet.py (100%) rename tests/models/nets/{ => time_series}/test_cnn_ha_etal.py (100%) rename tests/models/nets/{ => time_series}/test_cnn_pf.py (100%) rename tests/models/nets/{ => time_series}/test_imu_transformer.py (100%) rename tests/models/nets/{ => time_series}/test_inception_time.py (100%) rename tests/models/nets/{ => time_series}/test_resnet_1d.py (100%) diff --git a/tests/models/nets/test_deeplabv3.py b/tests/models/nets/image/test_deeplabv3.py similarity index 100% rename from tests/models/nets/test_deeplabv3.py rename to tests/models/nets/image/test_deeplabv3.py diff --git a/tests/models/nets/test_setr.py b/tests/models/nets/image/test_setr.py similarity index 100% rename from tests/models/nets/test_setr.py rename to tests/models/nets/image/test_setr.py diff --git a/tests/models/nets/test_sfm.py b/tests/models/nets/image/test_sfm.py similarity index 100% rename from tests/models/nets/test_sfm.py rename to tests/models/nets/image/test_sfm.py diff --git a/tests/models/nets/test_unet.py b/tests/models/nets/image/test_unet.py similarity index 100% rename from tests/models/nets/test_unet.py rename to tests/models/nets/image/test_unet.py diff --git a/tests/models/nets/test_wisenet.py b/tests/models/nets/image/test_wisenet.py similarity index 100% rename from tests/models/nets/test_wisenet.py rename to tests/models/nets/image/test_wisenet.py diff --git a/tests/models/nets/test_cnn_ha_etal.py b/tests/models/nets/time_series/test_cnn_ha_etal.py similarity index 100% rename from tests/models/nets/test_cnn_ha_etal.py rename to tests/models/nets/time_series/test_cnn_ha_etal.py diff --git a/tests/models/nets/test_cnn_pf.py b/tests/models/nets/time_series/test_cnn_pf.py similarity index 100% rename from tests/models/nets/test_cnn_pf.py rename to tests/models/nets/time_series/test_cnn_pf.py diff --git a/tests/models/nets/test_imu_transformer.py b/tests/models/nets/time_series/test_imu_transformer.py similarity index 100% rename from tests/models/nets/test_imu_transformer.py rename to tests/models/nets/time_series/test_imu_transformer.py diff --git a/tests/models/nets/test_inception_time.py b/tests/models/nets/time_series/test_inception_time.py similarity index 100% rename from tests/models/nets/test_inception_time.py rename to tests/models/nets/time_series/test_inception_time.py diff --git a/tests/models/nets/test_resnet_1d.py b/tests/models/nets/time_series/test_resnet_1d.py similarity index 100% rename from tests/models/nets/test_resnet_1d.py rename to tests/models/nets/time_series/test_resnet_1d.py