Skip to content

Instantly share code, notes, and snippets.

View lzhbrian's full-sized avatar
😎
Interesting

Tzu-Heng Lin lzhbrian

😎
Interesting
View GitHub Profile
@lzhbrian
lzhbrian / infinite_dataloader.py
Created November 13, 2020 04:06 — forked from MFreidank/infinite_dataloader.py
A pytorch DataLoader that generates an unbounded/infinite number of minibatches from the dataset.
from torch.utils.data import DataLoader
class InfiniteDataLoader(DataLoader):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Initialize an iterator over the dataset.
self.dataset_iterator = super().__iter__()
def __iter__(self):
@lzhbrian
lzhbrian / boto3-list-instances.py
Created August 24, 2020 03:16 — forked from ableasdale/boto3-list-instances.py
Using Boto 3 to list out AWS EC2 instance information
import boto3
from termcolor import colored
ec2 = boto3.resource('ec2')
for i in ec2.instances.all():
print("Id: {0}\tState: {1}\tLaunched: {2}\tRoot Device Name: {3}".format(
colored(i.id, 'cyan'),
colored(i.state['Name'], 'green'),
@lzhbrian
lzhbrian / trim_detectron_model.py
Created April 26, 2019 07:13 — forked from wangg12/trim_detectron_model.py
trim last layers of detectron model for maskrcnn-benchmark
import os
import torch
import argparse
from maskrcnn_benchmark.config import cfg
from maskrcnn_benchmark.utils.c2_model_loading import load_c2_format
def removekey(d, listofkeys):
r = dict(d)
for key in listofkeys:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lzhbrian
lzhbrian / pandas_melt.py
Created September 5, 2017 09:22 — forked from rainsunny/pandas_melt.py
Turn certain columns to key-value rows ( and the reverse )
"""
Turn this
location name Jan-2010 Feb-2010 March-2010
A "test" 12 20 30
B "foo" 18 20 25
into this
location name Date Value