Skip to content

Instantly share code, notes, and snippets.

View Chris-hughes10's full-sized avatar

Chris Hughes Chris-hughes10

View GitHub Profile
@Chris-hughes10
Chris-hughes10 / EfficientDet Pytorch-lightning with EfficientNet v2 backbone Blog Post.ipynb
Last active February 5, 2025 01:44
EfficientDet Pytorch-lightning with EfficientNet v2 backbone Blog Post.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Chris-hughes10
Chris-hughes10 / train_mnist.py
Last active November 24, 2021 10:53
pytorch-accelerated_blog_mnist_quickstart
# this example is taken from
# https://github.com/Chris-hughes10/pytorch-accelerated/blob/main/examples/train_mnist.py
import os
from torch import nn, optim
from torch.utils.data import random_split
from torchvision import transforms
from torchvision.datasets import MNIST
@Chris-hughes10
Chris-hughes10 / trainer_with_metrics.py
Created November 24, 2021 11:02
pytorch_accelerated_blog_trainer_metrics_snippet
from torchmetrics import MetricCollection, Accuracy, Precision, Recall
class TrainerWithMetrics(Trainer):
def __init__(self, num_classes, *args, **kwargs):
super().__init__(*args, **kwargs)
# this will be moved to the correct device automatically by the
# MoveModulesToDeviceCallback callback, which is used by default
self.metrics = MetricCollection(
{
@Chris-hughes10
Chris-hughes10 / train_with_metrics_in_loop.py
Created November 24, 2021 11:11
pytorch_accelerated_blog_metrics_in_trainer_script
# https://github.com/Chris-hughes10/pytorch-accelerated/blob/main/examples/metrics/train_with_metrics_in_loop.py
import os
from torch import nn, optim
from torch.utils.data import random_split
from torchmetrics import MetricCollection, Accuracy, Precision, Recall
from torchvision import transforms
from torchvision.datasets import MNIST
from pytorch_accelerated import Trainer
@Chris-hughes10
Chris-hughes10 / classification_metrics_callback.py
Created November 24, 2021 11:22
pytorch_accelerated_blog_metrics_callback_snippet
from torchmetrics import MetricCollection, Accuracy, Precision, Recall
from pytorch_accelerated.callbacks import TrainerCallback
class ClassificationMetricsCallback(TrainerCallback):
def __init__(self, num_classes):
self.metrics = MetricCollection(
{
"accuracy": Accuracy(num_classes=num_classes),
@Chris-hughes10
Chris-hughes10 / train_with_metrics_in_callback.py
Created November 24, 2021 11:28
pytorch_accelerated_blog_metrics_in_callback
# https://github.com/Chris-hughes10/pytorch-accelerated/blob/main/examples/metrics/train_with_metrics_in_callback.py
import os
from torch import nn, optim
from torch.utils.data import random_split
from torchmetrics import MetricCollection, Accuracy, Precision, Recall
from torchvision import transforms
from torchvision.datasets import MNIST
@Chris-hughes10
Chris-hughes10 / mf_model.py
Created December 9, 2021 07:39
Recommender blog: matrix factorization model
import torch
from torch import nn
class MfDotBias(nn.Module):
def __init__(
self, n_factors, n_users, n_items, ratings_range=None, use_biases=True
):
super().__init__()
self.bias = use_biases
@Chris-hughes10
Chris-hughes10 / recommender_metrics_callback.py
Created December 9, 2021 07:43
Recommender Blog: Torchmetrics recommender callback
from pytorch_accelerated.callbacks import TrainerCallback
import torchmetrics
class RecommenderMetricsCallback(TrainerCallback):
def __init__(self):
self.metrics = torchmetrics.MetricCollection(
{
"mse": torchmetrics.MeanSquaredError(),
"mae": torchmetrics.MeanAbsoluteError(),
}
@Chris-hughes10
Chris-hughes10 / Recommender blog post.ipynb
Created December 9, 2021 09:19
Comparing matrix factorixation with transformers using pytorch-accelerated blog post.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Chris-hughes10
Chris-hughes10 / parser_image_name.py
Created January 27, 2022 14:53
timm blog - custom parser
from pathlib import Path
from timm.data.parsers.parser import Parser
class ParserImageName(Parser):
def __init__(self, root, class_to_idx=None):
super().__init__()
self.root = Path(root)