Skip to content

Instantly share code, notes, and snippets.

View diaoenmao's full-sized avatar
🎯
Focusing

Enmao Diao diaoenmao

🎯
Focusing
View GitHub Profile
# Resume
git clone https://github.com/Collaborative-AI/colda.git
cd colda
# Init
git commit --allow-empty -m "Initial dummy commit"
# Merge for package
git remote add --fetch package https://github.com/Collaborative-AI/Package.git
git merge package/main --allow-unrelated-histories
@diaoenmao
diaoenmao / resizer.py
Last active July 14, 2020 20:35
Image resizer for Deep Learining image dataset
from PIL import Image
from argparse import ArgumentParser
import os
from multiprocessing import Pool
alg_dict = {
'lanczos': Image.LANCZOS,
'nearest': Image.NEAREST,
'bilinear': Image.BILINEAR,
'bicubic': Image.BICUBIC,
@diaoenmao
diaoenmao / h5tool.py
Created July 3, 2020 05:56
CelebA-HQ Generation h5tool.py generation file for Python 3
# Instructions can be found at https://github.com/willylulu/celeba-hq-modified and https://zhuanlan.zhihu.com/p/52188519
import os
import sys
import io
import glob
import pickle
import argparse
import threading
import queue
@diaoenmao
diaoenmao / test.py
Last active December 13, 2018 04:54
Anomaly Detection for Multimodality Dataset
if __name__ == '__main__':
aligned_cmumosi_highlevel = mmdatasdk.mmdataset('./data/MOSI/deployed')
data_keys = mmdatasdk.dataset.standard_datasets.CMU_MOSI.cmu_mosi_std_folds.standard_train_fold + \
mmdatasdk.dataset.standard_datasets.CMU_MOSI.cmu_mosi_std_folds.standard_valid_fold + \
mmdatasdk.dataset.standard_datasets.CMU_MOSI.cmu_mosi_std_folds.standard_test_fold
supported_feature_names = {'covarep':'COVAREP','opensmile':'OpenSmile-emobase2010','facet':'FACET 4.1','glove':'glove_vectors','bert':'BERT embeddings','label':'Opinion Segment Labels'}
data = {k:{} for k in supported_feature_names}
id = {k:[] for k in supported_feature_names}
print('multiple labels keys')
for k in supported_feature_names:
@diaoenmao
diaoenmao / patches.py
Last active January 7, 2023 17:00
Extract patches from images and recover orginal images from patches
def extract_patches_2d(img,patch_shape,step=[1.0,1.0],batch_first=False):
patch_H, patch_W = patch_shape[0], patch_shape[1]
if(img.size(2)<patch_H):
num_padded_H_Top = (patch_H - img.size(2))//2
num_padded_H_Bottom = patch_H - img.size(2) - num_padded_H_Top
padding_H = nn.ConstantPad2d((0,0,num_padded_H_Top,num_padded_H_Bottom),0)
img = padding_H(img)
if(img.size(3)<patch_W):
num_padded_W_Left = (patch_W - img.size(3))//2
num_padded_W_Right = patch_W - img.size(3) - num_padded_W_Left
@diaoenmao
diaoenmao / pytorch_unused_params.py
Last active October 26, 2018 09:36
reproduce unused param error
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
torch.manual_seed(2809)
def check_params(modelA, modelB):