This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnNormalize(object): | |
def __init__(self, mean, std): | |
self.mean = mean | |
self.std = std | |
def __call__(self, tensor): | |
""" | |
Args: | |
tensor (Tensor): Tensor image of size (C, H, W) to be normalized. | |
Returns: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place this file to the root of the project | |
# Adjust based on your needs | |
repos: | |
- repo: https://github.com/pre-commit/pre-commit-hooks | |
rev: v4.3.0 | |
hooks: | |
- id: check-added-large-files # Prevent giant files from being committed. | |
- id: check-ast # Simply check whether files parse as valid python. | |
- id: fix-byte-order-marker # Removes UTF-8 byte order marker. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
images = [Image.open(x) for x in ['Test1.jpg', 'Test2.jpg', 'Test3.jpg']] | |
widths, heights = zip(*(i.size for i in images)) | |
total_width = sum(widths) | |
max_height = max(heights) | |
new_im = Image.new('RGB', (total_width, max_height)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prettytable import PrettyTable | |
def count_parameters(model): | |
table = PrettyTable(["Module", "Parameters"]) | |
# Assume the model consists of three main components: backbone, transformer, head | |
module_param_dict = { | |
"backbone": 0, | |
"transformer": 0, | |
"head": 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import torch | |
import numpy as np | |
from torchvision.models import resnet18, ResNet18_Weights # TODO: Import your model | |
from tqdm import tqdm | |
from rich import print | |
# ========== TODO: Adjust based on your needs ========== | |
MODEL = resnet18(weights=ResNet18_Weights.IMAGENET1K_V1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import torch | |
import torch.nn as nn | |
from torch.autograd import Variable | |
from torch.utils.data import DataLoader | |
import torchvision | |
import torchvision.transforms as T | |
from torchvision.datasets import ImageFolder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a batched LSTM forward and backward pass | |
""" | |
import numpy as np | |
import code | |
class LSTM: | |
@staticmethod | |
def init(input_size, hidden_size, fancy_forget_bias_init = 3): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import matplotlib.pyplot as plt | |
def save_fig( | |
fig, fig_name, fig_dir, tight_layout=True, padding=False, fig_extension="png", resolution=300, transparent=True | |
): | |
""" | |
Save figure | |
Parameters | |
---------- |