Skip to content

Instantly share code, notes, and snippets.

View jeasinema's full-sized avatar
💭
I may be slow to respond.

Xiaojian Ma jeasinema

💭
I may be slow to respond.
View GitHub Profile
@jeasinema
jeasinema / weight_init.py
Last active May 25, 2023 09:32
A simple script for parameter initialization for PyTorch
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import torch
import torch.nn as nn
import torch.nn.init as init
def weight_init(m):
'''
@jeasinema
jeasinema / spatial_softmax.py
Last active March 10, 2023 08:11
Spatial(Arg)Softmax for pytorch
import torch
import torch.nn.functional as F
from torch.nn.parameter import Parameter
import numpy as np
class SpatialSoftmax(torch.nn.Module):
def __init__(self, height, width, channel, temperature=None, data_format='NCHW'):
super(SpatialSoftmax, self).__init__()
self.data_format = data_format
@jeasinema
jeasinema / tensorboard_logging.py
Created April 9, 2018 19:31
A simple python snippet for logging with tensorboard
"""Simple example on how to log scalars and images to tensorboard without tensor ops.
License: Copyleft
"""
__author__ = "Jeasine Ma"
import tensorflow as tf
from PIL import Image
import numpy as np
from io import BytesIO
export CUDA_HOME=$HOME/tools/cuda-9.0 # change to your path
export CUDA_TOOLKIT_ROOT_DIR=$CUDA_HOME
export LD_LIBRARY_PATH="$CUDA_HOME/extras/CUPTI/lib64:$LD_LIBRARY_PATH"
export LIBRARY_PATH=$CUDA_HOME/lib64:$LIBRARY_PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
export CFLAGS="-I$CUDA_HOME/include $CFLAGS"
export PATH="$CUDA_HOME/bin:$PATH"
@jeasinema
jeasinema / NoteDup_patched
Last active October 12, 2020 21:45
Remove the yinxiang->evernote warning of NoteDup (https://github.com/ppyyf/notedup-bin)
java -jar notedup_patched.jar
@jeasinema
jeasinema / delaunay.py
Last active August 21, 2020 05:36
A python implementation of delaunay algorithm
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
# File Name : face_morphing.py
# Creation Date : 04-04-2018
# Created By : Jeasine Ma [jeasinema[at]gmail[dot]com]
import cv2
import json
import numpy as np
import torch
import numpy as np
import argparse
from torchvision import models
import matplotlib.pyplot as plt
import cv2
import os
resnet = models.resnet50(pretrained=True)
@jeasinema
jeasinema / create_legend.py
Last active September 2, 2019 06:53
Create customized legend
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import seaborn as sns
import numpy as np
fig = plt.figure()
fig.set_size_inches(18, 3)
ax = fig.subplots(1)
label = ['Expert', 'Demo', 'Pre-train', 'POfD', 'Penalty', 'Penalty + Ann.', 'Ours']
flatui = ["#9b59b6", "#999900", "#3498db", "#95a5a6", "#009900", "#fc9272", "#e74c3c"]
clrs = sns.color_palette(flatui)
@jeasinema
jeasinema / imagenet1000_clsidx_to_labels.txt
Created June 27, 2019 05:46 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
@jeasinema
jeasinema / jeasinema.sty
Last active May 12, 2019 07:41
Some useful macros for writing technical papers
% packages
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{hyperref}
\usepackage{xspace}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{color}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{footmisc}