Skip to content

Commit

Permalink
style(ruff): fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Jun 23, 2024
1 parent 1769d39 commit edb1963
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 49 deletions.
4 changes: 1 addition & 3 deletions .github/verify_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def parse_args():
)

parser.add_argument("pr", type=int, help="PR number")
args = parser.parse_args()

return args
return parser.parse_args()


if __name__ == "__main__":
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/classification/sknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
b, m, c = paths.shape[:3]
z = self.sa(paths.sum(dim=1)).view(b, m, c, 1, 1)
attention_factors = torch.softmax(z, dim=1)
out = (attention_factors * paths).sum(dim=1)

return out
return (attention_factors * paths).sum(dim=1)


class SKBottleneck(_ResBlock):
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/classification/tridentnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
dilations = [1] * self.num_branches if self.dilation[0] == 1 else [1 + idx for idx in range(self.num_branches)]

# Use shared weight to apply the convolution
out = torch.cat(
return torch.cat(
[
F.conv2d(
_x,
Expand All @@ -57,8 +57,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
1,
)

return out


class Tridentneck(_ResBlock):
expansion: int = 4
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/detection/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ def _format_outputs(self, x: Tensor) -> Tuple[Tensor, Tensor, Tensor]:
def _forward(self, x: Tensor) -> Tensor:
out = self.backbone(x)
out = self.block4(out)
out = self.classifier(out)

return out
return self.classifier(out)

def forward(
self, x: Tensor, target: Optional[List[Dict[str, Tensor]]] = None
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/detection/yolov2.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ def _forward(self, x: Tensor) -> Tensor:
out = torch.cat((passthrough, out), 1)
out = self.block6(out)

out = self.head(out)

return out
return self.head(out)

def forward(
self, x: Union[Tensor, List[Tensor], Tuple[Tensor, ...]], target: Optional[List[Dict[str, Tensor]]] = None
Expand Down
3 changes: 1 addition & 2 deletions holocron/models/detection/yolov4.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,14 @@ def forward(
y3 = self.yolo3(o3, target)

if not self.training:
detections = [
return [
{
"boxes": torch.cat((det1["boxes"], det2["boxes"], det3["boxes"]), dim=0),
"scores": torch.cat((det1["scores"], det2["scores"], det3["scores"]), dim=0),
"labels": torch.cat((det1["labels"], det2["labels"], det3["labels"]), dim=0),
}
for det1, det2, det3 in zip(y1, y2, y3)
]
return detections

return {k: y1[k] + y2[k] + y3[k] for k in y1}

Expand Down
6 changes: 2 additions & 4 deletions holocron/models/segmentation/unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ def forward(self, x: Tensor) -> Tensor:
x = decoder(xs.pop(), x)

# Classifier
x = self.classifier(x)
return x
return self.classifier(x)


class UBlock(nn.Module):
Expand Down Expand Up @@ -368,8 +367,7 @@ def forward(self, x: Tensor) -> Tensor:
x = self.upsample(x)

# Classifier
x = self.classifier(x)
return x
return self.classifier(x)


def _unet(arch: str, pretrained: bool, progress: bool, **kwargs: Any) -> UNet:
Expand Down
3 changes: 1 addition & 2 deletions holocron/models/segmentation/unet3p.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def forward(self, x: Tensor) -> Tensor:
xs[idx] = self.decoder[idx](xs[:idx], xs[idx], xs[idx + 1 :])

# Classifier
x = self.classifier(xs[0])
return x
return self.classifier(xs[0])


def _unet(arch: str, pretrained: bool, progress: bool, **kwargs: Any) -> nn.Module:
Expand Down
8 changes: 2 additions & 6 deletions holocron/nn/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def concat_downsample2d(x: Tensor, scale_factor: int) -> Tensor:
# N * C * H * W --> N * C * (H/scale_factor) * scale_factor * (W/scale_factor) * scale_factor
x = x.view(b, c, h // scale_factor, scale_factor, w // scale_factor, scale_factor)
x = x.permute(0, 3, 5, 1, 2, 4).contiguous()
x = x.view(b, int(c * scale_factor**2), h // scale_factor, w // scale_factor)

return x
return x.view(b, int(c * scale_factor**2), h // scale_factor, w // scale_factor)


def z_pool(x: Tensor, dim: int) -> Tensor:
Expand Down Expand Up @@ -364,9 +362,7 @@ def _xcorr2d(
h = floor((h + (2 * padding[0]) - (dilation[0] * (weight.shape[-2] - 1)) - 1) / stride[0] + 1)
w = floor((w + (2 * padding[1]) - (dilation[1] * (weight.shape[-1] - 1)) - 1) / stride[1] + 1)

x = x.view(-1, weight.shape[0], h, w)

return x
return x.view(-1, weight.shape[0], h, w)


def _convNd(x: Tensor, weight: Tensor) -> Tensor:
Expand Down
6 changes: 2 additions & 4 deletions holocron/nn/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __init__(self, inplace: bool = False) -> None:
self.inplace = inplace

def extra_repr(self) -> str:
inplace_str = "inplace=True" if self.inplace else ""
return inplace_str
return "inplace=True" if self.inplace else ""


class HardMish(_Activation):
Expand Down Expand Up @@ -80,5 +79,4 @@ def __init__(self, in_channels: int, kernel_size: int = 3) -> None:
def forward(self, x: Tensor) -> Tensor:
out = self.conv(x)
out = self.bn(out)
x = torch.max(x, out)
return x
return torch.max(x, out)
3 changes: 1 addition & 2 deletions holocron/nn/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ def forward(self, x: Tensor) -> Tensor:
x_h = cast(Tensor, self.h_branch(x))
x_w = cast(Tensor, self.w_branch(x))

out = (x_c + x_h + x_w) / 3
return out
return (x_c + x_h + x_w) / 3
4 changes: 1 addition & 3 deletions holocron/nn/modules/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,4 @@ def forward(self, x: Tensor) -> Tensor:

# Multiply-Add operation
# --> (N, C, H // s, W // s)
out = (kernel * x_unfolded).sum(dim=3).view(*x.shape[:2], *kernel.shape[-2:])

return out
return (kernel * x_unfolded).sum(dim=3).view(*x.shape[:2], *kernel.shape[-2:])
9 changes: 3 additions & 6 deletions holocron/nn/modules/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def forward(self, x: Tensor) -> Tensor:
return x.view(x.size(0), x.size(1), -1).mean(-1).view(x.size(0), x.size(1), 1, 1)

def extra_repr(self) -> str:
inplace_str = "flatten=True" if self.flatten else ""
return inplace_str
return "flatten=True" if self.flatten else ""


class GlobalMaxPool2d(nn.Module):
Expand All @@ -97,13 +96,11 @@ def forward(self, x: Tensor) -> Tensor:
return x.view(x.size(0), x.size(1), -1).max(-1).values.view(x.size(0), x.size(1), 1, 1)

def extra_repr(self) -> str:
inplace_str = "flatten=True" if self.flatten else ""
return inplace_str
return "flatten=True" if self.flatten else ""


def get_padding(kernel_size: int, stride: int = 1, dilation: int = 1) -> int:
padding = ((stride - 1) + dilation * (kernel_size - 1)) // 2
return padding
return ((stride - 1) + dilation * (kernel_size - 1)) // 2


class BlurPool2d(nn.Module):
Expand Down
3 changes: 1 addition & 2 deletions holocron/nn/modules/lambda_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:

Y = Yc + Yp
# B x (H * W) x num_heads x dim_v -> B x (num_heads * dim_v) x H x W
out = Y.permute(0, 2, 3, 1).reshape(b, self.num_heads * v.shape[2], h, w)
return out
return Y.permute(0, 2, 3, 1).reshape(b, self.num_heads * v.shape[2], h, w)
4 changes: 1 addition & 3 deletions references/clean_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def parse_args():

parser.add_argument("checkpoint", type=str, help="path to the training checkpoint")
parser.add_argument("outfile", type=str, help="model")
args = parser.parse_args()

return args
return parser.parse_args()


if __name__ == "__main__":
Expand Down

0 comments on commit edb1963

Please sign in to comment.