Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
skip: [mypy, pytest]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
rev: v0.13.1
hooks:
- id: ruff
args: [--fix]
Expand Down
2 changes: 1 addition & 1 deletion ai_toolkit/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_dataset_initializer(dataset_name: str) -> DatasetLoader:
"""Retrieves class initializer from its string name."""
if not hasattr(sys.modules[__name__], dataset_name):
raise RuntimeError(f"Dataset class {dataset_name} not found in datasets/")
return cast(DatasetLoader, getattr(sys.modules[__name__], dataset_name)())
return cast("DatasetLoader", getattr(sys.modules[__name__], dataset_name)())


__all__ = (
Expand Down
2 changes: 1 addition & 1 deletion ai_toolkit/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_metric_initializer(metric_name: str) -> type[Metric]:
"""Retrieves class initializer from its string name."""
if not hasattr(sys.modules[__name__], metric_name):
raise RuntimeError(f"Metric {metric_name} not found in metrics folder.")
return cast(type[Metric], getattr(sys.modules[__name__], metric_name))
return cast("type[Metric]", getattr(sys.modules[__name__], metric_name))


__all__ = (
Expand Down
2 changes: 1 addition & 1 deletion ai_toolkit/metrics/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Accuracy(Metric):
def __repr__(self) -> str:
return f"{self.name}: {100. * self.value:.2f}%"
return f"{self.name}: {100.0 * self.value:.2f}%"

@staticmethod
def calculate_accuracy(output: torch.Tensor, target: torch.Tensor) -> float:
Expand Down
2 changes: 1 addition & 1 deletion ai_toolkit/metrics/f1_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def calculate_f1_score(
f1 = 2 * (precision * recall) / (precision + recall + eps)
f1 = f1.clamp(min=eps, max=1 - eps)
f1_score = 1 - f1.mean()
return cast(float, f1_score)
return cast("float", f1_score)

def update(self, val_dict: SimpleNamespace) -> float:
y_pred, y_true = val_dict.output, val_dict.target
Expand Down
2 changes: 1 addition & 1 deletion ai_toolkit/metrics/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def update(self, val_dict: SimpleNamespace) -> float:
self.epoch_avg += loss * val_dict.batch_size
self.running_avg += loss * val_dict.batch_size
self.num_examples += val_dict.batch_size
return cast(float, loss)
return cast("float", loss)
6 changes: 3 additions & 3 deletions ai_toolkit/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def get_model_initializer(model_name: str) -> type[nn.Module]:
"""Retrieves class initializer from its string name."""
if not hasattr(sys.modules[__name__], model_name):
raise RuntimeError(f"Model class {model_name} not found in models/")
return cast(type[nn.Module], getattr(sys.modules[__name__], model_name))
return cast("type[nn.Module]", getattr(sys.modules[__name__], model_name))


__all__ = (
"BasicCNN",
"DenseNet",
"BasicLSTM",
"MaskRCNN",
"BasicRNN",
"DenseNet",
"MaskRCNN",
"get_model_initializer",
)
2 changes: 1 addition & 1 deletion ai_toolkit/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_model(
test_loss /= test_len
print(
f"\nTest set: Average loss: {test_loss:.4f},",
f"Accuracy: {correct}/{test_len} ({100. * correct / test_len:.2f}%)\n",
f"Accuracy: {correct}/{test_len} ({100.0 * correct / test_len:.2f}%)\n",
)


Expand Down
Loading