Skip to content

Instantly share code, notes, and snippets.

@zshn25
zshn25 / utils.py
Created May 28, 2024 12:48
Python utils
from typing import Iterable
#from collections import Iterable # < py38
def flatten(items):
"""Yield items from any nested iterable;
Source: https://stackoverflow.com/a/40857703
Usage:
@zshn25
zshn25 / fusion.py
Last active July 31, 2023 14:05
Conv2d and BatchNorm2d fusion
from torch import nn
from torch.nn.utils.fusion import fuse_conv_bn_eval
def fuse_all_conv_bn(model):
stack = []
for name, module in model.named_children(): # immediate children
if list(module.named_children()): # is not empty (not a leaf)
fuse_all_conv_bn(module)
@zshn25
zshn25 / requirements.txt
Last active May 22, 2022 07:40
ResNet Feature Pyramid with Pytorch
torch