Skip to content

Commit

Permalink
Add pyproject.toml and Fix Ruff issues (#36)
Browse files Browse the repository at this point in the history
* Add pyproject.toml and fix ruff issues

* open file using Path

* fix ruff issues
  • Loading branch information
willyfh authored Mar 3, 2024
1 parent 9bcdf01 commit 09f26c6
Show file tree
Hide file tree
Showing 25 changed files with 810 additions and 503 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: debug-statements
- id: detect-private-key

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.0"
Expand Down
22 changes: 12 additions & 10 deletions docs/examples/graph/plot_basic_dense.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
"""
Basic Dense
"""Basic Dense
=======================================
Visualization of basic dense model
"""
""" # noqa: D205

import torch.nn as nn
import visualtorch
import matplotlib.pyplot as plt
import torch
import visualtorch
from torch import nn


class SimpleDense(nn.Module):
def __init__(self):
super(SimpleDense, self).__init__()
"""Simple Dense Model."""

def __init__(self) -> None:
super().__init__()
self.h0 = nn.Linear(4, 8)
self.h1 = nn.Linear(8, 8)
self.h2 = nn.Linear(8, 4)
self.out = nn.Linear(4, 2)

def forward(self, x):
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Define the forward pass."""
x = self.h0(x)
x = self.h1(x)
x = self.h2(x)
x = self.out(x)
return x
return self.out(x)


model = SimpleDense()
Expand Down
25 changes: 14 additions & 11 deletions docs/examples/graph/plot_custom_node_color.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
"""
Custom Color
"""Custom Color
=======================================
Visualization of custom color
"""
""" # noqa: D205

import torch.nn as nn
import visualtorch
import matplotlib.pyplot as plt
from collections import defaultdict

import matplotlib.pyplot as plt
import torch
import visualtorch
from torch import nn


class SimpleDense(nn.Module):
def __init__(self):
super(SimpleDense, self).__init__()
"""Simple Dense Model."""

def __init__(self) -> None:
super().__init__()
self.h0 = nn.Linear(4, 8)
self.h1 = nn.Linear(8, 8)
self.h2 = nn.Linear(8, 4)
self.out = nn.Linear(4, 2)

def forward(self, x):
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Define the forward pass."""
x = self.h0(x)
x = self.h1(x)
x = self.h2(x)
x = self.out(x)
return x
return self.out(x)


model = SimpleDense()
Expand Down
22 changes: 12 additions & 10 deletions docs/examples/graph/plot_custom_node_size.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
"""
Custom Node Size
"""Custom Node Size
=======================================
Visualization of custom node size
"""
""" # noqa: D205

import torch.nn as nn
import visualtorch
import matplotlib.pyplot as plt
import torch
import visualtorch
from torch import nn


class SimpleDense(nn.Module):
def __init__(self):
super(SimpleDense, self).__init__()
"""Simple Dense Model."""

def __init__(self) -> None:
super().__init__()
self.h0 = nn.Linear(4, 8)
self.h1 = nn.Linear(8, 8)
self.h2 = nn.Linear(8, 4)
self.out = nn.Linear(4, 2)

def forward(self, x):
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Define the forward pass."""
x = self.h0(x)
x = self.h1(x)
x = self.h2(x)
x = self.out(x)
return x
return self.out(x)


model = SimpleDense()
Expand Down
22 changes: 12 additions & 10 deletions docs/examples/graph/plot_custom_spacing_layers.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
"""
Custom Spacing for Layers
"""Custom Spacing for Layers
=======================================
Visualization of custom spacing between layers
"""
""" # noqa: D205

import torch.nn as nn
import visualtorch
import matplotlib.pyplot as plt
import torch
import visualtorch
from torch import nn


class SimpleDense(nn.Module):
def __init__(self):
super(SimpleDense, self).__init__()
"""Simple Dense Model."""

def __init__(self) -> None:
super().__init__()
self.h0 = nn.Linear(4, 8)
self.h1 = nn.Linear(8, 8)
self.h2 = nn.Linear(8, 4)
self.out = nn.Linear(4, 2)

def forward(self, x):
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Define the forward pass."""
x = self.h0(x)
x = self.h1(x)
x = self.h2(x)
x = self.out(x)
return x
return self.out(x)


model = SimpleDense()
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/layered/plot_2d_view.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
2D View
"""2D View
=======================================
Visualization of 2D view
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
Expand Down
36 changes: 19 additions & 17 deletions docs/examples/layered/plot_basic_custom.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
"""
Basic Custom
"""Basic Custom
=======================================
Visualization of basic custom model
"""
""" # noqa: D205

import torch.nn as nn
import torch.nn.functional as F
import visualtorch
import matplotlib.pyplot as plt
import torch
import torch.nn.functional as func
import visualtorch
from torch import nn


# Example of a simple CNN model
class SimpleCNN(nn.Module):
def __init__(self):
"""Simple CNN Model."""

def __init__(self) -> None:
super().__init__()
self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1)
self.conv2 = nn.Conv2d(16, 32, kernel_size=3, padding=1)
self.conv3 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
self.fc1 = nn.Linear(64 * 28 * 28, 128)
self.fc2 = nn.Linear(128, 10)

def forward(self, x):
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Define the forward pass."""
x = self.conv1(x)
x = F.relu(x)
x = F.max_pool2d(x, 2, 2)
x = func.relu(x)
x = func.max_pool2d(x, 2, 2)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2, 2)
x = func.relu(x)
x = func.max_pool2d(x, 2, 2)
x = self.conv3(x)
x = F.relu(x)
x = F.max_pool2d(x, 2, 2)
x = func.relu(x)
x = func.max_pool2d(x, 2, 2)
x = x.view(x.size(0), -1)
x = self.fc1(x)
x = F.relu(x)
x = self.fc2(x)
return x
x = func.relu(x)
return self.fc2(x)


# Create an instance of the SimpleCNN
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/layered/plot_basic_sequential.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Basic Sequential
"""Basic Sequential
=======================================
Visualization of basic sequential model
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/layered/plot_custom_color.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""
Custom Color
"""Custom Color
=======================================
Visualization of custom color
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
from collections import defaultdict

import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
nn.Conv2d(3, 16, kernel_size=3, padding=1),
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/layered/plot_custom_opacity.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Custom Opacity
"""Custom Opacity
=======================================
Change the color transparency
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
Expand Down
14 changes: 8 additions & 6 deletions docs/examples/layered/plot_custom_orientation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Custom Orientation
"""Custom Orientation
=======================================
Visualization of custom orientation for 1 dim layers
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
Expand All @@ -29,7 +28,10 @@
input_shape = (1, 3, 224, 224)

img = visualtorch.layered_view(
model, input_shape=input_shape, one_dim_orientation="x", spacing=40
model,
input_shape=input_shape,
one_dim_orientation="x",
spacing=40,
)

plt.axis("off")
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/layered/plot_custom_shading.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Custom Shading
"""Custom Shading
=======================================
Visualization of custom shading
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
Expand Down
9 changes: 4 additions & 5 deletions docs/examples/layered/plot_custom_spacing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Custom Spacing
"""Custom Spacing
=======================================
Visualization of custom spacing
"""
""" # noqa: D205

import visualtorch
import torch.nn as nn
import matplotlib.pyplot as plt
import visualtorch
from torch import nn

# Example of a simple CNN model using nn.Sequential
model = nn.Sequential(
Expand Down
Loading

0 comments on commit 09f26c6

Please sign in to comment.