Skip to content

Instantly share code, notes, and snippets.

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

ZHANG Zhi tczhangzhi

💭
I may be slow to respond.
View GitHub Profile
@tczhangzhi
tczhangzhi / demo.vba
Last active October 25, 2019 18:36
Resize plot area or legend in Excel
Sub ResizePlotArea()
Dim iHeight, iWidth As Integer
iTop = 40
iLeft = 0
iHeight = 180
iWidth = 280
ActiveChart.PlotArea.Select
Selection.Top = iTop
Selection.Left = iLeft
@tczhangzhi
tczhangzhi / losses.py
Last active October 19, 2019 10:29
Multi-label Segmentation Loss
import torch
import torch.nn
import torch.nn.functional as F
def one_hot_encode_truth(truth, num_class=4):
# N, H, W --> N, C, H, W (C = num_class)
one_hot = truth.repeat(1, num_class, 1, 1)
arange = torch.arange(1, num_class + 1).view(1, num_class, 1, 1).to(truth.device)
one_hot = (one_hot == arange).float()
@tczhangzhi
tczhangzhi / visual.py
Created November 2, 2019 06:51
Visualization of models
import math
import torch
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.lines import Line2D
@tczhangzhi
tczhangzhi / paper_similarity.py
Created March 28, 2020 15:54
Used to calculate the coincidence rate of two papers, suitable for expanding conference papers into journals
import diff_match_patch
paper_a_path = 'a.tex'
paper_b_path = 'b.tex'
a_data = None
with open(icme_path, "r") as f:
a_data = f.read()
b_data = None
@tczhangzhi
tczhangzhi / load.py
Created April 3, 2020 09:57
Load parallel models, or models with different layers and parameter shapes
from collections import OrderedDict
def load_parallel(model, state_dict):
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = k[7:]
new_state_dict[name] = v
model.load_state_dict(new_state_dict)
return model