Skip to content

Instantly share code, notes, and snippets.

@JefferyW
JefferyW / os.py
Created March 4, 2020 20:07
Python os operation
# For searching the file which name contains specific string in folder and sub folder
def search(s,t,mainpath):
rootdir = mainpath
searchpath = np.zeros(0)
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
if filename.find(s) != -1 and filename.find(t) != -1:
searchpath = np.append(searchpath,
os.path.abspath(os.path.join(parent,filename)))
return searchpath
@JefferyW
JefferyW / T-SNE_visual.py
Last active January 8, 2020 22:38
T-SNE visualisation tool
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.cm as cm
import numpy as np
from scipy.spatial import ConvexHull
from sklearn.mixture import GaussianMixture
from scipy import linalg
from sklearn.neighbors import NearestNeighbors
from sklearn.manifold import TSNE
@JefferyW
JefferyW / keras_save_load.py
Created January 8, 2020 22:12
Keras save and load model
from keras.models import model_from_yaml
def saveModel(model, savename):
# serialize model to YAML
model_yaml = model.to_yaml()
with open(savename+".yaml", "w") as yaml_file:
yaml_file.write(model_yaml)
print("Yaml Model ",savename,".yaml saved to disk")
# serialize weights to HDF5
model.save_weights(savename+".h5")