Skip to content

Commit

Permalink
reduced numbers of pylint warnings (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinicke authored Sep 2, 2022
1 parent 75871bd commit b41cbe2
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 33 deletions.
23 changes: 18 additions & 5 deletions glasses/models/AutoModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@
from glasses.utils.storage import HuggingFaceStorage
from typing import List, Optional, OrderedDict
from torch import nn
from .classification import *
from .segmentation import *

from .classification import (
ResNetXt,
WideResNet,
DenseNet,
SEResNet,
RegNet,
ResNeSt,
VGG,
MobileNet,
EfficientNet,
EfficientNetLite,
FishNet,
ViT,
DeiT,
)
from .segmentation import UNet
from rich.table import Table
from .classification.resnet import (
ResNet,
Expand Down Expand Up @@ -273,9 +288,7 @@ def models_table(storage: Optional[Storage] = HuggingFaceStorage()) -> Table:
table.add_column("Name", justify="left", no_wrap=True)
table.add_column("Pretrained", justify="left", no_wrap=True)

[
for k in AutoModel.zoo.keys():
table.add_row(k, "true" if k in storage.models else "false")
for k in AutoModel.zoo.keys()
]

return table
10 changes: 5 additions & 5 deletions glasses/models/AutoTransform.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import torch
import torchvision.transforms as T
from glasses.models import *
from typing import Tuple, List, Callable
from torchvision.transforms import InterpolationMode
from functools import partial

# from glasses.models import *

IMAGENET_DEFAULT_MEAN = torch.Tensor([0.485, 0.456, 0.406])
IMAGENET_DEFAULT_STD = torch.Tensor([0.229, 0.224, 0.225])

Expand All @@ -22,8 +23,10 @@ def __init__(
std: Tuple[float],
mean: Tuple[float],
interpolation: str = "bilinear",
transforms: List[Callable] = list(),
transforms: List[Callable] = None,
):
if transforms is None:
transforms = []
self.input_size: int = input_size
base_transforms = [
T.Resize(resize, Transform.interpolations[interpolation]),
Expand Down Expand Up @@ -56,9 +59,6 @@ class AutoTransform:
"eca_resnet26t": ImageNetTransform(
resize=320, input_size=320, interpolation="bicubic"
),
"eca_resnet26t": ImageNetTransform(
resize=320, input_size=320, interpolation="bicubic"
),
"eca_resnet50t": ImageNetTransform(
resize=320, input_size=320, interpolation="bicubic"
),
Expand Down
2 changes: 1 addition & 1 deletion glasses/models/base/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def unfreeze(self, who: Optional[nn.Module] = None):


class Interpretable:
"""Protocol that allows the clas that subclass it to interpret an input using and instance of `Interpretability`"""
"""Protocol that allows the class that subclass it to interpret an input using and instance of `Interpretability`"""

def interpret(self, x: torch.Tensor, using: Interpretability, *args, **kwargs):
return using(x, self, *args, **kwargs)
2 changes: 1 addition & 1 deletion glasses/nn/att/CBAM.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch.nn as nn
from torch import Tensor
from einops.layers.torch import Rearrange, Reduce
from einops.layers.torch import Reduce


class CBAMChannelAtt(nn.Module):
Expand Down
25 changes: 12 additions & 13 deletions glasses/nn/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import torch.nn as nn
import math
from functools import partial
from typing import Callable, Tuple, Optional
from torch import Tensor
from functools import partial
from torch import nn, Tensor
from torch.nn import functional as F
from torchvision.ops import StochasticDepth

from glasses.nn import regularization


class Lambda(nn.Module):
def __init__(self, lambd: Callable[[Tensor], Tensor]):
"""An utility Module, it allows custom function to be passed
"""An utility Module, it allows custom function to be passed
Args:
lambd (Callable[Tensor]): A function that does something on a tensor
Args:
lambd (Callable[Tensor]): A function that does something on a tensor
Examples:
>>> add_two = Lambda(lambd x: x + 2)
>>> add_two(Tensor([0])) // 2
"""

def __init__(self, lambd: Callable[[Tensor], Tensor]):

Examples:
>>> add_two = Lambda(lambd x: x + 2)
>>> add_two(Tensor([0])) // 2
"""
super().__init__()
self.lambd = lambd

Expand Down
5 changes: 4 additions & 1 deletion glasses/nn/pool/SpatialPyramidPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ class SpatialPyramidPool(nn.Module):
"""

def __init__(
self, num_pools: List[int] = [1, 4, 16], pool: nn.Module = nn.AdaptiveMaxPool2d
self, num_pools: List[int] = None, pool: nn.Module = nn.AdaptiveMaxPool2d
):
super().__init__()

if num_pools is None:
num_pools = [1, 4, 16]

self.pools = nn.ModuleList([])
for p in num_pools:
# the output of 2d pool is B X C X P X P
Expand Down
1 change: 0 additions & 1 deletion glasses/utils/ModuleTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from torch import Tensor
from dataclasses import dataclass, field
from .Tracker import Tracker
from pprint import pprint
from typing import List


Expand Down
1 change: 0 additions & 1 deletion glasses/utils/storage/Storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from re import L
from typing import Any, List
from abc import ABC, abstractmethod

Expand Down
2 changes: 1 addition & 1 deletion glasses/utils/storage/hugging_face/HFModelHub.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import logging
import os
from typing import Dict, Optional
import torch
import requests
from typing import Dict, Optional
from torch import nn
from torch import Tensor

Expand Down
8 changes: 4 additions & 4 deletions glasses/utils/storage/hugging_face/ModelCardProducer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import time
from glasses.models import AutoModel
from huggingface_hub import Repository, HfFolder
from .HuggingFaceStorage import HuggingFaceStorage
from pathlib import Path
from torch import nn
from huggingface_hub import Repository
from glasses.models import AutoModel
from .HuggingFaceStorage import HuggingFaceStorage


# ---
# tags:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"matplotlib",
"einops",
"rich",
"huggingface-hub",
],
python_requires=">=3.8",
extras_require={
Expand Down

0 comments on commit b41cbe2

Please sign in to comment.